Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(pypi): inherit proxy env variables in compile_pip_requirements test #2941

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

Merged
merged 4 commits into from
Jun 3, 2025
Merged
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ END_UNRELEASED_TEMPLATE
* (py_test, py_binary) Allow external files to be used for main
* (pypi) Correctly aggregate the sources when the hashes specified in the lockfile differ
by platform even though the same version is used. Fixes [#2648](https://github.com/bazel-contrib/rules_python/issues/2648).
* (pypi) `compile_pip_requirements` test rule works behind the proxy

{#v0-0-0-added}
### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def main(
update_command = (
os.getenv("CUSTOM_COMPILE_COMMAND") or f"bazel run {target_label_prefix}.update"
)
test_command = f"bazel test {target_label_prefix}_test"
test_command = f"bazel test {target_label_prefix}.test"

os.environ["CUSTOM_COMPILE_COMMAND"] = update_command
os.environ["PIP_CONFIG_FILE"] = os.getenv("PIP_CONFIG_FILE") or os.devnull
Expand Down
8 changes: 7 additions & 1 deletion python/private/pypi/pip_compile.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ def pip_compile(
By default this rules generates a filegroup named "[name]" which can be included in the data
of some other compile_pip_requirements rule that references these requirements
(e.g. with `-r ../other/requirements.txt`).

It also generates two targets for running pip-compile:

- validate with `bazel test [name].test`
Expand Down Expand Up @@ -160,6 +159,12 @@ def pip_compile(
}

env = kwargs.pop("env", {})
env_inherit = kwargs.pop("env_inherit", [])
proxy_variables = ["https_proxy", "http_proxy", "no_proxy", "HTTPS_PROXY", "HTTP_PROXY", "NO_PROXY"]

for var in proxy_variables:
if var not in env_inherit:
env_inherit.append(var)

py_binary(
name = name + ".update",
Expand All @@ -182,6 +187,7 @@ def pip_compile(
"@@platforms//os:windows": {"USERPROFILE": "Z:\\FakeSetuptoolsHomeDirectoryHack"},
"//conditions:default": {},
}) | env,
env_inherit = env_inherit,
# kwargs could contain test-specific attributes like size
**dict(attrs, **kwargs)
)
Expand Down