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