-
-
Notifications
You must be signed in to change notification settings - Fork 646
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
Allow --python-setup-requirement-constraints
to work with inline requirements
#10723
Comments
I think always having a target is better. It's no big hardship to require a target, and consistency is important. And no particular need to restrict the number of sources to 0 or 1, even, |
|
AFAICT, there is no need to restrict to a single lockfile now, just to a single set of constraints, now represented by this target. They can be spread over multiple lockfiles. No? |
Yes, they can be. But why? The one use case I was imagining was that you have your inlined constraints from I can't imagine why you'd have two distinct constraints files if they are both meant to act as one. Two constraints files in general? Absolutely. But if they end up getting merged by Pants into one file, then I don't see the reason, and that merging could be confusing as it violates expectations. |
I just don't see the need to impose artificial constraints. If the "unit" of resolution is a target, then let that target do whatever... Maybe people want to split the lockfile just to make it easy to edit or manage in some way, for example. In other words, let's lean in to "a resolve is represented by a target", and then there's no need to fuss about how many files and/or inline constraints that target encapsulates. |
That's true. What we can do then is have this new implementation call (One of my concerns was thinking that we had to manually merge the files ourselves. The fact that we can just pass it through to Pex makes me feel better.) |
Yep! The true underlying concept is a "resolve", not a file. Can probably even support sources and inline constraints in the same target? |
@jsirois could you weigh in briefly on the idea of a |
I haven't thought about the inline
Since we only actually need a constraints.txt materialized to a chroot for Pex to see, couldn't we just directly materialize one there? |
Yes, and this is the plan. But we need a mechanism for the very generic |
My point is why does it need to be modeled as a macro? Is that just aping the precedent of |
For robust Pipenv/Poetry support, we have two requirements:
We might not need need a macro for the lockfile part, I'm not sure. I think we do need it for the second requirement, though, as we need to generate multiple targets dynamically. |
I'm studiously trying to avoid implementing this but also nudge, so please forgive the pushing: Aren't all targets dynamically generated via rules? We parse BUILD files in rules now - that's no longer a special step like it was in v1. Couldn't a rule parse pipenv files to generate targets? |
This is roughly how we expect that a |
Hm, I've been working on this and a bit stuck. @stuhood and I decided that we should continue to support But it's tricky to have the option either be a file or a target address, as our code is currently factored, for example, to fail if a target cannot be resolved invalid. I'm thinking, instead, add a new option We can tighten it up once we figure out what multiple lockfiles looks like from a user perspective. |
…ry macro (#11724) Closes #10723. This adds a new `_python_constraints` target, which allows defining the constraints as a list of strings in a BUILD file, rather than needing a constraints file on disk. This is useful for macros because they can generate this target. As decided in that issue, we do not require using this new target - users can continue to use a file on disk via `[python-setup].requirement_constraints`. It's not yet clear how this new target type will be used as we add support for multiple lockfiles, so the target is made private for now and its main intended use is macros like Pipenv and Poetry. [ci skip-rust] [ci skip-build-wheels]
Problem
We need to be able to have constraints files work with constraints declared inline, e.g. through strings in a BUILD file, like this:
Why? This blocks macros for Pipenv and Poetry working with constraints files #10655. Those need to be able to generate a target "in-memory" for the constraints, rather than writing to disk and saving that file to VCS.
For now, we will continue to support only one lockfile. You should probably only be able to do inline constraints, or do an actual file on disk. It doesn't make sense yet to be able to mix both.
Note that a single
_python_constraints
target is meant to represent the entire resolve, rather than one single constraint. This will be a key detail when we add multiple lockfiles: users choose the entire lockfile they want, rather than mixing pieces of different ones.Approach
(Edit history: this originally considered always requiring a
python_constraints
for the[python-setup]
option, rather than allowing for a file still. We allow either to maintain API flexibility because things will likely change soon for multiple lockfiles, and we don't want to break the API multiple times.)Define a new target type in
backend/python/target_types.py
through the Target API. See https://www.pantsbuild.org/v2.4/docs/target-api-new-targets.COMMON_TARGET_FIELDS
and a new field likeConstraints(StringSequence)
. It doesn't make sense to haveDependencies
, for example._python_constraints
for now, i.e. a private API, so that we can keep flexibility with changing things. For now, this is solely intended for macro consumption.backend/python/register.py
.Update
python_setup.py
for--requirement-constraints
.file_option
because this eagerly validates that the file actually exists on disk. Usetype=str
. See https://www.pantsbuild.org/v2.4/docs/rules-api-subsystems.help
message andmetavar
, but let's not do that yet until we decide to graduate the target to be public.requirement_constraints
to explain it could either be a file path or a target address.TODO: finish updating step 3
pex.py
andpex_from_targets.py
. This uses the Rules API, so check out https://www.pantsbuild.org/v2.4/docs/rules-api-concepts if you haven't yet.pex.py
.pex_from_targets.py
is a little tricky, and can be approached afterpex.py
through factoring up a new helper@rule
../pants --isort-skip --black-skip fmt src/python/pants/util/strutil.py
. Because you're changingpex.py
, it will cause all the PEXes to be rebuilt for things like Docformatter. Docformatter builds extremely quickly, so this will be the fastest way to iterate. You can also addlogger.info()
calls topex.py
to debug things.await Get(WrappedTarget, AddressInput, AddressInput.parse(python_setup.requirement_constraints)
. This will resolve the raw address string like3rdparty/python:constraints
into a properTarget
. (WrappedTarget
has a fieldtarget: Target
)WrappedTarget
, you can use the Target API, e.g.wrapped_tgt.target[PythonConstraints].value
to get the raw string sequence.constraint_file_digest = await Get(Digest, PathGlobs)
, we can useawait Get(Digest, CreateDigest([FileContent("constraints.generated.txt", formatted_constraints_from_previous_step.encode())])
. See https://www.pantsbuild.org/v2.0/docs/rules-api-file-system for what this all means.argv.extend(["--constraints", python_setup.requirement_constraints])
to instead beargv.extend(["--constraints", "constraints.generated.txt"])
.The text was updated successfully, but these errors were encountered: