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 docs for UV_PROJECT_ENVIRONMENT #6987

Merged
merged 2 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions docs/concepts/projects.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,30 @@ use [`uvx`](../guides/tools.md) or
managed = false
```

### Custom project environment paths

The `UV_PROJECT_ENVIRONMENT` environment variable can be used to configure the project virtual
environment path (`.venv` by default).

If a relative path is provided, it will be resolved relative to the workspace root. If an absolute
path is provided, it will be used as-is, i.e. a child directory will not be created for the
environment. If an environment is not present at the provided path, uv will create it.

This option can be used to write to the system Python environment, though it is not recommended.
`uv sync` will remove extraneous packages from the environment by default and, as such, may leave
the system in a broken state.

!!! important

If an absolute path is provided and the setting is used across multiple projects, the
environment will be overwritten by invocations in each project. This setting is only recommended
for use in CI or Docker images.

!!! note

uv does not read the `VIRTUAL_ENV` environment variable during project operations. A warning
will be displayed if `VIRTUAL_ENV` is set to a different path than the project's environment.

## Project lockfile

uv creates a `uv.lock` file next to the `pyproject.toml`.
Expand Down
4 changes: 4 additions & 0 deletions docs/configuration/environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ In addition, uv respects the following environment variables:
packages.
- `UV_TOOL_DIR`: Used to specify the directory where uv will store managed tools.
- `UV_TOOL_BIN_DIR`: Used to specify the "bin" directory where uv will install tool executables.
- `UV_PROJECT_ENVIRONMENT`: Use to specify the path to the directory to use for a project virtual
environment. See the
[project documentation](../concepts/projects.md#custom-project-environment-paths) for more
details.
- `UV_PYTHON_INSTALL_DIR`: Used to specify the directory where uv will store managed Python
installations.
- `UV_PYTHON_INSTALL_MIRROR`: Managed Python installations are downloaded from
Expand Down
7 changes: 7 additions & 0 deletions docs/guides/integration/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,13 @@ Or, you can use `uv run` for any commands that require the environment:
RUN uv run some_script.py
```

!!! tip

Alternatively, the
[`UV_PROJECT_ENVIRONMENT` setting](../../concepts/projects.md#custom-project-environment-paths) can
be set before syncing to install to the system Python environment and skip environment activation
entirely.

### Using installed tools

To use installed tools, ensure the [tool bin directory](../../concepts/tools.md#the-bin-directory)
Expand Down
6 changes: 6 additions & 0 deletions docs/guides/integration/github.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,12 @@ steps:
run: uv run pytest tests
```

!!! tip

The
[`UV_PROJECT_ENVIRONMENT` setting](../../concepts/projects.md#custom-project-environment-paths) can
be used to install to the system Python environment instead of creating a virtual environment.
zanieb marked this conversation as resolved.
Show resolved Hide resolved

## Caching

It may improve CI times to store uv's cache across workflow runs.
Expand Down