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

--constraints in pex #335

Merged
merged 6 commits into from
Jan 11, 2017
Merged

--constraints in pex #335

merged 6 commits into from
Jan 11, 2017

Conversation

toumorokoshi
Copy link
Contributor

@toumorokoshi toumorokoshi commented Dec 30, 2016

this is an implementation of adding constraint support to pex:

https://pip.pypa.io/en/stable/user_guide/#constraints-files

As the "-c" keyword is already used, this implementation opts for "--constraint" by itself.

It works pretty well:

pex requests --constraints constraints.txt -o /tmp/requests.pex

with the constraints file

requests==2.12.1
aiohttp==1.2.0

resulted in a pex that had requests versioned 2.12.1, but not aiohttp.

I really wanted to start the conversation with this PR: I'm new to the Pex code and didn't know the best place to implement this, so I wanted to get feedback on an approach before doing a bunch of work to add tests.

One issue along the way: conflicts arose when attempting to reference the same package twice:

pex requests requests==2.12.1 -o /tmp/requests.pex

This was caused by a lack of semantic equality in the WheelPackage, so I added that too. Happy to pick that up in another PR/Issue if that's more appropriate.

@toumorokoshi toumorokoshi changed the title --constraints in pex --constraint in pex Dec 30, 2016
@toumorokoshi toumorokoshi changed the title --constraint in pex --constraints in pex Dec 30, 2016
@@ -477,6 +487,13 @@ def build_pex(args, options, resolver_option_builder):
for requirements_txt in options.requirement_files:
resolvables.extend(requirements_from_file(requirements_txt, resolver_option_builder))

for constraints_txt in options.constraint_files:
constraints = []
for r in requirements_from_file(constraints_txt, resolver_option_builder):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

pip states the constraints format is identical to requirements:

https://pip.pypa.io/en/stable/user_guide/#constraints-files

so I figured the way to guarantee that in pex was to share the requirements code.

Copy link
Contributor

Choose a reason for hiding this comment

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

seems like a good tidbit to put into a comment

Copy link
Contributor

@kwlzn kwlzn left a comment

Choose a reason for hiding this comment

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

thanks for the PR! seems reasonable to me - would be great to circle back with some tests to verify/ensure the constraint behavior.

default=[],
type=str,
action='append',
help='Add requirements from the given requirements file. This option can be used multiple '
Copy link
Contributor

Choose a reason for hiding this comment

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

should this read Add constraints from the given constraints file instead?

@toumorokoshi
Copy link
Contributor Author

@kwlzn @sixninetynine thanks for reviewing! added unit tests.

Copy link
Contributor

@kwlzn kwlzn left a comment

Choose a reason for hiding this comment

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

looks great - thanks! I have one last request around test coverage here that I think is important - let me know what you think.

builder = ResolverOptionsBuilder()
rs = _ResolvableSet()
constraint = ResolvableRequirement.from_string('foo', builder)
constraint.is_constraint = True
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe I'm missing something, but I'd expect to see a test here that:

  1. adds a constraint for foo==$SOME_VERSION.
  2. adds a non-constraint requirement for foo.
  3. given multiple visible foo versions (some higher, some lower than $SOME_VERSION), selects the appropriate one based on the constraint.

and then maybe another variant of that which doesn't apply the constraint and would end up with the very latest version of foo available under the same conditions (sans the constraint)?

seem reasonable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, that makes sense. the latter sounds like a unit test that should already exist (since that's just testing standard requirement behavior), but I can add both.

@kwlzn kwlzn mentioned this pull request Jan 6, 2017
@toumorokoshi
Copy link
Contributor Author

@kwlzn how does this look?

Copy link
Contributor

@kwlzn kwlzn left a comment

Choose a reason for hiding this comment

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

lgtm! thanks

@kwlzn kwlzn merged commit 23e333e into pex-tool:master Jan 11, 2017
@kwlzn
Copy link
Contributor

kwlzn commented Jan 11, 2017

@toumorokoshi thanks for the PR! and sorry for the delay on reviewing this - I've been out sick for a couple of days.

@bloomonkey bloomonkey mentioned this pull request Apr 5, 2017
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.

3 participants