-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Add --no-proxy Option #13051
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add --no-proxy Option #13051
Conversation
Hi everyone - am I missing anything on this PR? Also, I am thinking about logging a message if both |
I'm going to put it on the 25.0 milestone so it doesn't get forgotten, but it will be up to a pip maintainer or release manager to review and decide whether it stays on there. I don't have a lot of experience reviewing this type of PR but it looks simple and your note about existing use of |
@martinezlc99, I just happened to be investigating this behavior today and it was a pleasant surprise to see this was active just yesterday. Thanks for driving this forward! I did want to ask, wouldn't the ideal behavior be for the Unfortunately, there seems to be buggy behavior in requests that means simple passing on a |
@jdlangs I think what this PR has going for it is its simplicity. Generally pip should rely on sourcing behavior from the standard or vendored libraries. I notice that uv has not implemented There is no standard definition of what |
Yeah, just using environment variables does seem like the most standard and robust method, but if pip provides a proxy argument, I think being able to configure
The simplest PR would actually be only passing a
Point taken, but is there any tool that treats |
Yeah, I think it's an unfortunate naming collision , maybe |
@notatallshaw @jdlangs my initial intent, and my understanding based on the original issue, was to bypass the proxy completely, so the boolean option made sense. But, I agree the I did a quick search to see how other tools handle this situation and found there is not a consensus:
The Chromium Chromium also supports A nice medium may be adding support for Open to thoughts/suggestions. |
But in this implementation you still take the proxy options provided to pip (which I assume can be either CLI or config), so it doesn't bypass the proxy options completely. Which is fine, there is precedence for this in the existing options I don't know how much other CLIs here are that informative as it's not exactly the same behavior. I would prefer to keep it something simple, but preferably a little more accurate, naming is hard, I'd stick to the current name unless something is obviously better. I really don't think pip should be trying to do it's own emulation of big complex tools, e.g. |
Thanks @notatallshaw - agree with all your points...forgot this implementation will take the proxy from the CLI as well 😎 So I think the name of the option is the only outstanding item. I like your suggestion of |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
It looks like the discussion here is still ongoing. So I'll postpone this to the next release. |
To restart the discussion on this PR, I'm fine with |
@notatallshaw it looks like you have been working on this - do you plan to merge it for 25.1? If not, I suggest we just remove the milestone, and it can go in when it's ready. |
I agree with @ichard26 , let's change the name. I'll move it to the next milestone, but will try and review if it gets updated quickly. |
@notatallshaw - apologies for not tracking this response, been a bit busy. I will update the name ASAP. |
…to option function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having come back to review this again, the main wrinkle with this design is that it's not true all proxy configuration set via environment variables will be ignored. All of pip's options can be set via environment variables. PIP_PROXY=myproxy
is equivalent to pip --proxy=myproxy
I don't know common ignoring PIP_PROXY
would be, but this flag has the potential to be confusing. Thoughts?
# Handle no proxy option | ||
if options.no_proxy: | ||
# Handle case of both --no-proxy-env being set along with --proxy=<proxy>. | ||
# In this case, the proxies from the environmental variables will be | ||
# ignored, but the command line proxy will be used. | ||
http_proxy = options.proxy if options.proxy else None | ||
https_proxy = options.proxy if options.proxy else None | ||
session.proxies = { | ||
"http": http_proxy, | ||
"https": https_proxy, | ||
} | ||
session.trust_env = False | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be merged into the pre-existing proxy logic in the following way, but would be this too magical?
# Handle configured proxies, including --no-proxy-env
if options.proxy or options.no_proxy_env:
session.proxies = {
"http": options.proxy or None,
"https": options.proxy or None,
}
session.trust_env = False
no_proxy: Callable[..., Option] = partial( | ||
Option, | ||
"--no-proxy-env", | ||
dest="no_proxy", | ||
action="store_true", | ||
default=False, | ||
help="Ignore all configured proxy settings, including environmental variables.", | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no_proxy: Callable[..., Option] = partial( | |
Option, | |
"--no-proxy-env", | |
dest="no_proxy", | |
action="store_true", | |
default=False, | |
help="Ignore all configured proxy settings, including environmental variables.", | |
) | |
no_proxy_env: Callable[..., Option] = partial( | |
Option, | |
"--no-proxy-env", | |
dest="no_proxy_env", | |
action="store_true", | |
default=False, | |
help="Do not read proxy configuration from environment variables.", | |
) |
@@ -1048,6 +1057,7 @@ def check_list_path_option(options: Values) -> None: | |||
no_input, | |||
keyring_provider, | |||
proxy, | |||
no_proxy, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no_proxy, | |
no_proxy_env, |
@@ -0,0 +1 @@ | |||
Add ``--no-proxy-env`` option to bypass http proxy. Using this option will ignore any configured http proxies, including any environmental variables |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add ``--no-proxy-env`` option to bypass http proxy. Using this option will ignore any configured http proxies, including any environmental variables | |
Add ``--no-proxy-env`` option to bypass proxies set via environment variables. |
Thanks @ichard26. From my perspective, overriding The renaming of the option name to include environment seems like it would also cover the |
This, because pip's CLI infrastructure treats |
@ichard26 - you are correct. Given this PR allows So as to not restart the discussions from scratch, I propose we clarify the documentation to indicate which environmental variables are ignored with this option; however, open to updating to ignore other means of P.S. I had previously set It seems in the timeframe of the initial PR and now, the I mention this only to state the two converse proxy options are consistent now. |
Fixes #5378.
This PR was originally done in #12011, which I cancelled due to age and associated pain of rebasing.
Originally this PR stalled in addressing #12011 (comment), but since then I have noticed the
--proxy=PROXY
option also setssession.trust_env = False
as well, so the behavior is consistent.