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

Allow single constraints and overrides to be passed via the CLI #9614

Open
zanieb opened this issue Dec 3, 2024 · 11 comments
Open

Allow single constraints and overrides to be passed via the CLI #9614

zanieb opened this issue Dec 3, 2024 · 11 comments
Assignees
Labels
cli Related to the command line interface

Comments

@zanieb
Copy link
Member

zanieb commented Dec 3, 2024

The --constraint and --override flags should be updated to allow single constraints (in addition to the current behavior of accepting a file path), e.g., --constraint "foo>=0.1". In the --constraint case, this is mostly unambiguous — if there's a version specifier then we can treat it as a constraint. It is possible to have a file with that name, but it seems very unlikely in practice. In the --override case, we do allow overriding a dependency to have no specifiers, e.g., --override foo. I'm not sure if we should allow this via this interface? It seems nice to avoid the ambiguity. Historically, we've avoided inspecting the file system to determine the behavior of arguments and I think that is a good goal to maintain.

Previous discussion at

@zanieb zanieb added the cli Related to the command line interface label Dec 3, 2024
@zanieb
Copy link
Member Author

zanieb commented Dec 3, 2024

This proposal applies to both the uv pip interface (though it would differ from the upstream) and top-level interface (where --constraint and --override is only implemented for uv tool install at the moment but should be added elsewhere)

@notatallshaw-gts
Copy link

It is possible to have a file with that name, but it seems very unlikely in practice

You could always check for a file first and then fall back to see if it's a valid version specifier (that includes an operator, e.g. foo>=0.1 not just foo).

@zanieb
Copy link
Member Author

zanieb commented Dec 3, 2024

You could always check for a file first and then fall back to see if it's a valid version specifier

This is the behavior we have historically avoided. We don't want the CLI behavior to change based on the state of the file system.

@notatallshaw-gts
Copy link

notatallshaw-gts commented Dec 3, 2024

You could always check for a file first and then fall back to see if it's a valid version specifier

This is the behavior we have historically avoided. We don't want the CLI behavior to change based on the state of the file system.

Okay but constraints.txt is a valid requirement 😉.

>>> from packaging.requirements import Requirement
>>> Requirement('constraints.txt')
<Requirement('constraints.txt')>

And that is likely to be the name of a file, so I guess document this carefully on what the boundary conditions are between choosing a file or a requirement.

@notatallshaw-gts
Copy link

we do allow overriding a dependency to have no specifiers, e.g., --override foo

One last thing, the one use case to be aware of here is when specifying an always falsey environment marker, e.g. foo ; sys_platform == 'never'.

@zanieb
Copy link
Member Author

zanieb commented Dec 3, 2024

Okay but constraints.txt is a valid requirement 😉.

Yeah so that's why I said we'd require a version specifier. A constraint without a version specifier doesn't do anything.

One last thing, the #4422 (comment) to be aware of here is when specifying an always falsey environment marker, e.g. foo ; sys_platform == 'never'.

Good point!

@charliermarsh
Copy link
Member

charliermarsh commented Dec 4, 2024

Yeah, I guess we'd say: if it includes ;, =, <, or > (and not / or \) we treat it as a specifier.

@notatallshaw-gts
Copy link

:

Do you mean ;?

@charliermarsh
Copy link
Member

charliermarsh commented Dec 4, 2024

Yes, sorry. (Edited.)

@charliermarsh charliermarsh self-assigned this Dec 7, 2024
@charliermarsh
Copy link
Member

@zanieb -- Just noticed one problem here... The values are technically space-delimited, so you can do UV_CONSTRAINTS="file1 file2" etc. That was initially for pip compatibility. But if they're space-delimited, it becomes much harder to do this... Not impossible, but definitely harder.

@zanieb
Copy link
Member Author

zanieb commented Dec 7, 2024

Alas. I'm not sure what to do about that.

As a minor note, it's UV_CONSTRAINT.

One alternative option: we could align on the name in the pyproject.toml, which would be --dependency-constraint and --dependency-override. I don't love the setting name though (I find it non-obvious).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli Related to the command line interface
Projects
None yet
Development

No branches or pull requests

3 participants