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

UV_SYSTEM_PYTHON cannot be switched off #3000

Closed
hynek opened this issue Apr 11, 2024 · 7 comments · Fixed by #3001
Closed

UV_SYSTEM_PYTHON cannot be switched off #3000

hynek opened this issue Apr 11, 2024 · 7 comments · Fixed by #3001
Assignees
Labels
needs-design Needs discussion, investigation, or design

Comments

@hynek
Copy link
Contributor

hynek commented Apr 11, 2024

I'm using uv as part of a GitHub Action and have noticed that when the caller sets UV_SYSTEM_PYTHON=true, it cannot be undone by locally setting UV_SYSTEM_PYTHON=false although the error indicates that false is a valid value. I always get the "system is incompatible with python":

$ env UV_SYSTEM_PYTHON=false uv pip install --python .venv/bin/python ruff
error: the argument '--python <PYTHON>' cannot be used with '--system'
$ uv --version
uv 0.1.31 (7bcca28b1 2024-04-09

I have now solved it by unsetting the variable, but I think this should work?

@charliermarsh
Copy link
Member

Will need to look into it... This is something that Clap does automatically (https://github.com/clap-rs/clap), we just specify the mapping between argument and environment variable.

@hynek
Copy link
Contributor Author

hynek commented Apr 11, 2024

Yeah I've noticed when looking at #2354. Since this problem will likely manifest itself elsewhere too, I hope this doesn't mean you have a clap rewrite on your plate, too. 😬

@charliermarsh charliermarsh self-assigned this Apr 11, 2024
@charliermarsh charliermarsh added the needs-design Needs discussion, investigation, or design label Apr 11, 2024
@charliermarsh
Copy link
Member

Hahah don't worry I have enough on my plate to be comfortable passing on that one :)

@charliermarsh
Copy link
Member

I suspect the problem here is actually that Clap thinks both --system and --python are being passed (even though --system is falsey).

@charliermarsh
Copy link
Member

If you omit --python, do you see the right behavior? uv would default to .venv anyway, as long as --system is false. (We should fix the interaction here, I'm just confirming the diagnosis...)

@hynek
Copy link
Contributor Author

hynek commented Apr 11, 2024

It does, but it has bad interactions with venv too (which is what sent me down this path):

nox > Running session tests-3.8(opt_deps=[])
nox > Creating virtual environment (uv) using python3.8 in .nox/tests-3-8-opt_deps
nox > Command uv venv -p python3.8 /home/runner/work/stamina/stamina/.nox/tests-3-8-opt_deps failed with exit code 2:
error: the argument '--python <PYTHON>' cannot be used with '--system'

@charliermarsh
Copy link
Member

Okay, I believe I know how to fix this.

charliermarsh added a commit that referenced this issue Apr 12, 2024
## Summary

It turns out that if you have an environment variable set, Clap will
consider that equivalent to passing the flag, even if it's set to (e.g.)
something falsy or the default value.

So, e.g., this fails:

```shell
UV_SYSTEM=false uv pip install --python ./.venv/bin/python flask
```

Worse, this fails, because it thinks `--no-index` and `--index-url` are
conflicting:

```shell
export UV_INDEX_URL=https://google.com
uv pip install flask --no-index
```

This PR removes some of the conflicts, namely those related to
environment variables, such that:

- You _can_ pass mixes of `--no-index`, `--index-url`, etc. If
`--no-index` is provided, all the index URLs will be ignored (but we
won't error).
- Passing `--pre` will always enable prereleases, even if `--prerelease`
is also provided. (We could warn here, although honestly it's not
trivial because we'd need to make `--prerelease` take an optional, then
we'd lose the default argument from the `--help`.)
- You _can_ pass `--system` and `--python`. If `--python` is provided,
we use that, and ignore `--system`. (We could warn here.)

I guess the underlying problem here is that we can't differentiate
between arguments passed on the CLI and those set as environment
variables. But making bigger changes here seems out-of-scope.

Closes #3000.
charliermarsh added a commit that referenced this issue May 24, 2024
## Summary

Allows, e.g., `UV_SYSTEM_PYTHON=false uv pip install --python
.venv/bin/python`.

This was intended to work after fixing
#3000, but I think I misdiagnosed
the scope when closing that issue, and the linked PR there only fixed
some _other_ problems around index URLs.

The only thing we really lose here is we no longer error when
`--break-system-packages` is provided without `--system`, but we can
enforce that elsewhere if we want.

Closes #3829.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-design Needs discussion, investigation, or design
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants