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

fix(pip.parse): allow absolute path for python_interpreter; skip hermetic toolchain lookup when used #1619

Merged
merged 2 commits into from
Dec 16, 2023
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ A brief description of the categories of changes:
`experimental_target_platforms = ["all"]` to the `pip_parse` or the `bzlmod`
equivalent. This may help in cases where fetching wheels for a different
platform using `download_only = True` feature.
* (bzlmod pip.parse) The `pip.parse(python_interpreter)` arg now works for
specifying a local system interpreter.

[0.XX.0]: https://github.com/bazelbuild/rules_python/releases/tag/0.XX.0

Expand Down
7 changes: 6 additions & 1 deletion python/pip_install/pip_repository.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ def _resolve_python_interpreter(rctx):

Args:
rctx: Handle to the rule repository context.
Returns: Python interpreter path.

Returns:
`path` object, for the resolved path to the Python interpreter.
"""
python_interpreter = _get_python_interpreter_attr(rctx)

Expand All @@ -91,10 +93,13 @@ def _resolve_python_interpreter(rctx):
if os == WINDOWS_NAME:
python_interpreter = python_interpreter.realpath
elif "/" not in python_interpreter:
# It's a plain command, e.g. "python3", to look up in the environment.
found_python_interpreter = rctx.which(python_interpreter)
if not found_python_interpreter:
fail("python interpreter `{}` not found in PATH".format(python_interpreter))
python_interpreter = found_python_interpreter
else:
python_interpreter = rctx.path(python_interpreter)
return python_interpreter

def _get_xcode_location_cflags(rctx):
Expand Down
11 changes: 6 additions & 5 deletions python/private/bzlmod/pip.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def _create_whl_repos(module_ctx, pip_attr, whl_map, whl_overrides):
# if we do not have the python_interpreter set in the attributes
# we programmatically find it.
hub_name = pip_attr.hub_name
if python_interpreter_target == None:
if python_interpreter_target == None and not pip_attr.python_interpreter:
python_name = "python_" + version_label(pip_attr.python_version, sep = "_")
if python_name not in INTERPRETER_LABELS.keys():
fail((
Expand Down Expand Up @@ -357,13 +357,14 @@ Targets from different hubs should not be used together.
"python_version": attr.string(
mandatory = True,
doc = """
The Python version to use for resolving the pip dependencies, in Major.Minor
format (e.g. "3.11"). Patch level granularity (e.g. "3.11.1") is not supported.
The Python version the dependencies are targetting, in Major.Minor format
(e.g., "3.11"). Patch level granularity (e.g. "3.11.1") is not supported.
If not specified, then the default Python version (as set by the root module or
rules_python) will be used.

The version specified here must have a corresponding `python.toolchain()`
configured.
If an interpreter isn't explicitly provided (using `python_interpreter` or
`python_interpreter_target`), then the version specified here must have
a corresponding `python.toolchain()` configured.
""",
),
"whl_modifications": attr.label_keyed_string_dict(
Expand Down