Commit graph

4810 commits

Author SHA1 Message Date
John Mumm
797f1fbac0
Add support for global uv python pin (#12115)
These changes add support for

```
uv python pin 3.12 --global 
```

This adds the specified version to a `.python-version` file in the
user-level config directory. uv will now use the user-level version as a
fallback if no version is found in the project directory or its
ancestors.

Closes #4972
2025-03-13 13:48:37 +01:00
konsti
b4eabf9a61
Render token claims on publish permission error (#12135)
Match the official trusted publishing GitHub Action from
db8f07d387/oidc-exchange.py (L165-L184)

See
3863562081
for an example of how this renders
2025-03-13 11:19:08 +01:00
John Mumm
be87255539
Refactor *Settings to clarify and reduce repetition (#12138)
When making changes to uv that require new (or altered) settings, there
are many places in the code that need to change. This slows down work,
reduces confidence in changes for new developers, and adds noise to PRs.
The goal of this PR is to reduce the number of points that need to
change (and that the developer needs to understand) when making changes
to settings.

This PR consolidates `ResolverSettings` and `ResolverInstallerSettings`
by factoring out the shared settings and using a new field
`resolver_settings` on `ResolverInstallerSettings`. This not only
reduces repetition, but makes it easier for a human to parse the code
without having to compare long lists of fields to spot differences (the
difference was that `ResolverInstallerSettings` had two extra fields).

This also removes `ResolverSettingsRef` and
`ResolverInstallerSettingsRef`, using normal Rust references instead.
For the time being, I've left `InstallerSettingsRef` in place because it
appears to have a semantic meaning that might be relied upon. However,
it would now be straightforward to refactor to pass
`&ResolverInstallerSettings` wherever `InstallerSettingsRef` appears,
further reducing sprawl.

The change has the downside of adding
`settings.resolver_settings.<field>` and requiring dereferencing at
various points where it was not required before (with the *SettingsRef
approach). But this means there are significantly fewer places that must
change to update settings.
2025-03-13 09:10:28 +01:00
James Z.M. Gao
7fc4e076c1
remove BaseClientBuild::client, expose ExtraMiddleware (#12133)
close #12127 

as discussed in #12127 remove unused BaseClientBuild::client field, and
make base_client::ExtraMiddleware public.
2025-03-12 10:43:21 +00:00
Zanie Blue
c1a0bb85ea
Bump version to 0.6.6 (#12125) 2025-03-12 00:02:48 +00:00
Zanie Blue
b7167dc4d8
Fix uv python install --reinstall when the version is not yet installed (#12124)
I noticed this was failing to perform the install
2025-03-11 23:53:28 +00:00
Zanie Blue
553bcccb6a
Add support for dynamic musl Python distributions on x86-64 Linux (#12121)
Following the upstream release and #12120, removes gating preventing
installation of the managed musl Python versions.

Of note

- The filtering of musl Python distributions has moved from the Rust
runtime to the metadata fetcher
- The filtering is now conditional on the PBS release date, removing all
old static musl distributions
- We could support the `+static` musl downloads in the future; right
now, they are deprioritized when selecting a variant
- I added test to CI which uses Alpine and installs numpy
2025-03-11 18:14:10 -05:00
github-actions[bot]
f3fb1c5a17
Sync latest Python releases (#12120)
Automated update for Python releases.

---------

Co-authored-by: zanieb <2586601+zanieb@users.noreply.github.com>
Co-authored-by: Zanie Blue <contact@zanie.dev>
2025-03-11 20:58:47 +00:00
Zanie Blue
a59778fca3
Update the index.authenticate docs (#12102)
Follow-up to #11896 

Reframes the documentation a bit.

Looking into why the `[index]` child fields aren't generate in the
reference correctly too.
2025-03-11 15:01:42 -05:00
justin
c48af312ae
Add --marker flag to uv add (#12012)
## Summary

Add a `--marker` flag to `uv add` which applies a marker to all given
requirements.

Example:

```
$ uv-debug add --marker "platform_machine == 'x86_64'" \
    "anyio>=2.31.0" \
    "iniconfig>=2; sys_platform != 'win32'" \
    "numpy>1.19; sys_platform == 'win32'"
```

```toml
[project]
name = "project"
version = "0.1.0"
requires-python = ">=3.12.0"
dependencies = [
    "anyio>=2.31.0 ; platform_machine == 'x86_64'",
    "iniconfig>=2 ; platform_machine == 'x86_64' and sys_platform != 'win32'",
    "numpy>1.19 ; platform_machine == 'x86_64' and sys_platform == 'win32'",
]
```

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


## Test Plan

Added snapshot tests

---------

Co-authored-by: konstin <konstin@mailbox.org>
2025-03-11 16:29:36 +01:00
Jean-Michel Rouet
d660882b8d
publish with sized stream to comply with WSGI pypi server constraints. (#12111)
<!--
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

This PR is meant to fix issue #11862 

It allows to send sized bodies during `publish`

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

## Test Plan

the PR was tested on the MRE from #11862 

<!-- How was it tested? -->
2025-03-11 15:54:30 +01:00
samypr100
e096ab2411
Add support for Windows legacy scripts via uv tool run (#12079)
## Summary

Follow up to https://github.com/astral-sh/uv/pull/11888 with added
support for uv tool run.

Changes
* Added functionality for running windows scripts in previous PR was
moved from run.rs to uv_shell::runnable.
* EXE was added as a supported type, this simplified integration across
both uv run and uvx while retaining a backwards compatible behavior and
properly prioritizing .exe over others. Name was adjusted to runnable as
a result to better represent intent.

## Test Plan

New tests added.

## Documentation

Added new documentation.
2025-03-11 09:02:17 -05:00
konsti
82212bb439
Show ambiguous requirements when uv add failed (#12106)
Improves the error message.

Fixes #12105

Co-authored-by: Charlie Marsh <charlie.r.marsh@gmail.com>
2025-03-10 23:00:09 -04:00
konsti
e843433b07
Cache workspace discovery (#12096)
Reduce the overhead of `uv run` in large workspaces. Instead of
re-discovering the entire workspace each time we resolve the metadata of
a member, we can the discovered set of workspace members. Care needs to
be taken to not cache the discovery for `uv init`, `uv add` and `uv
remove`, which change the definitions of workspace members.

Below is apache airflow e3fe06382df4b19f2c0de40ce7c0bdc726754c74 `uv run
python` with a minimal payload. With this change, we avoid a ~350ms
overhead of each `uv run` invocation.

```
$ hyperfine --warmup 2 \
    "uv run --no-dev python -c \"print('hi')\"" \
    "uv-profiling run --no-dev python -c \"print('hi')\""
Benchmark 1: uv run --no-dev python -c "print('hi')"
  Time (mean ± σ):     492.6 ms ±   7.0 ms    [User: 393.2 ms, System: 97.1 ms]
  Range (min … max):   482.3 ms … 501.5 ms    10 runs
 
Benchmark 2: uv-profiling run --no-dev python -c "print('hi')"
  Time (mean ± σ):     129.7 ms ±   2.5 ms    [User: 105.4 ms, System: 23.2 ms]
  Range (min … max):   126.0 ms … 136.1 ms    22 runs
 
Summary
  uv-profiling run --no-dev python -c "print('hi')" ran
    3.80 ± 0.09 times faster than uv run --no-dev python -c "print('hi')"
```

The profile after those change below. We still spend a large chunk in
toml parsing (both `uv.lock` and `pyproject.toml`), but it's not
excessive anymore.


![image](https://github.com/user-attachments/assets/6fe78510-7e25-48ee-8a6d-220ee98ad120)
2025-03-10 22:03:30 +01:00
John Mumm
c58675fdac
Add an optional authentication policy to [index] configuration (#11896)
Adds a new optional key `auth-policy` to `[tool.uv.index]` that sets the
authentication policy for the index URL.

The default is `"auto"`, which attempts to authenticate when necessary.
`"always"` always attempts to authenticate and fails if the endpoint is
unauthenticated. `"never"` never attempts to authenticate.

These policy address two kinds of cases:
* Some indexes don’t fail on unauthenticated requests; instead they just
forward to the public PyPI. This can leave the user confused as to why
their package is missing. The "always" policy prevents this.
* "never" allows users to ensure their credentials couldn't be leaked to
an unexpected index, though it will only allow for successful requests
on an index that doesn't require credentials.

Closes #11600
2025-03-10 12:24:25 -05:00
konsti
aa629c4a54
Re-add 3 retries in uv publish (#12041)
In the publish client, we have to set the client retries to 0 as the
retry middleware is incompatible with upload bodies. This however also
sets `client.retry_policy()` to a zero-retry policy, so we need to
construct our own policy.

Fixes #12027

---------

Co-authored-by: Zanie Blue <contact@zanie.dev>
2025-03-10 12:38:08 +01:00
John Mumm
ba74b9ea93
Move config dir functions to public functions in uv_dirs (#12090)
This PR moves functions for finding user- and system-level config
directories to public functions in `uv_fs::config`. This will allow them
to be used in future work without duplicating code.
2025-03-10 12:05:05 +01:00
Charlie Marsh
9776dc5882
Remove some allocations from uv-auth (#12077)
## Summary

Use `SmallString`, and no need to allocate a `String` to fetch from the
URLs cache.
2025-03-09 14:28:33 -04:00
Charlie Marsh
bcc3e4f196
Add Rustdoc boxes around references (#12076) 2025-03-09 13:17:28 -04:00
John Mumm
b7968e7789
Conflicting groups should handle conflicting inclusions automatically (#12005)
This adds support for inferring dependency group conflict sets from the
directly defined conflicts in configuration. For example, if you declare
a conflict between groups `alpha` and `beta` and `dev` includes `beta`,
then we will infer a conflict between `dev` and `alpha`. We will also
handle a conflict between two groups if they transitively include groups
that conflict with each other. See #11232 for more details.

Closes #11232
2025-03-08 19:21:25 +01:00
JonCholas
b239c3ec4a
Avoid consider PATH updated when the export is commented in the shellrc (#12043)
## Summary

<!-- What's the purpose of the change? What does it do, and why? -->
The way the `tool update-shell` checks if the command to export the PATH
exists or not in the RC files is a blind search, and therefore if finds
the command inside comments.

example with .zshenv

This content
```
# uv
# export PATH="/Users/cholas/.local/bin:$PATH"
```

Generates the following msg
```
error: The executable directory /Users/cholas/.local/bin is not in PATH, but the Zsh configuration files are already up-to-date
```

With this change, that content won't be considered as configured and the
following will be added
```
# uv
export PATH="/Users/cholas/.local/bin:$PATH"
```

This will make the `update-shell` more reliable

## Test Plan

I tested with and without the change with commented export in zsh in
mac. Tested running `cargo run -- tool update-shell`

---------

Co-authored-by: Charlie Marsh <charlie.r.marsh@gmail.com>
2025-03-08 14:45:06 +00:00
Charlie Marsh
3c220c845e
Remove unused archive timestamp (#12064)
## Summary

Must've been leftover from a prior refactor.
2025-03-08 09:10:27 -05:00
konsti
b2a0ea3701
Integration test uv_build package (#12058)
I somehow missed running an actual integration test of the PEP 517 API
in CI and the python shim was using the old uv CLI interface still.

The tests include pip, uv and `python -m build`. They must be a in CI
job since we can't depend on the Python package in the Rust tests (we
only get the binary in `cargo test`, not the `uv_build` wheel).
2025-03-07 23:40:53 +01:00
Charlie Marsh
3dc9ac149d
Insert dependencies into fork state prior to fetching metadata (#12057)
## Summary

The order here is slightly off... As-is, we fetch the metadata for the
dependency, _then_ insert the URLs and indexes into the fork state -- so
the fetch doesn't take the explicit index or URL into account. This has
mostly been unobserved because we re-fetch anyway in the next request,
but if we do things in the right order (add to fork state, fetch
dependencies, insert dependencies), we can cut down on the fetches.

Closes https://github.com/astral-sh/uv/issues/12056.
2025-03-07 14:45:46 -05:00
Charlie Marsh
8fb616b61e
Use 'Upload' instead of 'Download' in publish reporter (#12029)
## Summary

Closes https://github.com/astral-sh/uv/issues/12026.
2025-03-07 10:48:34 -05:00
Christian Sachs
c57dd1a4a8
Allow overriding module name for uv build backend (#11884)
Thank you for uv, it has game-changer capabilities in the field of
Python package and environment maangement!

## Summary

This is a small PR adding the option `module-name`
(`tool.uv.build-backend.module-name`) to the uv build backend (
https://github.com/astral-sh/uv/issues/8779 ).

Currently, the uv build backend will assume that the module name matches
the (dash to underdash-transformed) package name. In some packaging
scenarios this is not the case, and currently there exists no
possibility to override it, which this PR addresses.

From the main issue ( https://github.com/astral-sh/uv/issues/8779 ) I
could not tell if there is any extensive roadmap or plans how to
implement more complex scenarios, hence this PR as a suggestion for a
small feature with a big impact for certain scenarios.

I am new to Rust, I hope the borrow/reference usage is correct.

## Test Plan

So far I tested this at an example, if desired I can look into extending
the tests.

Fixes #11428

---------

Co-authored-by: konstin <konstin@mailbox.org>
2025-03-07 15:20:00 +01:00
John Mumm
1ab1945dd9
Move DependencyGroups to uv-pypi-types so it can be imported there (#12037)
This PR is in support of #12005, where we need to import
`DependencyGroups` in the `uv-pypi-types` crate without a circular
dependency on `uv-workspace`.
2025-03-07 12:30:47 +01:00
Zanie Blue
f18e6ef6d4
Bump uv-build version to 0.6.5 (#12019) 2025-03-06 20:51:29 +00:00
Zanie Blue
bcbcd0a1e5
Bump version to 0.6.5 (#12018) 2025-03-06 14:39:23 -06:00
konsti
bf4c7afe8b
A minimal build backend for uv: uv_build (#11446)
uv itself is a large package with many dependencies and lots of
features. To build a package using the uv build backend, you shouldn't
have to download and install the entirety of uv. For platform where we
don't provide wheels, it should be possible and fast to compile the uv
build backend. To that end, we're introducing a python package that
contains a trimmed down version of uv that only contains the build
backend, with a minimal dependency tree in rust.

The `uv_build` package is publish from CI just like uv itself. It is
part of the workspace, but has much less dependencies for its own
binary. We're using cargo deny to enforce that the network stack is not
part of the dependencies. A new build profile ensure we're getting the
minimum possible binary size for a rust binary.

---------

Co-authored-by: Zanie Blue <contact@zanie.dev>
2025-03-06 13:27:20 -06:00
Charlie Marsh
d4a805544f
Allow users to set package = true on tool.uv.sources (#12014)
## Summary

In https://github.com/astral-sh/uv/issues/11998, a user is attempting to
vendor `pydantic-core`. But when they add `pydantic-core = { path =
"src/foo/vendor/pydantic-core" } `, we're installing it as a virtual
package, since `pydantic-core/pyproject.toml` contains `package =
false`.

This PR allows users to mark dependencies as "explicitly a package" or
"explicitly not a package" (i.e., virtual), as a workaround.

Closes https://github.com/astral-sh/uv/issues/11998.
2025-03-06 18:28:09 +00:00
Charlie Marsh
626fff1be7
Invalidate lockfile when empty dependency groups are added or removed (#12010)
## Summary

Since https://github.com/astral-sh/uv/pull/8598, we (correctly) include
empty groups in the lockfile, so we can validate them properly in the
satisfaction check.

Closes https://github.com/astral-sh/uv/issues/12007.
2025-03-06 12:44:20 -05:00
Charlie Marsh
40dce4e009
Allow overrides in all satisfies checks (#11995)
## Summary

This PR adds support for `SitePackages::satisfies` with unnamed
overrides and requirements.

The main challenge here was cases like: you have a `requirements.in`
with `git+https://github.com/pallets/flask` in it, and an
`overrides.txt` with `flask==2.0.0` in it. You _need_ to include
`flask==2.0.0`, but you can't know that without resolving the unnamed
URL requirement (since overrides only take effect when the package is
included, like constraints).

We now make the assumption that any unnamed overrides _are_ relevant,
for the purpose of the satisfies check. This is conservative, but this
whole check is an optimization anyway.
2025-03-05 21:54:19 -05:00
Charlie Marsh
b955211698
Allow overrides in satisfies check for uv tool run (#11994)
## Summary

For now, this routine requires that all requirements, constraints, and
overrides are named. I'll look at generalizing it later.
2025-03-05 21:43:49 -05:00
Charlie Marsh
c9e09de794
Warn user on uvx run command (#11992)
## Summary

If a user invokes `uvx run ...`, we hint them towards `uvx`. Otherwise,
this invokes the `run` package, which is unmaintained on PyPI.

If the user is _only_ using PyPI, we show an interactive prompt here;
otherwise, we just show a dedicated warning on error.

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

## Test Plan

Prompting to success:

![Screenshot 2025-03-05 at 5 00
47 PM](https://github.com/user-attachments/assets/d8180606-94e1-41df-b799-19b8ba57e662)

If you use `--from`, we avoid the prompt and hint:

![Screenshot 2025-03-05 at 5 03
26 PM](https://github.com/user-attachments/assets/59919390-01d3-4ddf-97bc-bb857ae9f8b0)

If you provide another index, we don't prompt, but we do warn on
failure:

![Screenshot 2025-03-05 at 5 03
43 PM](https://github.com/user-attachments/assets/0cc72c36-5744-48f1-aeff-4a214190d6fd)
2025-03-06 02:15:19 +00:00
samypr100
0fb5291239
Add support for Windows legacy scripts via uv run (#11888)
## Summary

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

This adds support for running .ps1, .cmd, .bat legacy scripts typically
provided by setuptools [legacy script
files](https://packaging.python.org/en/latest/guides/distributing-packages-using-setuptools/#scripts).

Note, .bat and .cmd scripts were somewhat supported previously by
[Command](https://doc.rust-lang.org/std/process/index.html#batch-file-special-handling)
when the extension was explicit but documentation says such behavior
should not be relied upon.

In addition, when no extension is provided and a legacy script exists,
it will try to infer the appropriate extension on Windows and use the
right runtime with preference for .ps1. Only powershell.exe and cmd.exe
are supported right now.

## Test Plan

Added tests. Tested with nuitka locally via uv run.

Note uvx support will be added in a follow up.
2025-03-05 14:39:48 -06:00
Charlie Marsh
28ff80b639
Respect markers on constraints when validating current environment (#11976)
## Summary

Small omission I noticed last night. This was overly strict (so, didn't
lead to any incorrect behavior; more that we did unnecessary work in
some cases).
2025-03-05 09:25:30 -05:00
Alex Lowe
7340ff72da
Add NO_BUILD and NO_BUILD_PACKAGE environment variables (#11968)
<!--
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? -->
Similar to https://github.com/astral-sh/uv/pull/11399

This adds `UV_NO_BUILD` and `UV_NO_BUILD_PACKAGE` environment variables
for non-pip commands.

## Test Plan

<!-- How was it tested? -->
Tested manually and with snapshot tests.


Fixes #11963

Signed-off-by: Alex Lowe <alex@lowe.dev>
2025-03-04 22:58:19 -06:00
Charlie Marsh
0f5b106dae
Fix empty constraints in satisfies check (#11971)
## Summary

Oversight from my constraints PR in `uv tool run`.
2025-03-05 03:11:20 +00:00
Charlie Marsh
5a3771967f
Remove Serialize implementations from some settings (#11969)
## Summary

We never serialize these (and we may need to transform them prior to
doing so).
2025-03-05 02:55:57 +00:00
Ed Morley
3c81e4121b
Fix include_system_side_packages typo (#11967)
`s/include_system_side_packages/include_system_site_packages/`
2025-03-05 00:49:35 +00:00
github-actions[bot]
f5acd60ac9
Fix PyPy Python version label (#11965)
Closes https://github.com/astral-sh/uv/issues/11863

Co-authored-by: zanieb <2586601+zanieb@users.noreply.github.com>
2025-03-05 00:36:21 +00:00
Charlie Marsh
3a53ec3c5a
Compare major-minor specifiers when filtering interpreters (#11952)
## Summary

If we're looking at (e.g.) `python3.12`, and we have a `requires-python:
">=3.12.7, <3.13"`, then checking if the range includes `3.12` will
return `false`. Instead, we need to look at the lower- and upper-bound
major-minors of the `requires-python`.

Closes https://github.com/astral-sh/uv/issues/11825.
2025-03-04 23:29:39 +00:00
konsti
a169dbeabe
Fix system site packages detection default (#11956)
See https://docs.python.org/3/library/site.html and
a549f43938/Lib/site.py (L614-L639):
The default is for system site packages is true, they have to be
disabled by setting the key to something that is not true.
2025-03-04 18:22:13 -05:00
Charlie Marsh
8f8c0e8918
Move LowerBound and UpperBound structs in uv-pep440 (#11950)
## Summary

I want to use these in `uv-python` and there's nothing specific to the
resolver or even to Python in these structs.
2025-03-04 12:35:16 -05:00
konsti
12f8d6f2c5
Remove prepended sys.path (#11954)
We prepend the interpreter discovery in a temporary path to `sys.path`,
which we have to strip to avoid the `sys.path` value containing a
then-deleted temp dir.
2025-03-04 16:00:26 +00:00
John Mumm
c072c9adca
Return error when running uvx with a .py script (#11623)
If we see `uvx script.py`, we exit early, giving a hint to use `uv run
script.py` if the script exists. If it does not exist, we suggest
running `uv run` with a normalized package name.

This PR includes a snapshot test for each of these scenarios.

An alternative approach would be to wait until we encounter an error,
and then add the hint. But if there happens to be a malicious package
called `script-py`, this would be run unintentionally (a point raised by
@zanieb).
 
Closes #10784

---------

Co-authored-by: Zanie Blue <contact@zanie.dev>
2025-03-04 14:29:36 +00:00
Lewis Gaul
3b83b48fd2
Fix error message suggesting --user instead of --username (#11947)
<!--
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
Fix error message suggesting `--user` instead of `--username`:
```
   > uv publish --publish-url ... ... --password $(cat ~/.token)
Publishing 1 file to ...
error: Attempted to publish with a password, but no username. Either provide a username with `--user` (`UV_PUBLISH_USERNAME`), or use `--token` (`UV_PUBLISH_TOKEN`) instead of a password.

   > uv publish --publish-url ... ... --user lewis --password $(cat ~/.token)
error: unexpected argument '--user' found

  tip: a similar argument exists: '--username'

Usage: uv publish <FILES|--index <INDEX>|--username <USERNAME>|--password <PASSWORD>|--token <TOKEN>|--trusted-publishing <TRUSTED_PUBLISHING>|--keyring-provider <KEYRING_PROVIDER>|--publish-url <PUBLISH_URL>|--check-url <CHECK_URL>|--skip-existing>

For more information, try '--help'.
```

## Test Plan
I have not tested manually, I'm hoping this isn't necessary and there
will be sufficient CI coverage.
2025-03-04 08:58:08 -05:00
Charlie Marsh
b460e51e19
Allow --constraints and --overrides in uvx (#10207)
## Summary

Closes https://github.com/astral-sh/uv/issues/9813.
2025-03-04 02:18:48 +00:00
Zanie Blue
f0ec9fd44a
Bump version to 0.6.4 (#11934) 2025-03-03 16:04:11 -06:00