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

Support combining markers? #540

Open
pfmoore opened this issue Apr 27, 2022 · 1 comment
Open

Support combining markers? #540

pfmoore opened this issue Apr 27, 2022 · 1 comment

Comments

@pfmoore
Copy link
Member

pfmoore commented Apr 27, 2022

I'm trying to write a PEP 621 consumer, and I'm having trouble with the optional-dependencies item. The issue is that I could potentially need to combine markers, and I don't see a particularly reliable way of doing so. Consider:

[project.optional-dependencies]
test = [
  "pytest < 5.0.0",
  "pytest-cov[all]",
  "pywin32; os_name == 'nt'"
]

To construct Requires-Dist from this, I need to add a dependency pywin32; os_name == 'nt' and extra == 'test'.

The best way I can see of doing this is

req = Requirement(req_str)
if req.marker is None:
    req.marker = Marker(f"extra == '{extra_name}'")
else:
    req.marker = Marker(f"({req.marker}) and extra == '{extra_name}'")

requires_dist.append(str(req))

Is that the best way of doing this? It would be extremely useful in this situation if markers supported & and | operations, to avoid the error-prone conversion to and from strings.

@brettcannon
Copy link
Member

Is that the best way of doing this?

It's at least what first came to mind for me. 😁

I think this also ties into #496 which wanted to expose the AST of markers.

But otherwise overriding & and | to combine markers seems reasonable to me as a way to build them up.

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

3 participants
@brettcannon @pfmoore and others