Commit graph

201 commits

Author SHA1 Message Date
Charlie Marsh
9a76e47888
Allow multiple pinned indexes in tool.uv.sources (#7769)
## Summary

This PR lifts the restriction that a package must come from a single
index. For example, you can now do:

```toml
[project]
name = "project"
version = "0.1.0"
readme = "README.md"
requires-python = ">=3.12"
dependencies = ["jinja2"]

[tool.uv.sources]
jinja2 = [
    { index = "torch-cu118", marker = "sys_platform == 'darwin'"},
    { index = "torch-cu124", marker = "sys_platform != 'darwin'"},
]

[[tool.uv.index]]
name = "torch-cu118"
url = "https://download.pytorch.org/whl/cu118"

[[tool.uv.index]]
name = "torch-cu124"
url = "https://download.pytorch.org/whl/cu124"
```

The construction is very similar to the way we handle URLs today: you
can have multiple URLs for a given package, but they must appear in
disjoint forks. So most of the code is just adding that abstraction to
the resolver, following our handling of URLs.

Closes #7761.
2024-10-15 22:58:15 +00:00
Charlie Marsh
5b391770df
Add support for named and explicit indexes (#7481)
## Summary

This PR adds a first-class API for defining registry indexes, beyond our
existing `--index-url` and `--extra-index-url` setup.

Specifically, you now define indexes like so in a `uv.toml` or
`pyproject.toml` file:

```toml
[[tool.uv.index]]
name = "pytorch"
url = "https://download.pytorch.org/whl/cu121"
```

You can also provide indexes via `--index` and `UV_INDEX`, and override
the default index with `--default-index` and `UV_DEFAULT_INDEX`.

### Index priority

Indexes are prioritized in the order in which they're defined, such that
the first-defined index has highest priority.

Indexes are also inherited from parent configuration (e.g., the
user-level `uv.toml`), but are placed after any indexes in the current
project, matching our semantics for other array-based configuration
values.

You can mix `--index` and `--default-index` with the legacy
`--index-url` and `--extra-index-url` settings; the latter two are
merely treated as unnamed `[[tool.uv.index]]` entries.

### Index pinning

If an index includes a name (which is optional), it can then be
referenced via `tool.uv.sources`:

```toml
[[tool.uv.index]]
name = "pytorch"
url = "https://download.pytorch.org/whl/cu121"

[tool.uv.sources]
torch = { index = "pytorch" }
```

If an index is marked as `explicit = true`, it can _only_ be used via
such references, and will never be searched implicitly:

```toml
[[tool.uv.index]]
name = "pytorch"
url = "https://download.pytorch.org/whl/cu121"
explicit = true

[tool.uv.sources]
torch = { index = "pytorch" }
```

Indexes defined outside of the current project (e.g., in the user-level
`uv.toml`) can _not_ be explicitly selected.

(As of now, we only support using a single index for a given
`tool.uv.sources` definition.)

### Default index

By default, we include PyPI as the default index. This remains true even
if the user defines a `[[tool.uv.index]]` -- PyPI is still used as a
fallback. You can mark an index as `default = true` to (1) disable the
use of PyPI, and (2) bump it to the bottom of the prioritized list, such
that it's used only if a package does not exist on a prior index:

```toml
[[tool.uv.index]]
name = "pytorch"
url = "https://download.pytorch.org/whl/cu121"
default = true
```

### Name reuse

If a name is reused, the higher-priority index with that name is used,
while the lower-priority indexes are ignored entirely.

For example, given:

```toml
[[tool.uv.index]]
name = "pytorch"
url = "https://download.pytorch.org/whl/cu121"

[[tool.uv.index]]
name = "pytorch"
url = "https://test.pypi.org/simple"
```

The `https://test.pypi.org/simple` index would be ignored entirely,
since it's lower-priority than `https://download.pytorch.org/whl/cu121`
but shares the same name.

Closes #171.

## Future work

- Users should be able to provide authentication for named indexes via
environment variables.
- `uv add` should automatically write `--index` entries to the
`pyproject.toml` file.
- Users should be able to provide multiple indexes for a given package,
stratified by platform:
```toml
[tool.uv.sources]
torch = [
  { index = "cpu", markers = "sys_platform == 'darwin'" },
  { index = "gpu", markers = "sys_platform != 'darwin'" },
]
```
- Users should be able to specify a proxy URL for a given index, to
avoid writing user-specific URLs to a lockfile:
```toml
[[tool.uv.index]]
name = "test"
url = "https://private.org/simple"
proxy = "http://<omitted>/pypi/simple"
```
2024-10-15 18:24:23 -04:00
Charlie Marsh
855c1917e1
Respect [tool.uv.sources] in build requirements (#7172)
## Summary

We weren't respecting `tool.uv.sources` for `build-requires`.

Closes https://github.com/astral-sh/uv/issues/7147.
2024-10-15 15:31:04 +00:00
Adam Dangoor
9351652e32
Update dependencies.md with typo fix (stands -> standards) (#8142) 2024-10-12 13:53:36 +01:00
David Szotten
7b9b690b02
document --reinstall with --exclude-newer to ensure downgrades (#6721)
fixes #6676
2024-10-09 23:03:31 +00:00
Zanie Blue
ab80bf5f10
Clarify project environment creation a little (#7941)
Closes https://github.com/astral-sh/uv/issues/7940
2024-10-05 15:02:04 +00:00
bluss
67769a4985
packaged app: use executable named for the project and main function (#7670)
## Summary

Create a function main as the default for a packaged app. Configure the
default executable as:

`example-packaged-app = "example_packaged_app:main"`

Which is often what you want - the executable has the same name as the
app.
The purpose is to more often hit what the user wants, so they don't have
to even rename the command to start developing.

## Test Plan

- existing tests are updated
2024-09-30 17:19:36 -05:00
Charlie Marsh
f67347e72c
Allow multiple source entries for each package in tool.uv.sources (#7745)
## Summary

This PR enables users to provide multiple source entries in
`tool.uv.sources`, e.g.:

```toml
[tool.uv.sources]
httpx = [
  { git = "https://github.com/encode/httpx", tag = "0.27.2", marker = "sys_platform == 'darwin'" },
  { git = "https://github.com/encode/httpx", tag = "0.24.1", marker = "sys_platform == 'linux'" },
]
```

The implementation is relatively straightforward: when we lower the
requirement, we now return an iterator rather than a single requirement.
In other words, the above is transformed into two requirements:

```txt
httpx @ git+https://github.com/encode/httpx@0.27.2 ; sys_platform == 'darwin'
httpx @ git+https://github.com/encode/httpx@0.24.1 ; sys_platform == 'linux'
```

We verify (at deserialization time) that the markers are
non-overlapping.

Closes https://github.com/astral-sh/uv/issues/3397.
2024-09-30 21:16:44 +00:00
Sebastián Ramírez
5fc1495c54
✏️ Fix typo in projects.md (#7784)
## Summary

✏️ Fix typo in `projects.md`

<!-- What's the purpose of the change? What does it do, and why? -->

## Test Plan

<!-- How was it tested? -->

---------

Co-authored-by: Charlie Marsh <charlie.r.marsh@gmail.com>
2024-09-29 19:40:45 +00:00
Charlie Marsh
a3abd89ab0
Note that uv lock --upgrade-package retains locked versions (#7694)
Closes https://github.com/astral-sh/uv/issues/7672.
2024-09-25 22:17:55 +00:00
Charlie Marsh
cc2aa8855a
Add documentation on cache versioning (#7693)
Closes https://github.com/astral-sh/uv/issues/7547.
2024-09-25 22:13:02 +00:00
Jacob Coffee
8259600ca6
Fix - to _ in Packaged applications doc (#7571)
## Summary

Small stale/typo char in docs when generating a project

```
➜ ntp -v uv-test && uv venv --python 3.12 --seed && uv init --app --package example-packaged-app
Directory /tmp/testing/uv-test created and switched to.
Using Python 3.12.4 interpreter at: /Users/coffee/.local/share/mise/installs/python/3.12/bin/python3.12
Creating virtual environment with seed packages at: .venv
 + pip==24.2
Activate with: source .venv/bin/activate.fish
Virtual environment created with Python 3.12 and activated.
Using Python 3.12.4 interpreter at: /Users/coffee/.local/share/mise/installs/python/3.12/bin/python3.12
Creating virtual environment with seed packages at: .venv
 + pip==24.2
Activate with: source .venv/bin/activate.fish
Initialized project `example-packaged-app` at `/private/tmp/testing/uv-test/example-packaged-app`

/tmp/testing/uv-test via  pyenv (uv-test) on ☁  (us-east-2)
➜ tree
   0 B    ┌─ README.md
4096 B    ├─ pyproject.toml
4096 B    │     ┌─ __init__.py
4096 B    │  ┌─ example_packaged_app
4096 B    ├─ src
8192 B ┌─ example-packaged-app
8192 B uv-test
```

## Test Plan

Eyeballs
2024-09-20 08:47:53 +02:00
Charlie Marsh
fda227616c
Allow users to provide pre-defined metadata for resolution (#7442)
## Summary

This PR enables users to provide pre-defined static metadata for
dependencies. It's intended for situations in which the user depends on
a package that does _not_ declare static metadata (e.g., a
`setup.py`-only sdist), and that is expensive to build or even cannot be
built on some architectures. For example, you might have a Linux-only
dependency that can't be built on ARM -- but we need to build that
package in order to generate the lockfile. By providing static metadata,
the user can instruct uv to avoid building that package at all.

For example, to override all `anyio` versions:

```toml
[project]
name = "project"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = ["anyio"]

[[tool.uv.dependency-metadata]]
name = "anyio"
requires-dist = ["iniconfig"]
```

Or, to override a specific version:

```toml
[project]
name = "project"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = ["anyio"]

[[tool.uv.dependency-metadata]]
name = "anyio"
version = "3.7.0"
requires-dist = ["iniconfig"]
```

The current implementation uses `Metadata23` directly, so we adhere to
the exact schema expected internally and defined by the standards. Any
entries are treated similarly to overrides, in that we won't even look
for `anyio@3.7.0` metadata in the above example. (In a way, this also
enables #4422, since you could remove a dependency for a specific
package, though it's probably too unwieldy to use in practice, since
you'd need to redefine the _rest_ of the metadata, and do that for every
package that requires the package you want to omit.)

This is under-documented, since I want to get feedback on the core ideas
and names involved.

Closes https://github.com/astral-sh/uv/issues/7393.
2024-09-18 03:18:05 +00:00
Charlie Marsh
778da3350a
Add --no-editable support to uv sync and uv export (#7371)
## Summary

Closes https://github.com/astral-sh/uv/issues/5792.
2024-09-17 14:50:36 +00:00
Charlie Marsh
9f7d9da449
Prune unzipped source distributions in uv cache prune --ci (#7446)
## Summary

It's very unlikely that retaining these is beneficial, since you tend to
partition the cache by platform anyway.

Closes https://github.com/astral-sh/uv/issues/7394.
2024-09-16 19:18:20 -04:00
Charlie Marsh
8d4b6ca971
Add documentation on platform-specific dependencies (#7411)
## Summary

Closes https://github.com/astral-sh/uv/issues/6758.
2024-09-15 17:55:37 -04:00
Aditya Pratap Singh
3d62154849
Add support for remaining pip-supported file extensions (#7387)
closes #7365 

Summary

This pull request adds support for additional file extension aliases in
the SourceDistExtension and ExtensionError enums. The newly supported
file extensions include .tbz, .tgz, .txz, .tar.lz, .tar.lzma. These
changes align the extensions supported by the SourceDistExtension with
those used in Python packaging tools, enhancing compatibility with a
broader range of source distribution formats.

Test Plan
should be added or updated to verify that the new extensions are
correctly recognized as valid source distributions and that errors are
correctly raised when unsupported extensions are provided.
2024-09-14 19:59:07 +00:00
Aditya Pratap Singh
adcb67a882
Fix documentation typos for uv build --build-constraint flag (#7330)
Summary

This pull request fixes a typo in the --build-constraints flag, which
should be singular (--build-constraint). This update ensures consistency
across the documentation and prevents potential confusion for users.

Closes #7315

## Test Plan
The change was verified by reviewing the relevant documentation files
where the flag is referenced. No functional code changes were made, so
no additional testing is required beyond confirming the documentation
update.

## Tested
The change was tested by visually inspecting the updated documentation
to confirm that the typo has been corrected
2024-09-12 14:07:33 -05:00
Zanie Blue
f22e5ef69a
Avoid selecting prerelease Python installations without opt-in (#7300)
Similar to our semantics for packages with pre-release versions.

We will not use prerelease versions unless there are only prerelease
versions available, a specific version is requested,
or the prerelease version is found in a reasonable source (active
environment, explicit path, etc. but not `PATH`).

For example, `uv python install 3.13 && uv run python --version` will no
longer use `3.13.0rc2` unless that is the only Python version available,
`--python 3.13` is used, or that's the Python version that is present in
`.venv`.
2024-09-11 15:49:33 -05:00
Charlie Marsh
58a157a0ad
Support globs as cache keys in tool.uv.cache-keys (#7268)
## Summary

This has been asked for a few times. There are risks that these checks
could be slow, but they're buyer-beware.

Closes https://github.com/astral-sh/uv/issues/7246.
2024-09-11 15:30:59 -04:00
Charlie Marsh
3f011f3b7b
Add uv run --no-sync (#7192)
## Summary

When `--no-sync` is provided, we won't lock or sync, but we will run the
command in the project environment.

Closes https://github.com/astral-sh/uv/issues/7165.
2024-09-10 17:29:43 -04:00
Zanie Blue
b5cc913d5c
Create py.typed files during uv init --lib (#7232) 2024-09-10 15:16:00 -05:00
Vivien Maisonneuve
e87d8e719d
Fix typo in docs: cache-key -> cache-keys (#7244)
## Summary

The new entry is `tool.uv.cache-keys` (with an `s`), not
`tool.uv.cache-key`.
2024-09-10 09:25:25 -04:00
Bartosz Sławecki
5905f40f50
Use type hints in code from uv init (#7225)
Let's promote type hints!

<!--
Thank you for contributing to uv! To help us out with reviewing, please
consider the following:

- Does this pull request include a summary of the change? (See below.)
- Does this pull request include a descriptive title?
- Does this pull request include references to any relevant issues?
-->

## Summary

<!-- What's the purpose of the change? What does it do, and why? -->
The generated script now annotates the return type of the dummy function
`hello()`.

## Test Plan

<!-- How was it tested? -->
All existing tests have been synced with this update.
2024-09-09 15:37:21 -05:00
Charlie Marsh
4f2349119c
Add support for dynamic cache keys (#7136)
## Summary

This PR adds a more flexible cache invalidation abstraction for uv, and
uses that new abstraction to improve support for dynamic metadata.

Specifically, instead of relying solely on a timestamp, we now pass
around a `CacheInfo` struct which (as of now) contains
`Option<Timestamp>` and `Option<Commit>`. The `CacheInfo` is saved in
`dist-info` as `uv_cache.json`, so we can test already-installed
distributions for cache validity (along with testing _cached_
distributions for cache validity).

Beyond the defaults (`pyproject.toml`, `setup.py`, and `setup.cfg`
changes), users can also specify additional cache keys, and it's easy
for us to extend support in the future. Right now, cache keys can either
be instructions to include the current commit (for `setuptools_scm` and
similar) or file paths (for `hatch-requirements-txt` and similar):

```toml
[tool.uv]
cache-keys = [{ file = "requirements.txt" }, { git = true }]
```

This change should be fully backwards compatible.

Closes https://github.com/astral-sh/uv/issues/6964.

Closes https://github.com/astral-sh/uv/issues/6255.

Closes https://github.com/astral-sh/uv/issues/6860.
2024-09-09 20:19:15 +00:00
Soof Golan
14ebc393fc
treat .tgz the same as .tar.gz (#7201)
## Summary

Fixes #7081 

Treats source distribution `.tgz` the same as `.tar.gz` plans

## Test Plan

Quick Version

```bash
cd $(mktemp -d)
uv init
uv add --dev build
.venv/bin/python -m build -s .
mv -v dist/*tar.gz dist/"$(basename dist/*.tar.gz .tar.gz)".tgz
uv pip install dist/*.tgz
```

Can add a proper test to the branch if requested
2024-09-08 23:09:39 +00:00
Mathieu Kniewallner
eec5403adf
docs(concepts): mention PEP 625 (#7189)
## Summary

Follow-up to
https://github.com/astral-sh/uv/pull/7168#discussion_r1748914880.
2024-09-08 17:28:35 -04:00
Mathieu Kniewallner
8341d810b2
docs: list supported sdist formats (#7168)
## Summary

Explicitly list the formats and extensions that uv supports, based on
[this
list](86ee8d2c01/crates/distribution-filename/src/extension.rs (L70-L77)).
Not a huge fan of adding the section in `concepts/resolution.md`, but I
did not find a better place. Alternatively we could maybe add a
dedicated page that shortly explains Python package types (wheels,
sdists), where such a section could live?

## Test Plan

Local run of the documentation.
2024-09-07 19:16:12 +00:00
FishAlchemist
aa3297a8d7
Replace incorrect `--source and --binary flags with correct --sdist and --wheel flags in uv build` (#7156)
## Summary
Replace incorrect ``--source`` and ``--binary`` flags with correct
``--sdist`` and ``--wheel`` flags in uv build.
 

![image](https://github.com/user-attachments/assets/f72a9c73-bfce-441b-8756-d0cb22afcd7d)

## Test Plan
Run the server locally

![image](https://github.com/user-attachments/assets/f702f19f-96b8-4338-bd1b-e2fb35f5697a)
2024-09-07 07:50:56 -04:00
Charlie Marsh
80f51cee06
Accept --build-constraints in uv build (#7085)
## Summary

Closes #7082.

Closes #7065.
2024-09-05 18:46:36 +00:00
Jakub Beránek
ae16c4e524
Document how to manually update locked package version (#7083)
This PR updates documentation to explicitly mention how to update a
specific package with a locked version to a different version.

Fixes: https://github.com/astral-sh/uv/issues/7019

---------

Co-authored-by: Zanie Blue <contact@zanie.dev>
2024-09-05 16:37:43 +00:00
my1e5
86c8906d10
Update docs on .python-version file (#7051)
## Summary

Closes https://github.com/astral-sh/uv/issues/7027

* When displaying the file structure of a uv-managed project show the
`.python-version` file which is now created by default.
* Mention the purpose of the `.python-version` file in `Guides/Working
on projects/Project structure`
* In `Concepts/Python versions/Project python versions`, changed
sentence about `.python-version` file to reflect the fact it is included
by default so is likely to be present.
2024-09-04 19:22:34 -04:00
Ed Morley
c1effd6b05
Misc projects docs grammar fixes (#7048)
Co-authored-by: Zanie Blue <contact@zanie.dev>
2024-09-04 20:58:36 +00:00
Zanie Blue
5ca3ded53b
Touchup to the project environment config section (#7038) 2024-09-04 15:02:35 -05:00
Zanie Blue
b2cb3bb2ae
Add project docs for project.scripts (#7010)
Closes https://github.com/astral-sh/uv/issues/6998

Common point of confusion because Poetry defines these in
`tool.poetry.scripts`
2024-09-04 12:16:31 -05:00
Charlie Marsh
724a93bfdb
Add documentation for uv build (#6991) 2024-09-04 15:53:14 +00:00
Zanie Blue
88ba1e90a0
Add docs for UV_PROJECT_ENVIRONMENT (#6987) 2024-09-03 19:47:05 -04:00
Zanie Blue
614839e88b
Add optional dependencies section to the lockfile document (#6982)
Closes https://github.com/astral-sh/uv/issues/6729
2024-09-03 19:37:36 -04:00
Ed Morley
a5f1e1c765
Fix typos in docs, error messages and comments (#6910) 2024-09-01 11:37:43 +00:00
Mathieu Kniewallner
c9e4395322
docs: add missing console highlights (#6900)
## Summary

Spotted a few missing `console` highlights in the documentation.
2024-08-31 19:04:19 -04:00
Charlie Marsh
83467f0a51
Fix typos (#6891) 2024-08-30 19:45:33 -04:00
konsti
a39eb61ade
Use windows registry to discover python (#6761)
Our current strategy of parsing the output of `py --list-paths` to get
the installed python versions on windows is brittle (#6524, missing
`py`, etc.) and it's slow (10ms last time i measured).

Instead, we should behave spec-compliant and read the python versions
from the registry following PEP 514.

It's not fully clear which errors we should ignore and which ones we
need to raise.

We're using the official rust-for-windows crates for accessing the
registry.

Fixes #1521
Fixes #6524
2024-08-29 22:48:22 +02:00
Charlie Marsh
cbfc928a9c
Add uv export --format requirements.txt (#6778)
## Summary

The interface here is intentionally a bit more limited than `uv pip
compile`, because we don't want `requirements.txt` to be a system of
record -- it's just an export format. So, we don't write annotation
comments (i.e., which dependency is requested from which), we don't
allow writing extras, etc. It's just a flat list of requirements, with
their markers and hashes.

Closes #6007.

Closes #6668.

Closes #6670.
2024-08-29 17:46:42 +00:00
my1e5
f956ab8fae
Update default hello.py to pass ruff format (#6811)
Closes https://github.com/astral-sh/uv/issues/6808
2024-08-29 10:31:52 -04:00
Charlie Marsh
cef3d35405
Support {package}@{version} in uv tool install (#6762)
## Summary

Closes https://github.com/astral-sh/uv/issues/6759.

Closes https://github.com/astral-sh/uv/issues/6535.
2024-08-28 12:40:49 -04:00
Zanie Blue
75a5066e10
Improvements to the application and library documentation (#6726) 2024-08-27 23:15:12 +00:00
Charlie Marsh
c1e831881b
Update workspace documentation to remove legacy virtual projects (#6720) 2024-08-27 17:31:12 -04:00
Zanie Blue
d5d8375c7e
Update project documentation for the application / library concepts (#6718)
Follows https://github.com/astral-sh/uv/pull/6689 and
https://github.com/astral-sh/uv/pull/6585
2024-08-27 16:22:31 -05:00
Zanie Blue
cee0d2daf5
Improve lockfile concept documentation, add coverage for upgrades (#6698) 2024-08-27 11:20:53 -05:00
Karim Abou Zeid
5ef0375204
Fix docs for disabling build isolation with uv sync (#6674)
Self-explanatory
2024-08-27 08:49:59 -04:00