Skip to content

Commit 9429ae6

Browse files
authored
fix(pypi): inherit proxy env variables in compile_pip_requirements test (#2941)
Bazel does not pass environment variables implicitly (even running test outside of sandbox). This forces compile_pip_requirements test to fail with timeout when attempting to run it behind the proxy. Also changes test_command in dependency_resolver string helper to use dot instead of underscore following deprecation notice
1 parent 948fcec commit 9429ae6

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ END_UNRELEASED_TEMPLATE
9898
* (py_test, py_binary) Allow external files to be used for main
9999
* (pypi) Correctly aggregate the sources when the hashes specified in the lockfile differ
100100
by platform even though the same version is used. Fixes [#2648](https://github.com/bazel-contrib/rules_python/issues/2648).
101+
* (pypi) `compile_pip_requirements` test rule works behind the proxy
101102

102103
{#v0-0-0-added}
103104
### Added

python/private/pypi/dependency_resolver/dependency_resolver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def main(
165165
update_command = (
166166
os.getenv("CUSTOM_COMPILE_COMMAND") or f"bazel run {target_label_prefix}.update"
167167
)
168-
test_command = f"bazel test {target_label_prefix}_test"
168+
test_command = f"bazel test {target_label_prefix}.test"
169169

170170
os.environ["CUSTOM_COMPILE_COMMAND"] = update_command
171171
os.environ["PIP_CONFIG_FILE"] = os.getenv("PIP_CONFIG_FILE") or os.devnull

python/private/pypi/pip_compile.bzl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ def pip_compile(
4545
By default this rules generates a filegroup named "[name]" which can be included in the data
4646
of some other compile_pip_requirements rule that references these requirements
4747
(e.g. with `-r ../other/requirements.txt`).
48-
4948
It also generates two targets for running pip-compile:
5049
5150
- validate with `bazel test [name].test`
@@ -160,6 +159,12 @@ def pip_compile(
160159
}
161160

162161
env = kwargs.pop("env", {})
162+
env_inherit = kwargs.pop("env_inherit", [])
163+
proxy_variables = ["https_proxy", "http_proxy", "no_proxy", "HTTPS_PROXY", "HTTP_PROXY", "NO_PROXY"]
164+
165+
for var in proxy_variables:
166+
if var not in env_inherit:
167+
env_inherit.append(var)
163168

164169
py_binary(
165170
name = name + ".update",
@@ -182,6 +187,7 @@ def pip_compile(
182187
"@@platforms//os:windows": {"USERPROFILE": "Z:\\FakeSetuptoolsHomeDirectoryHack"},
183188
"//conditions:default": {},
184189
}) | env,
190+
env_inherit = env_inherit,
185191
# kwargs could contain test-specific attributes like size
186192
**dict(attrs, **kwargs)
187193
)

0 commit comments

Comments
 (0)