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

Provide a mechanism to AND interpreter constraint strings #914

Closed
Eric-Arellano opened this issue Mar 4, 2020 · 2 comments
Closed

Provide a mechanism to AND interpreter constraint strings #914

Eric-Arellano opened this issue Mar 4, 2020 · 2 comments

Comments

@Eric-Arellano
Copy link
Contributor

In #678, we changed --interpreter-constraint to OR between multiple values. This is useful for disjoint constraints, e.g. CPython==2.7.* OR CPython>=3.5.

We explained that you can AND by using a single constraint, e.g. CPython>=3.5,<3.6.

However, there is no way to AND with the entire requirement string, e.g. there is no way to say CPython==3.7.* AND CPython==3.8.0 without manually merging the constraints into one.

While this may be fine for most usages, Pants needs to be able to AND the entire requirement string. Specifically, in Pants, constraints should be ANDed accross targets (but ORed within the target). For example, the below results in CPython==3.7.* AND CPython==3.6.*.

python_library(
  name="dep_global",
  source="test_compat.py",
)

python_library(
  name="dep",
  source="test_compat.py",
  compatibility='CPython==3.7.*',
)

python_tests(
  name = 'compat',
  source='test_compat.py',
  dependencies=[":dep", ":dep_global"],
  compatibility='CPython==3.6.*',
)

It's not clear what the API should look like for this. --interpreter-constraint should certainly still OR. Possibly, we introduce a new flag?

Possibly we parametrize whether --interpreter-constraint should OR vs. AND? (Although, we may likely need to support both. It's unclear to me if we can use static analysis to avoid this by having Pants pre-process the constraints.)

@Eric-Arellano
Copy link
Contributor Author

I think I saw a library last week that understands requirement strings and can do algebra between them, such as merging them. I'm going to first explore if we can use that approach of static analysis before having to resort to this change to Pex.

@Eric-Arellano
Copy link
Contributor Author

Per the suggestion in #918 (comment), the needed functionality was achieved in Pants by combining requirement strings there to AND where necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant