Commit graph

3462 commits

Author SHA1 Message Date
konsti
dda91d443c
Publish: Password requires username (#8045) 2024-10-15 08:01:13 +00:00
Ahmed Ilyas
88cbc98eec
Support interactive input in uv publish (#8158) 2024-10-15 10:00:43 +02:00
Charlie Marsh
c683191408
Don't recommend --prerelease=allow for source dist builds (#8192)
## Summary

Closes https://github.com/astral-sh/uv/issues/3686.
2024-10-14 21:04:30 -04:00
Zanie Blue
b466202305
Do not use free-threaded interpreters without a free-threaded request (#8191)
As mentioned in https://github.com/astral-sh/uv/issues/8189

We only checked if an interpreter was free-threaded _when_ free-threaded
variants were requested. But we should not use free-threaded
interpreters unless explicitly requested.
2024-10-14 22:48:32 +00:00
samypr100
01c44af3c3
chore: unify all env vars used (#8151)
## Summary

This PR declares and documents all environment variables that are used
in one way or another in `uv`, either internally, or externally, or
transitively under a common struct.

I think over time as uv has grown there's been many environment
variables introduced. Its harder to know which ones exists, which ones
are missing, what they're used for, or where are they used across the
code. The docs only documents a handful of them, for others you'd have
to dive into the code and inspect across crates to know which crates
they're used on or where they're relevant.

This PR is a starting attempt to unify them, make it easier to discover
which ones we have, and maybe unlock future posibilities in automating
generating documentation for them.

I think we can split out into multiple structs later to better organize,
but given the high influx of PR's and possibly new environment variables
introduced/re-used, it would be hard to try to organize them all now
into their proper namespaced struct while this is all happening given
merge conflicts and/or keeping up to date.

I don't think this has any impact on performance as they all should
still be inlined, although it may affect local build times on changes to
the environment vars as more crates would likely need a rebuild. Lastly,
some of them are declared but not used in the code, for example those in
`build.rs`. I left them declared because I still think it's useful to at
least have a reference.

Did I miss any? Are their initial docs cohesive?

Note, `uv-static` is a terrible name for a new crate, thoughts? Others
considered `uv-vars`, `uv-consts`.

## Test Plan

Existing tests
2024-10-14 16:48:13 -05:00
Charlie Marsh
c5d9f55bc4
Bump version to v0.4.21 (#8188) 2024-10-14 20:44:43 +00:00
Zanie Blue
5f33915e03
Add support for managed installs of free-threaded Python (#8100)
Closes https://github.com/astral-sh/uv/issues/7193

```

❯ cargo run -q -- python uninstall 3.13t
Searching for Python versions matching: Python 3.13t
Uninstalled Python 3.13.0 in 231ms
 - cpython-3.13.0+freethreaded-macos-aarch64-none
❯ cargo run -q -- python install 3.13t
Searching for Python versions matching: Python 3.13t
Installed Python 3.13.0 in 3.54s
 + cpython-3.13.0+freethreaded-macos-aarch64-none
❯ cargo run -q -- python install 3.12t
Searching for Python versions matching: Python 3.12t
error: No download found for request: cpython-3.12t-macos-aarch64-none
❯ cargo run -q -- python install 3.13rc3t
Searching for Python versions matching: Python 3.13rc3t
Found existing installation for Python 3.13rc3t: cpython-3.13.0+freethreaded-macos-aarch64-none
❯ cargo run -q -- run -p 3.13t python -c "import sys; print(sys.base_prefix)"
/Users/zb/.local/share/uv/python/cpython-3.13.0+freethreaded-macos-aarch64-none
```
2024-10-14 15:18:52 -05:00
Zanie Blue
da7ffd3357
Fix error message consistency for broken virtual environments due to pyvenv.cfg (#8180) 2024-10-14 13:22:30 -05:00
Charlie Marsh
d12d569f24
Use shared resolver state between add and lock (#8146)
## Summary

If you `uv add` a Git dependency, we resolve it twice:

![Screenshot 2024-10-12 at 2 17
27 PM](https://github.com/user-attachments/assets/342e2523-af06-4783-b836-93b6bd9f34bc)

While we need to avoid sharing state between `lock` and `sync` (see the
large TODO that moved in this change), we should prioritize sharing
state between different resolver operations.
2024-10-12 14:58:07 +00:00
Charlie Marsh
346050bf99
Improve major-minor bounds on requires-python (#8145) 2024-10-12 15:48:03 +01:00
Charlie Marsh
b12d5b619b
Use shared index when fetching metadata in lock satisfaction routine (#8147) 2024-10-12 15:46:55 +01:00
bluss
e67d87301a
Implement uv tree --no-dev (#8109)
## Summary

Allow pruning dev-dependencies in uv tree.
This is not inherently in conflict with --invert, but this pruning is
not yet implemented there.
2024-10-12 13:10:56 +00:00
Amos Wenger
a3b11dacb8
Support for wildcard in UV_INSECURE_HOST (#8052)
Allow '*' as a value to match all hosts, and provide
`reqwest_blocking_get` for uv tests, so that they also respect
UV_INSECURE_HOST (since they respect `ALL_PROXY`).

This lets those tests pass with a forward proxy - we can think about
setting a root certificate later so that we don't need to disable
certificate verification at all.

---

I tested this locally by running:

```bash
GIT_SSL_NO_VERIFY=true ALL_PROXY=localhost:8080 UV_INSECURE_HOST="*" cargo nextest run sync_wheel_path_source_error
```

With my forward proxy showing:

```
2024-10-09T18:20:16.300188Z  INFO fopro: Proxied GET cc2fedbd88/cffi-1.17.1-cp310-cp310-macosx_11_0_arm64.whl (headers 480.024958ms + body 92.345666ms)
2024-10-09T18:20:16.913298Z  INFO fopro: Proxied GET https://pypi.org/simple/pycparser/ (headers 509.664834ms + body 269.291µs)
2024-10-09T18:20:17.383975Z  INFO fopro: Proxied GET 5f610ebe42/pycparser-2.21-py2.py3-none-any.whl.metadata (headers 443.184208ms + body 2.094792ms)
```
2024-10-12 13:55:26 +01:00
Max Friedrich
8605259f3d
Fix typos in --no-... option names in no-op warnings (#8143)
## Summary

When trying out standalone scripts I noticed a warning that said
`--no_readme` is a no-op when I provided `--no-readme`.

I searched for this "--\w+_" pattern in the codebase and found a similar
typo in warnings in other places, so I fixed them here.

## Test Plan


no plan, since these commands are mainly for interactive use I would
assume nobody parses out warnings about unnecessary options?
2024-10-12 13:53:19 +01:00
Charlie Marsh
b91bd29970
Avoid excluding valid wheels for exact requires-python bounds (#8140)
## Summary

Closes https://github.com/astral-sh/uv/issues/8136.
2024-10-12 04:17:36 +00:00
Amos Wenger
715f28fd39
chore: Move all integration tests to a single binary (#8093)
As per
https://matklad.github.io/2021/02/27/delete-cargo-integration-tests.html

Before that, there were 91 separate integration tests binary.

(As discussed on Discord — I've done the `uv` crate, there's still a few
more commits coming before this is mergeable, and I want to see how it
performs in CI and locally).
2024-10-11 16:41:35 +02:00
Jiahao Yuan
fce7a838e9
Fix stream did not contain valid UTF-8 (#8120)
## Summary

Related issues: #8009 #7549

Although `PYTHONIOENCODING=utf-8` forces python to use UTF-8 for
`stdout`/`stderr`, it can't prevent code like
`sys.stdout.buffer.write()` or `subprocess.call(["cl.exe", ...])` to
bypass the encoder. This PR uses lossy UTF-8 conversion to avoid
decoding error.

## Alternative

Using `bstr` crate might be better since it can preserve original
information. Or we should follow the Windows convention, unset
`PYTHONIOENCODING` and decode with system default encoding.

## Test Plan

Running locally with non-ASCII character in `UV_CACHE_DIR` works fine,
but I have no unit test plan. Testing locale problem is hard :(
2024-10-11 09:10:06 -04:00
Noam Teyssier
7bd0d97ce5
feat: add comma value-delimiter to with argument in tool run args to allow for multiple arguments in with flag (#7909)
This is to address my own issue #7908 

## Summary

This change makes use of the `clap` value_delimiter parser to populate
the `with` `Vec<String>` which currently can either only be empty or
with 1 value for each `--with` flag.

This makes use of the current code structure but allows for multiple
arguments with a single `--with` flag.

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

## Test Plan

Can be tested with the following CLI:

```bash
target/debug/uv tool run --with numpy,polars,matplotlib ipython -c "import numpy;import polars;import matplotlib;"
```

And former behavior of multiple `--with` flags are kept

```bash
target/debug/uv tool run --with numpy --with polars --with matplotlib ipython -c "import numpy;import polars;import matplotlib;"
```

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

---------

Co-authored-by: Charlie Marsh <charlie.r.marsh@gmail.com>
2024-10-11 11:19:57 +02:00
Charlie Marsh
2506c1c274
Capitalize error messages from lockfile (#8115)
## Summary

This is more consistent with how we format errors everywhere else.
2024-10-11 01:50:00 +02:00
Charlie Marsh
538de64533
Use a single error type for uv-requirements (#8117) 2024-10-10 23:44:25 +00:00
Charlie Marsh
455b64cd77
Encapsulate tempfile within uv run (#8114)
## Summary

Some follow-up refactors to confine all the remote URL downloading and
parsing to within the `uv run` target abstractions.
2024-10-10 23:41:38 +00:00
Charlie Marsh
d864e1dbe5
Use separate types for stdin vs. file-based PEP 723 scripts (#8113) 2024-10-10 22:49:14 +00:00
Trevor Manz
e3775635d4
Support PEP 723 metadata with uv run - (#8111)
## Summary

Fixes #8097. One challenge is that the `Pep723Script` is used for both
reading
and writing the metadata, so I wasn't sure about how to handle
`script.write`
when stdin (currently just ignoring it, but maybe we should raise an
error?).

## Test Plan

Added a test case copying the `test_stdin` with PEP 723 metadata.
2024-10-11 00:35:07 +02:00
Charlie Marsh
0627b4a8a4
Use --with-requirements in uvx error hint (#8112)
## Summary

Closes https://github.com/astral-sh/uv/issues/6845.
2024-10-11 00:09:33 +02:00
Trevor Manz
585456a607
feat: Support remote scripts with uv run (#6375)
<!--
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?
-->

First off, congratulations on the 0.3 release! The PEP 723 standalone
scripts support is awesome, and I can already imagine a long tail of
little scripts of my own that would benefit from this functionality.

## Background

I really like the Deno CLI's support for running and installing remote
scripts.

```
deno run <url>
```

```
deno install --name foo <url>
```

I can see parallels with `uv run` and `uvx`. After mentioning this on
Discord, @zanieb suggested I could take a stab at a PR to implement
similar functionality for uv.

## Summary

This PR attempts to add support for executing remote standalone scripts
directly with `uv run`. While this is already possible by downloading
the script (i.e., via curl/wget) and then using uv run, having direct
support would be convenient.

The proposed functionality is:

```sh
uv run <url>
```

Another addition/alternative could be to support running scripts via
stdin:

```sh
curl -sL <url> | uv run -
```

But that is not implemented in this PR.

## Test Plan

I noticed that GitHub and `files.pythonhosted.org` URLs are used in some
of the tests. I've created a personal [GitHub
Gist](https://gist.github.com/manzt/cb24f3066c32983672025b04b9f98d1f)
with the example from PEP 723 for now to test this functionality.

~However, I couldn't figure out how to get the `with_snapshot` config
filter to filter out the tempfile path, so the test is currently
failing. Any assistance with this would be appreciated.~

## Notes

I'm not totally pleased with the implementation of this PR. I think it
would be better to handle the case earlier (and probably reuse the
cache), and avoid mutation, but since run command requires a local path
this was the simplest implementation I could come up with.

I know that performance is paramount with uv so I totally understand if
this requires a different approach or something more explicit to avoid
"inferring" the path. I'm just taking this as an opportunity to learn a
little more Rust and acquaint myself with the code base. cheers!

---------

Co-authored-by: Andrew Gallant <jamslam@gmail.com>
2024-10-10 14:10:17 -04:00
Zanie Blue
7d0e56607d
Use git config --get for author information for improved backwards compatibility (#8101)
See https://github.com/astral-sh/uv/pull/7756#issuecomment-2405577849
2024-10-10 12:16:16 -05:00
Ahmed Ilyas
97af56a603
Support uv export --no-header (#8096)
## Summary

Resolves https://github.com/astral-sh/uv/issues/8063

## Test Plan

`cargo test`
2024-10-10 17:17:44 +02:00
Charlie Marsh
7bac708b97
Treat resolver failures as fatal in lockfile validation (#8083)
## Summary

In the routine we use to verify whether the lockfile is up-to-date, we
sometimes have to resolve package metadata. If that resolution step
fails, the resolver is left in a bad state, as various tasks are marked
as pending despite the error. Treating that as a recoverable failure
thus leads to a deadlock.

This PR modifies the errors to be treated as fatal.

I think a more holistic fix here would be to add some kind of guard to
ensure that any tasks that fail are no longer marked as pending (or
enforce this in the type system).

Closes https://github.com/astral-sh/uv/issues/8074.
2024-10-10 14:01:20 +00:00
Charlie Marsh
dc3f628de1
Respect dynamic extras in uv lock and uv sync (#8091)
## Summary

We can't rely on reading these from the `pyproject.toml`; instead, we
resolve the project metadata (which will typically just require reading
the `pyproject.toml`, but will go through our standard metadata paths).

Closes https://github.com/astral-sh/uv/issues/8071.
2024-10-10 16:00:31 +02:00
Andrew Gallant
7b80b18166 uv-pep508: fix disjointness bug
This commit fixes a bug where disjointness checking didn't always
satisfy commutativity. And it *should*. The `is_disjoint_commutative`
test added here demonstrates a regression test. Before this commit,
its second assertion failed.

That is, given `m1 = extra == "A" and extra != "B"` and
`m2 = extra == "A"`, we were saying that m1 was disjoint with
m2 (wrong) but that m2 was not disjoint with m1 (right).

It turned out that this was a "simple" matter of not using the
correct parent node when calling negation. Likely just a
transcription snafu.

This bug does not seem restricted in scope to extras, which is
how I found it, so it's not clear why we haven't noticed it until
now. I noticed it because I was formulating markers in a similar
format for resolver forking based on conflicting extras, and this
resulted in incorrectly filtering out dependencies due to `is_disjoint`
returning a false positive.
2024-10-10 09:46:42 -04:00
Andrew Gallant
3df883c95d uv-pep508: add Debug impl for MarkerTree's actual internal representation
I found myself using this more verbose representation to double
check that there wasn't any other "hidden" state occurring in
markers, and that the graph debug display wasn't hiding anything
that I was missing.
2024-10-10 09:46:42 -04:00
Charlie Marsh
d652b0c024
Downgrade installer verbose logging to trace (#8078)
## Summary

Now that `uv-install-wheel` output shows up in `--verbose`, lets leave
`debug!` to logs that users might want to see. Logging _every_ file we
install seems excessive.
2024-10-10 12:28:18 +00:00
Pavel Dikov
bf15ca93cf
fix(venv.relocatable): script entrypoints should work if symlinked to (#8079)
Fixes: #8058

## Test Plan

Integration test (but only for Unix, because symlinks on Windows require
admin privs. Plus, they are not really all that idiomatic on Windows)
2024-10-10 14:00:56 +02:00
Charlie Marsh
8f62fc920e
Avoid verbose warnings for non-existent cache keys (#8077)
## Summary

These show up on ~every `--verbose` run.
2024-10-10 09:35:03 +00:00
Zanie Blue
82708944a3
Fix uv python pin 3.13t failure when parsing version for project requires check (#8056)
Closes https://github.com/astral-sh/uv/issues/7964

We can probably do some restructuring to avoid unwrapping here in the
future, but this just fixes the bug quick.
2024-10-10 00:17:20 +00:00
Charlie Marsh
46a0ed7fa2
Use comma-separated values for UV_FIND_LINKS (#8061)
## Summary

These values can include spaces when passed on the command-line... Clap
doesn't give us a way to provide a value separator for _only_ an
environment variable (as is pip's behavior), so I think we're stuck
using comma-separated for here right now.

See, e.g., https://github.com/clap-rs/clap/discussions/3796.

Closes #8057.
2024-10-09 23:05:51 +00:00
Charlie Marsh
1c5309080b
Add gap-preserving range-to-PEP 440 routine (#8060)
## Summary

These are changes I apparently forgot to push as per
https://github.com/astral-sh/uv/pull/7897/files#r1794312988.
2024-10-09 22:48:53 +00:00
Charlie Marsh
77ea9d9626
Fix handling of != intersections in requires-python (#7897)
## Summary

The issue here is that, if you user has a `requires-python` like `>=
3.7, != 3.8.5`, this gets expanded to the following bounds:

- `[3.7, 3.8.5)`
- `(3.8.5, ...`

We then convert this to the specific `>= 3.7, < 3.8.5, > 3.8.5`. But the
commas in that expression are conjunctions... So it's impossible to
satisfy? No version is both `< 3.8.5` and `> 3.8.5`.

Instead, we now preserve the input `requires-python` and just
concatenate the terms, only using PubGrub to compute the _bounds_.

Closes https://github.com/astral-sh/uv/issues/7862.
2024-10-10 00:24:43 +02:00
Brandon W Maister
0ec2d4e434
fix: Improve compatibility with VSCode PS1 prompt (#8006) 2024-10-09 17:33:21 +02:00
Ahmed Ilyas
1764a95d39
Support pip install --exact (#8044)
## Summary

Resolves #8041 

## Test Plan

`cargo test`
2024-10-09 15:31:28 +02:00
Jo
44d6478f88
Remove the newly created tool environment if sync failed (#8038)
## Summary

Resolves #8011

## Test Plan

```console
$ cargo run -- tool install pyenv
$ cargo run -- tool list
```
2024-10-09 13:01:53 +00:00
Zanie Blue
5bc726a1e7
Avoid deleting a project environment directory if we cannot tell if a pyvenv.cfg file exists (#8012)
I was exploring a fix to an [apparent
bug](3124893728)
but this was actually just a CI change
https://github.com/astral-sh/uv/pull/8013

Regardless, I think this code is safer?
2024-10-08 17:15:47 -05:00
Jacob Coffee
e8b8d236a1
docs: add alias context to uv tool run --help command (#7695)
<!--
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? -->
- Adds detail to the `uv tool run --help` CLI that lets users know about
the shorthand, `uvx`

## Test Plan

<!-- How was it tested? -->
Building and running CLI
```
…📝✓] via 🐋 orbstack via 🎁 v0.4.16 via  pyenv via ⚙️ v1.81.0on ☁️  (us-east-2) took 3s 
➜ ./target/debug/uv tool run --help
Run a command provided by a Python package. Also available via the alias `uvx`.

Usage: uv tool run [OPTIONS] [COMMAND]

...

You can also use `uvx` as an alias for `uv tool run`. 
Use `uv help tool run` for more details.
```

---------

Co-authored-by: Zanie Blue <contact@zanie.dev>
2024-10-08 21:43:50 +00:00
trag1c
37273cb4bc
Add prerelease compatibility check (#8020)
## Summary

Closes #7977. Makes `PythonDownloadRequest` account for the prerelease
part if allowed. Also stores the prerelease in `PythonInstallationKey`
directly as a `Prerelease` rather than a string.

## Test Plan

Correctly picks the relevant prerelease (rather than picking the most
recent one):
```
λ cargo run python install 3.13.0rc2
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.17s
     Running `target/debug/uv python install 3.13.0rc2`
Searching for Python versions matching: Python 3.13rc2
cpython-3.13.0rc2-macos-aarch64-none ------------------------------ 457.81 KiB/14.73 MiB                                                                                                                    ^C

λ cargo run python install 3.13.0rc3                 
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.17s
     Running `target/debug/uv python install 3.13.0rc3`
Searching for Python versions matching: Python 3.13rc3
Found existing installation for Python 3.13rc3: cpython-3.13.0rc3-macos-aarch64-none
```
2024-10-08 16:20:58 -05:00
Zanie Blue
0e1b25a536
Bump version to 0.4.20 (#8016) 2024-10-08 19:55:21 +00:00
Kemal Akkoyun
1a39ffe391
uv run: List available scripts when a script is not specified (#7687)
Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com>
## Summary

This PR adds the ability to list available scripts in the environment
when `uv run` is invoked without any arguments.
It somewhat mimics the behavior of `rye run` command
(See https://rye.astral.sh/guide/commands/run).

This is an attempt to fix #4024.

## Test Plan

I added test cases. The CI pipeline should pass.

### Manuel Tests

```shell
❯ uv run
Provide a command or script to invoke with `uv run <command>` or `uv run script.py`.

The following scripts are available:

normalizer
python
python3
python3.12

See `uv run --help` for more information.
```

---------

Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com>
Co-authored-by: Zanie Blue <contact@zanie.dev>
2024-10-08 19:34:50 +00:00
konsti
282fab5f70
Hint at wrong endpoint in publish (#7872)
Improve hints when using the simple index URL instead of the upload URL
in `uv publish`. This is the most common confusion when publishing, so
we give it some extra care and put it more centrally in the CLI help.

Fixes #7860

---------

Co-authored-by: Zanie Blue <contact@zanie.dev>
2024-10-08 19:16:02 +00:00
Jo
15e5e3f6af
Fill in authors filed during uv init (#7756)
## Summary

Fill in the `authors` field of `pyproject.toml` by fetching author info
from Git.

Resolves #7718
2024-10-08 14:06:37 -05:00
Zanie Blue
f6fd849f2c
Add managed downloads for CPython 3.13.0 final (#8010) 2024-10-08 12:53:09 -05:00
konsti
b5dbc32aee
Check consistency between prepare and build step (#7986) 2024-10-08 16:38:22 +00:00