Skip to content

Commit 0eb0068

Browse files
committed
fix(pypi): build the environment on the fly
At some point when we started using pipstar, we silently started building the python environment with system python interpreter. This is fine because the environment in those code paths would be unused, but this would break if python was not present on the machine. This PR fixes this by creating the environment on the fly with a little bit of code duplication. Fixes #3712
1 parent fa783be commit 0eb0068

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ Other changes:
126126
)
127127
```
128128
Fixes [#3676](https://github.com/bazel-contrib/rules_python/issues/3676).
129+
* (pypi) Fixes wheel extraction on hosts without python installed,
130+
Fixes [#3712](https://github.com/bazel-contrib/rules_python/issues/3712).
129131

130132
{#v2-0-0-added}
131133
### Added

python/private/pypi/whl_library.bzl

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,6 @@ def _whl_library_impl(rctx):
306306
extra_pip_args = []
307307
extra_pip_args.extend(rctx.attr.extra_pip_args)
308308

309-
# Manually construct the PYTHONPATH since we cannot use the toolchain here
310-
environment = _create_repository_execution_environment(rctx, python_interpreter, logger = logger)
311-
312309
whl_path = None
313310
sdist_filename = None
314311
if rctx.attr.whl_file:
@@ -377,7 +374,8 @@ def _whl_library_impl(rctx):
377374
python = python_interpreter,
378375
op = op_tmpl.format(name = rctx.attr.name, requirement = rctx.attr.requirement.split(" ", 1)[0]),
379376
arguments = args,
380-
environment = environment,
377+
# Manually construct the PYTHONPATH since we cannot use the toolchain here
378+
environment = _create_repository_execution_environment(rctx, python_interpreter, logger = logger),
381379
srcs = rctx.attr._python_srcs,
382380
quiet = rctx.attr.quiet,
383381
timeout = rctx.attr.timeout,
@@ -414,7 +412,8 @@ def _whl_library_impl(rctx):
414412
python_interpreter = python_interpreter,
415413
args = args,
416414
whl_path = whl_path,
417-
environment = environment,
415+
# Manually construct the PYTHONPATH since we cannot use the toolchain here
416+
environment = _create_repository_execution_environment(rctx, python_interpreter, logger = logger),
418417
logger = logger,
419418
)
420419

0 commit comments

Comments
 (0)