-
Notifications
You must be signed in to change notification settings - Fork 542
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
feat(pypi): support env markers in requirements files #2059
feat(pypi): support env markers in requirements files #2059
Conversation
Since #2000 is introducing useful helpers, I am gonna wait until that is merged and this PR is getting a little big, so I'm gonna need to split it into smaller portions. |
This is just a small PR to reduce the scope of bazelbuild#2059. Work towards bazelbuild#260, bazelbuild#1105, bazelbuild#1868.
…around This is extra preparation needed for bazelbuild#2059. Summary: - Create `pypi_repo_utils` for more ergonomic handling of Python in repo context. - Split the resolution of requirements files to platforms into a separate function to make the testing easier. This also allows more validation that was realized that there is a need for in the WIP feature PR. - Make the code more robust about the assumption of the target platform label. Work towards bazelbuild#260, bazelbuild#1105, bazelbuild#1868.
d93f1ae
to
69a296a
Compare
currently stacked on #2069 |
…around This is extra preparation needed for bazelbuild#2059. Summary: - Create `pypi_repo_utils` for more ergonomic handling of Python in repo context. - Split the resolution of requirements files to platforms into a separate function to make the testing easier. This also allows more validation that was realized that there is a need for in the WIP feature PR. - Make the code more robust about the assumption of the target platform label. Work towards bazelbuild#260, bazelbuild#1105, bazelbuild#1868.
…around (#2069) This is extra preparation needed for #2059. Summary: - Create `pypi_repo_utils` for more ergonomic handling of Python in repo context. - Split the resolution of requirements files to platforms into a separate function to make the testing easier. This also allows more validation that was realized that there is a need for in the WIP feature PR. - Make the code more robust about the assumption of the target platform label. Work towards #260, #1105, #1868.
69a296a
to
2106402
Compare
Move more things to repo_utils and stop using watch_tree, because it also starts watching __pycache__ files, that is causing excesive restarts. What is more, we previously where using uname to get the OS, but it does not make sense to do that, we can use rctx.os.name instead and common utilities. What is more, be more explicit about what OSes are supported in the local_runtime_repo.
…s ready for final review a better test should be added
… added to the bzlmod lockfile to re-evaluate the files if the sources change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Self review.
python/private/pypi/requirements_parser/resolve_target_platforms.py
Outdated
Show resolved
Hide resolved
with args.input_path.open() as f: | ||
reqs = json.load(f) | ||
|
||
response = {} | ||
for requirement_line, target_platforms in reqs.items(): | ||
entry, prefix, hashes = requirement_line.partition("--hash") | ||
hashes = prefix + hashes | ||
|
||
req = Requirement(entry) | ||
for p in target_platforms: | ||
(platform,) = Platform.from_string(p) | ||
if not req.marker or req.marker.evaluate(platform.env_markers("")): | ||
response.setdefault(requirement_line, []).append(p) | ||
|
||
with args.output_path.open("w") as f: | ||
json.dump(response, f) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently there are no unit tests, but if we agree on the approach I could add a few.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's fine. Whether we run a python program, uv, or Starlark, how we evaluate the markers is an internal detail, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…o feat/support-requirement-markers
I pushed a couple doc fixes, otherwise LGTM |
Before this change the
all_requirements
and related constants will havepackages that need to be installed only on specific platforms and will mean
that users relying on those constants (e.g.
gazelle
) will need to do extrawork to exclude platform-specific packages. The package managers that that
support outputting such files now include
uv
andpdm
. This might be alsouseful in cases where we attempt to handle non-requirements lock files.
Note, that the best way to handle this would be to move all of the requirements
parsing code to Python, but that may cause regressions as it is a much bigger
change. This is only changing the code so that we are doing extra processing
for the requirement lines that have env markers. The lines that have no markers
will not see any change in the code execution paths and the python interpreter
will not be downloaded.
We also use the
*_ctx.watch
API where available to correctly re-evaluate themarkers if the
packaging
Python sources for this change.Extra changes that are included in this PR:
repo_utils
to have a method forarch
getting from thectx
.local_runtime_repo
to perform the validation not relying on theimplementation detail of the
get_platforms_os_name
.$(UV)
make variable for theuv:current_toolchain
so that we cangenerate the requirements for
sphinx
usinguv
.genrule
anduv
forsphinx
and coso that we can test the
requirement
marker code. Note, therequirement
markers are not working well with the
requirement_cycles
.Fixes #1105.
Fixes #1868.
Work towards #260, #1975.
Related #1663.