Skip to content
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

Pass --proxy to build subprocesses #13124

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/6018.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The ``--proxy`` command-line option is now respected while installing build dependencies.
2 changes: 2 additions & 0 deletions src/pip/_internal/build_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,8 @@ def _install_requirements(
for link in finder.find_links:
args.extend(["--find-links", link])

if finder.proxy:
args.extend(["--proxy", finder.proxy])
for host in finder.trusted_hosts:
args.extend(["--trusted-host", host])
if finder.client_cert:
Expand Down
1 change: 1 addition & 0 deletions src/pip/_internal/cli/index_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ def _build_session(
"https": options.proxy,
}
session.trust_env = False
session.pip_proxy = options.proxy

# Determine if we can prompt the user for authentication or not
session.auth.prompting = not options.no_input
Expand Down
4 changes: 4 additions & 0 deletions src/pip/_internal/index/package_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,10 @@ def find_links(self) -> List[str]:
def index_urls(self) -> List[str]:
return self.search_scope.index_urls

@property
def proxy(self) -> Optional[str]:
return self._link_collector.session.pip_proxy

@property
def trusted_hosts(self) -> Iterable[str]:
for host_port in self._link_collector.session.pip_trusted_origins:
Expand Down
1 change: 1 addition & 0 deletions src/pip/_internal/network/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ def __init__(
# Namespace the attribute with "pip_" just in case to prevent
# possible conflicts with the base class.
self.pip_trusted_origins: List[Tuple[str, Optional[int]]] = []
self.pip_proxy = None

# Attach our User Agent to the request
self.headers["User-Agent"] = user_agent()
Expand Down
16 changes: 16 additions & 0 deletions tests/functional/test_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,19 @@ def test_proxy_does_not_override_netrc(
"simple",
)
script.assert_installed(simple="3.0")


@pytest.mark.network
def test_build_deps_use_proxy_from_cli(
script: PipTestEnvironment, capfd: pytest.CaptureFixture[str], data: TestData
) -> None:
args = ["wheel", "-v", str(data.packages / "pep517_setup_and_pyproject")]
args.extend(["--proxy", "http://127.0.0.1:9000"])

with proxy.Proxy(port=9000, num_acceptors=1, plugins=[AccessLogPlugin]):
result = script.pip(*args)

wheel_path = script.scratch / "pep517_setup_and_pyproject-1.0-py3-none-any.whl"
result.did_create(wheel_path)
out, _ = capfd.readouterr()
assert "CONNECT" in out
Loading