Skip to content

Add support for proxy environment variables in publish#2233

Open
bartosz121 wants to merge 1 commit intopypa:masterfrom
bartosz121:publish-env-proxy-support
Open

Add support for proxy environment variables in publish#2233
bartosz121 wants to merge 1 commit intopypa:masterfrom
bartosz121:publish-env-proxy-support

Conversation

@bartosz121
Copy link
Copy Markdown

stumbled across this at work, fixes #1908


  • httpx does not honor proxy environment variables automatically when a custom transport is passed, like in this case
  • we use httpx._utils.get_environment_proxies[0] to stay consistent with httpx behavior instead of reimplementing env var parsing ourselves

[0] https://github.com/encode/httpx/blob/b5addb64f0161ff6bfe94c124ef76f6a1fba5254/httpx/_utils.py#L30

  - httpx does not honor proxy environment variables automatically when a custom transport is passed, like in this case
  - we use `httpx._utils.get_environment_proxies`[0] to stay consistent with httpx behavior instead of reimplementing env var parsing ourselves

[0] https://github.com/encode/httpx/blob/b5addb64f0161ff6bfe94c124ef76f6a1fba5254/httpx/_utils.py#L30
Comment on lines +63 to +71
proxy_map = get_environment_proxies()
mounts: dict[str, httpx.HTTPTransport | None] = {}
for pattern, proxy in proxy_map.items():
if proxy is None:
mounts[pattern] = None
else:
mounts[pattern] = httpx.HTTPTransport(
retries=3, verify=self.__verify, cert=self.__cert, trust_env=True, proxy=proxy
)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't trust_env=True do the same thing? you can avoid depending on _utils

disclaimer: not a maintainer

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but only if no custom transport is provided [0]. httpx.Client only applies env proxies automatically when trust_env=True and transport is None.

I considered removing the custom transport entirely and relying on trust_env=True, but that would drop retries=3 because httpx.Client does not expose retries in its constructor

[0] https://github.com/encode/httpx/blob/b5addb64f0161ff6bfe94c124ef76f6a1fba5254/httpx/_client.py#L685-L686

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, using the private _utils import from httpx is not ideal. The cleanest alternative would be to drop the custom transport and use a plain httpx.Client, but that would also mean dropping retries=3. I’m happy to go either way if maintainers would prefer the simpler approach

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add HTTPS_PROXY support for hatch publish

2 participants