-
-
Notifications
You must be signed in to change notification settings - Fork 652
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
Start creating binary
goal with support for python
#8399
Conversation
src/python/pants/backend/python/rules/interpreter_constraints.py
Outdated
Show resolved
Hide resolved
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.
Thanks!
src/python/pants/backend/python/rules/interpreter_constraints.py
Outdated
Show resolved
Hide resolved
cb17e91
to
7ab2758
Compare
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.
This turned out really, really nicely. Thank you @gshuflin !
for target_adaptor in all_targets | ||
] | ||
|
||
#TODO This way of calculating the entry point works but is a bit hackish. |
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.
Would you mind expanding on this before landing? or opening a ticket?
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.
Opened a ticket for this.
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.
This is great! I love how you deduplicated interpreter constraints and requirements parsing.
|
||
|
||
@dataclass(frozen=True) | ||
class CreatePex: | ||
"""Represents a generic request to create a PEX from its inputs.""" | ||
output_filename: str | ||
requirements: Tuple[str] = () | ||
interpreter_constraints: Tuple[str] = () | ||
requirements: PexRequirements = PexRequirements() |
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.
What about instead making this Optional[PexRequirements] = None
? That more clearly signals to me that there are no requirements by default, rather than having to rely on knowing that PexRequirement()
will be empty by default.
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.
Hm, I have a slight preference for letting the type of this member be non-optional PexRequirements
, since it means there's not two ways to represent "no requirements" (None
and empty PexRequirements()
) with identical semantics. Same for PexInterpreterConstraints
.
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.
Yep. @Eric-Arellano : this is the "null object" pattern.
requirements: Tuple[str] = () | ||
interpreter_constraints: Tuple[str] = () | ||
requirements: PexRequirements = PexRequirements() | ||
interpreter_constraints: PexInterpreterContraints = PexInterpreterContraints() |
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.
Ditto on Optional[PexInterpreterContraints] = None
interpreter_constraint_args = [] | ||
for constraint in request.interpreter_constraints: | ||
interpreter_constraint_args.extend(["--interpreter-constraint", constraint]) | ||
interpreter_constraint_args = request.interpreter_constraints.generate_pex_arg_list() |
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.
You can inline this to line 107 so that line 107 becomes:
argv.extend(request.interpreter_constraints.generate_pex_arg_list())
def create_pex_and_get_all_data(self, *, requirements=None, entry_point=None, interpreter_constraints=None, | ||
def create_pex_and_get_all_data(self, *, requirements=PexRequirements(), | ||
entry_point=None, | ||
interpreter_constraints=PexInterpreterContraints(), |
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.
If you take my recommendation about interpreter constraints being optional, I would still recommend this being None
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.
Exciting! :D
path = 'dist/', | ||
directory_digest = binary.digest, | ||
) | ||
output = workspace.materialize_directories((dtm,)) |
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.
If materialize_directories
takes a tuple, why not make a tuple of the directories to materialize and do them in one call in parallel, rather than in a loop?
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.
Good idea!
all_target_requirements = [] | ||
for maybe_python_req_lib in adaptors: | ||
# This is a python_requirement()-like target. | ||
if hasattr(maybe_python_req_lib, 'requirement'): |
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.
Not for this PR, but in general RE #4535 it would be nice if this were maybe detected by superclass (and then a property access) rather than by grabbing around for raw field names...
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.
Absolutely, but yeah I don't want to handle that chunk of work until this PR is merged.
Problem
We need a version of the 'binary' goal that runs on the v2 engine.
Solution
This code creates a
@console_rule
for thebinary
goal, the necessary type boilerplate, implements treating a pants-created Python PEX as a binary, and writes it to thedist
directory.