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

Add support for respecting VIRTUAL_ENV in project commands via --active #11189

Merged
merged 1 commit into from
Feb 5, 2025

Conversation

zanieb
Copy link
Member

@zanieb zanieb commented Feb 3, 2025

I think UV_PROJECT_ENVIRONMENT is too complicated for use-cases where the user wants to sync to the active environment. I don't see a compelling reason not to make opt-in easier. I see a lot of questions about how to deal with this warning in the issue tracker, but it seems painful to collect them here for posterity.

A notable behavior here — we'll treat this as equivalent to UV_PROJECT_ENVIRONMENT so... if you point us to a valid virtual environment that needs to be recreated for some reason (e.g., new Python version request), we'll happily delete it and start over.

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

zanieb commented Feb 3, 2025

I'm also considering support for UV_PROJECT_ENVIRONMENT=ACTIVE, UV_PROJECT_ENVIRONMENT=VIRTUAL_ENV, or UV_PROJECT_USE_ACTIVE

@zanieb zanieb force-pushed the zb/active branch 3 times, most recently from c2e035a to cc28043 Compare February 3, 2025 19:31
@zanieb zanieb marked this pull request as ready for review February 3, 2025 19:57
@zanieb zanieb requested a review from charliermarsh February 3, 2025 19:57
@danielhollas
Copy link
Contributor

Another advantage of a dedicated flag is discoverability via command help. I was not aware of UV_PROJECT_ENVIRONMENT until now. uv sync --help | grep UV_PROJECT returns nothing.

@zanieb
Copy link
Member Author

zanieb commented Feb 5, 2025

Well, UV_PROJECT_ENVIRONMENT was intended to unblock people in edge-cases, it wasn't intended for use in normal workflows.

@charliermarsh
Copy link
Member

I think we should add this to the docs too before shipping.

@zmeir
Copy link

zmeir commented Feb 6, 2025

Thank you for this @zanieb !

I've been hit by this "issue" several times. From what I've seen, this mostly happens (to me at least) when I'm working on a project with a virtual env created by PyCharm - it creates venv by default, but UV_PROJECT_ENVIRONMENT defaults to .venv. And so I get this warning, delete .venv, and run the command again with UV_PROJECT_ENVIRONMENT=venv.
This will definitely help 😃

One follow-up question though:
Is it possible to set --active as the default via config? Alternatively, is it possible to change the default UV_PROJECT_ENVIRONMENT via config?

tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Feb 6, 2025
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [astral-sh/uv](https://github.com/astral-sh/uv) | patch | `0.5.27` -> `0.5.29` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>astral-sh/uv (astral-sh/uv)</summary>

### [`v0.5.29`](https://github.com/astral-sh/uv/blob/HEAD/CHANGELOG.md#0529)

[Compare Source](astral-sh/uv@0.5.28...0.5.29)

##### Enhancements

-   Add `--bare` option to `uv init` ([#&#8203;11192](astral-sh/uv#11192))
-   Add support for respecting `VIRTUAL_ENV` in project commands via `--active` ([#&#8203;11189](astral-sh/uv#11189))
-   Allow the project `VIRTUAL_ENV` warning to be silenced with `--no-active` ([#&#8203;11251](astral-sh/uv#11251))

##### Python

The managed Python distributions have been updated, including:

-   CPython 3.12.9
-   CPython 3.13.2
-   pkg-config files are now relocatable

See the [`python-build-standalone` release notes](https://github.com/astral-sh/python-build-standalone/releases/tag/20250205) for more details.

##### Bug fixes

-   Always use base Python discovery logic for cached environments ([#&#8203;11254](astral-sh/uv#11254))
-   Use a flock to avoid concurrent initialization of project environments ([#&#8203;11259](astral-sh/uv#11259))
-   Fix handling of `--all-groups` and `--no-default-groups` flags ([#&#8203;11224](astral-sh/uv#11224))

##### Documentation

-   Minor touchups to the Docker provenance docs ([#&#8203;11252](astral-sh/uv#11252))
-   Move content from the `mkdocs.public.yml` into the template ([#&#8203;11246](astral-sh/uv#11246))

### [`v0.5.28`](https://github.com/astral-sh/uv/blob/HEAD/CHANGELOG.md#0528)

[Compare Source](astral-sh/uv@0.5.27...0.5.28)

##### Bug fixes

-   Allow discovering virtual environments from the first interpreter found on the `PATH` ([#&#8203;11218](astral-sh/uv#11218))
-   Clear ephemeral overlays when running tools ([#&#8203;11141](astral-sh/uv#11141))
-   Disable SSL in Git commands for `--allow-insecure-host` ([#&#8203;11210](astral-sh/uv#11210))
-   Fix hardlinks in tar unpacking ([#&#8203;11221](astral-sh/uv#11221))
-   Set base executable when returning virtual environment ([#&#8203;11209](astral-sh/uv#11209))
-   Use base Python for cached environments ([#&#8203;11208](astral-sh/uv#11208))

##### Documentation

-   Add documentation on verifying Docker image attestations ([#&#8203;11140](astral-sh/uv#11140))
-   Add `last updated` to documentation ([#&#8203;11164](astral-sh/uv#11164))

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS4xNTguMSIsInVwZGF0ZWRJblZlciI6IjM5LjE1OC4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiXX0=-->
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

Successfully merging this pull request may close these issues.

4 participants