Skip to content

Commit 91b3224

Browse files
aignasrickeylev
andcommitted
fix(pypi): build the environment on the fly (bazel-contrib#3720)
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 bazel-contrib#3712 --------- Co-authored-by: Richard Levasseur <richardlev@gmail.com> (cherry picked from commit 19a2c04)
1 parent 577bb1f commit 91b3224

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

CHANGELOG.md

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

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

python/private/pypi/whl_library.bzl

Lines changed: 8 additions & 3 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:
@@ -361,6 +358,14 @@ def _whl_library_impl(rctx):
361358
enable_pipstar = (rp_config.enable_pipstar or whl_path) and rctx.attr.config_load
362359
enable_pipstar_extract = enable_pipstar and rp_config.bazel_8_or_later
363360

361+
# When pipstar is enabled, Python isn't used, so there's no need
362+
# to setup env vars to run Python, unless we need to build an sdist
363+
if enable_pipstar_extract and whl_path:
364+
environment = {}
365+
else:
366+
# Manually construct the PYTHONPATH since we cannot use the toolchain here
367+
environment = _create_repository_execution_environment(rctx, python_interpreter, logger = logger)
368+
364369
if not whl_path:
365370
if rctx.attr.urls:
366371
op_tmpl = "whl_library.BuildWheelFromSource({name}, {requirement})"

0 commit comments

Comments
 (0)