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

Start creating binary goal with support for python #8399

Merged
merged 5 commits into from
Oct 9, 2019

Conversation

gshuflin
Copy link
Contributor

@gshuflin gshuflin commented Oct 4, 2019

Problem

We need a version of the 'binary' goal that runs on the v2 engine.

Solution

This code creates a @console_rule for the binary goal, the necessary type boilerplate, implements treating a pants-created Python PEX as a binary, and writes it to the dist directory.

Copy link
Member

@stuhood stuhood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@gshuflin gshuflin force-pushed the v2-binary branch 2 times, most recently from cb17e91 to 7ab2758 Compare October 8, 2019 03:57
@gshuflin gshuflin marked this pull request as ready for review October 8, 2019 03:57
Copy link
Member

@stuhood stuhood left a 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.
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Contributor

@Eric-Arellano Eric-Arellano left a 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()
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Member

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()
Copy link
Contributor

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()
Copy link
Contributor

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(),
Copy link
Contributor

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

Copy link
Contributor

@illicitonion illicitonion left a 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,))
Copy link
Contributor

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?

Copy link
Contributor Author

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'):
Copy link
Contributor

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...

Copy link
Contributor Author

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.

@gshuflin gshuflin merged commit 29acc1c into pantsbuild:master Oct 9, 2019
@gshuflin gshuflin deleted the v2-binary branch October 9, 2019 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants