Commit graph

3091 commits

Author SHA1 Message Date
Andrew Gallant
c14e30ad09 pep508: fix doc test
Indented blocks in Markdown are treated as code blocks, and rustdoc
treats all unadorned code blocks as Rust doctests. Since this wasn't
intended as a doctest and isn't valid Rust, it makes `cargo test --doc`
fail. We fix this by using an explicit code block labeled as `text`.
2024-08-19 16:29:20 -07:00
Zanie Blue
5b74754140
Add output when uv add and uv remove update scripts (#6231)
Closes https://github.com/astral-sh/uv/issues/6214
2024-08-19 21:29:33 +00:00
Zanie Blue
c703917d99
Document the cache directory (#6229) 2024-08-19 15:51:45 -05:00
Zanie Blue
cc8fbedd37
Document the tools directory (#6228)
As in https://github.com/astral-sh/uv/pull/6227
2024-08-19 19:46:19 +00:00
Zanie Blue
b7c9ad981d
Document the Python installation directory (#6227) 2024-08-19 19:42:36 +00:00
Zanie Blue
5c2781c42a
Fix messages for unavailable packages when range is plural (#6221)
Not in love with the implementation, but it seems like the easiest path
forward for now.
2024-08-19 19:07:07 +00:00
Zanie Blue
6500f7110a
Change "any of" to "all of" in error messages (#6222) 2024-08-19 18:43:07 +00:00
Zanie Blue
f6f2c5b79e
Collapse redundant dependency clauses enumerating available versions (#6160)
In https://github.com/astral-sh/uv/issues/5046, we show the tautological
proof:

```
  ╰─▶ Because colabfold[alphafold]==1.5.5 depends on jax>=0.4.20 and only the following versions of jax are available:
          jax<=0.4.20
          jax==0.4.21
          jax==0.4.22
          jax==0.4.23
          jax==0.4.24
          jax==0.4.25
          jax==0.4.26
          jax==0.4.27
          jax==0.4.28
          jax==0.4.29
          jax==0.4.30
          jax==0.4.31
      we can conclude that colabfold[alphafold]==1.5.5 depends on jax>=0.4.20.
      And because jax>=0.4.20 depends on numpy>=1.26.0, we can conclude that colabfold[alphafold]==1.5.5 depends on numpy>=1.26.0.
      (1)
```

This is a part of the error tree because the statement
`colabfold[alphafold]==1.5.5 depends on jax>=0.4.20` is actually a
simplification of `colabfold[alphafold]==1.5.5 depends on
jax>=0.4.20,<0.5.0` and the no versions clause is a proof of that
simplification.

Without simplification, the clause looks like:

```
  ╰─▶ Because colabfold[alphafold]==1.5.5 depends on jax>=0.4.20,<0.5.0 and only the following versions of jax are available:
          jax<=0.4.20
          jax==0.4.21
          jax==0.4.22
          jax==0.4.23
          jax==0.4.24
          jax==0.4.25
          jax==0.4.26
          jax==0.4.27
          jax==0.4.28
          jax==0.4.29
          jax==0.4.30
          jax==0.4.31
      we can conclude that colabfold[alphafold]==1.5.5 depends on one of:
          jax==0.4.20
          jax==0.4.21
          jax==0.4.22
          jax==0.4.23
          jax==0.4.24
          jax==0.4.25
          jax==0.4.26
          jax==0.4.27
          jax==0.4.28
          jax==0.4.29
          jax==0.4.30
          jax==0.4.31
      And because jax>=0.4.20 depends on numpy>=1.26.0, we can conclude that colabfold[alphafold]==1.5.5 depends on numpy>=1.26.0.
```

I don't think we have a great way to avoid performing the simplification
of the range conditionally and it makes the error simpler to just jump
straight to `colabfold[alphafold]==1.5.5 depends on jax>=0.4.20`.

The derivation for this clause looks like:

```
          jax==0.4.20 | ==0.4.21 | ==0.4.22 | ==0.4.23 | ==0.4.24 | ==0.4.25 | ==0.4.26 | ==0.4.27 | ==0.4.28 | ==0.4.29 | ==0.4.30 | ==0.4.31 depends on numpy>=1.26.0
            no versions of jax>0.4.20, <0.4.21 | >0.4.21, <0.4.22 | >0.4.22, <0.4.23 | >0.4.23, <0.4.24 | >0.4.24, <0.4.25 | >0.4.25, <0.4.26 | >0.4.26, <0.4.27 | >0.4.27, <0.4.28 | >0.4.28, <0.4.29 | >0.4.29, <0.4.30 | >0.4.30, <0.4.31 | >0.4.31, <0.5.0
            colabfold[alphafold]==1.5.5 depends on jax>=0.4.20, <0.5.0
```

So it looks like we can take trees of this form and drop the "no
versions" clause _if_ the ranges are compatible[*]. See [this
comment](https://github.com/astral-sh/uv/pull/6160#discussion_r1720280922)
for a simpler explanation.

With this pull request, the clause simplifies to

```
╰─▶ Because colabfold[alphafold]==1.5.5 depends on jax>=0.4.20 and jax>=0.4.20 depends on numpy>=1.26.0,
     we can conclude that colabfold[alphafold]==1.5.5 depends on numpy>=1.26.0. (1)
```

Unfortunately, this doesn't change any snapshots in our test suite so
I'm uncertain if the strategy generalizes. In some incorrect iterations
of this logic, the snapshots did reveal my mistakes.

[*] "if the ranges are compatible" includes a bit of hand-waving. I'm
not 100% sure if I've chosen the correct range heuristic here.
2024-08-19 18:02:02 +00:00
Zanie Blue
df2ebf74d0
Document yanked packages caveat during sync (#6219)
Closes https://github.com/astral-sh/uv/issues/5928
2024-08-19 12:52:52 -05:00
Charlie Marsh
a4aef29164
Warn when --upgrade is passed to tool run (#6140)
## Summary

Passing `--upgrade` to `tool run` is confusing, because it doesn't
upgrade the installed tool. It just causes us to use an isolated tool
environment, which seems wrong.
2024-08-19 17:08:39 +00:00
Charlie Marsh
c80a831438
Add support for package@latest in tool run (#6138)
## Summary

`@latest` will ignore any installed tools and force a cache refresh.

Closes https://github.com/astral-sh/uv/issues/5807.
2024-08-19 16:58:36 +00:00
Zanie Blue
c817f41951
Document the effect of ordering on package priority (#6211)
Closes https://github.com/astral-sh/uv/issues/6209
Closes https://github.com/astral-sh/uv/issues/5474
2024-08-19 11:53:28 -05:00
Zanie Blue
6bc8639ce8
Allow customizing the tool install directory with UV_TOOL_BIN_DIR (#6207)
Requested in #6067
2024-08-19 15:02:10 +00:00
Zanie Blue
c32e01ec3d
Add support for python_version in ... markers (#6172)
Closes #3683 

Note our semantics do not exactly match the specification so we can
perform algebra on the markers. See the caveats in the documentation
(and in the discussion below).
2024-08-19 14:10:20 +00:00
Andrew Gallant
44b7b9a3c1 uv/tests: tweak marker emitting tests to use Python 3.12.1
The test output seems to depend on using Python 3.12.1 specifically.
While I'm not sure how it happens, it seems like these can get out of
sync between CI and local testing. In this case, I had a problem where
the marker expressions emitted locally were tied to Python 3.12.4, but
the tests in CI were tied to Python 3.12.1. Changing the test to require
3.12.1 specifically fixes this.
2024-08-19 06:02:29 -07:00
Andrew Gallant
5b6080f2ad uv/tests: add new initial set of 'workflow' tests
This initial set is meant to be a basic starting point where we
can test the interaction between 'uv' commands more systematically.
And specifically, with a focus on how the lock file changes.
2024-08-19 05:33:30 -07:00
Andrew Gallant
2b68a3d17a uv/tests: add and rejigger some helpers in our common test library
This adds some variations on 'uv add' and 'uv remove' specifically
for testing changes to the lock file (and not anything else).

We also rejigger 'run_and_format' so that we can use it in other
contexts, particularly for error reporting.

And we add a 'diff_lock' helper for returning the changes made to
a lock file after running a command.
2024-08-19 05:33:30 -07:00
Andrew Gallant
c7218e19ac cargo: add 'similar' dev dependency
We were already using this via 'insta'. We bring it in so that
we can explicitly snapshot diffs.
2024-08-19 05:33:30 -07:00
Andrew Gallant
a8011ffd50 uv/tests: use PathCopy::copy_from from assert_fs
Turns out assert_fs has a bunch of little goodies in it and we already
depend on it.
2024-08-19 05:33:30 -07:00
Andrew Gallant
5da561a917 uv/tests: remove deterministic macro
This was only being used in the ecosystem tests. Since we now don't do a
resolve when `uv lock` is run and when the lock file satisfies the
`pyproject.toml`, deterministic checking was removed since it's avoided
by construction. It was removed everywhere else, so we remove it here as
well.
2024-08-19 05:33:30 -07:00
Andrew Gallant
58fac3d577 uv/tests: remove non-deterministic checking in ecosystem tests
We basically avoid this by construction now, so there are no failures.
2024-08-19 05:33:30 -07:00
Andrew Gallant
b268f5eb8a uv/tests: move ecosystem project copying to TestContext
So that we can easily reuse ecosystem projects in other tests.
2024-08-19 05:33:30 -07:00
Andrew Gallant
74066ec29b cargo: remove unused 'derivative' dependency
This seems to be failing the `cargo shear` check on `main`. It looks
like this was caused by #6200.
2024-08-19 05:19:23 -07:00
konsti
4469f57516
Upstream konstin/pep508_rs#17 (#6200)
Upstream https://github.com/konstin/pep508_rs/pull/17

> This removes the `derivative` dependency which [seems to be
unmaintained](https://github.com/mcarton/rust-derivative/issues/117) and
depends on old versions of some crates, especially `syn`.
>
> I could also replace it with another crate like `educe` or
`derive-where` but the implementation seems simple enough.
2024-08-19 11:31:14 +00:00
Ed Morley
9e4c6a76d4
Update URL to distutils configuration files docs (#6004)
## Summary

The existing URL 404s:

https://docs.python.org/3/install/index.html#distutils-configuration-files

...since the `/3/` route now resolves to Python 3.12, where `distutils`
has been removed:
https://docs.python.org/3.12/whatsnew/3.12.html#distutils

The Python 3.11 docs are the most recent where the page still exists:

https://docs.python.org/3.11/install/index.html#distutils-configuration-files

## Test Plan

N/A
2024-08-19 11:48:03 +02:00
renovate[bot]
8a48f755d1
Update Rust crate which to v6.0.3 (#6193) 2024-08-19 02:31:05 +00:00
Zanie Blue
baf17bee86
Avoid panicking when the resolver thread encounters a closed channel (#6182)
Closes https://github.com/astral-sh/uv/issues/6167

We've been seeing intermittent failures in CI, which we thought were
unexpected HTTP 401s but it actually looks like a panic when handling an
expected HTTP error. I believe the problem is that an early client error
can cause the channel to close and we crash when we unwrap the `send`.
2024-08-18 21:04:05 +00:00
Branch Vincent
615dda0e94
Tolerate missing [project] table in uv venv (#6178)
## Summary

Fixes #6177

This ensures a `pyproject.toml` file without a `[project]` table is not
a fatal error for `uv venv`, which is just trying to discover/respect
the project's `python-requires` (#5592).

Similarly, any caught `WorkspaceError` is now also non-fatal and instead
prints a warning message (feeback welcome here, felt less surprising
than e.g. a malformed `pyproject.toml` breaking `uv venv`).

## Test Plan

I added two test cases: `cargo test -p uv --test venv`

Also, existing venv tests were failing for me since I use fish and the
printed activation script was `source .venv/bin/activate.fish` (to
repro, just run the tests with `SHELL=fish`). So added an insta filter
to normalize that.
2024-08-18 14:50:46 -04:00
Severen Redwood
f8bda467fa
Lift requirement that .egg-info filenames must include version (#6179)
## Summary

PR #4533 introduced (almost) spec compliant parsing of `.egg-info`
filenames, but added the overly strict requirement that the distribution
version must be present. This causes various `uv pip` operations to fail
in environments where there are `.egg-info` files without a version
component, so loosen this check by making the version component optional
and reading the version from the egg metadata when it is not present.

As an example of the issue, running `uv pip list` on my system currently
results in
```
error: Failed to read metadata from: `/usr/lib/python3.12/site-packages/PySide6.egg-info`
  Caused by: The `.egg-info` filename "PySide6.egg-info" is missing a version
```
whereas regular `pip list` succeeds:
```
$ pip list | rg -S pyside
PySide6                   6.7.2
```

## Test Plan

This has been tested by altering the `.egg-info` filename tests as
needed and ensuring the full test suite passes locally.
2024-08-18 13:04:40 -04:00
Di-Is
53159b5d98
Show generate-shell-completion command in uv help (#6180)
Resolve #6151

## Test Plan

Execution result of `cargo run -- help`

```bash
An extremely fast Python package manager.

Usage: uv [OPTIONS] <COMMAND>

Commands:
  run                        Run a command or script (experimental)
  init                       Create a new project (experimental)
  add                        Add dependencies to the project (experimental)
  remove                     Remove dependencies from the project (experimental)
  sync                       Update the project's environment (experimental)
  lock                       Update the project's lockfile (experimental)
  tree                       Display the project's dependency tree (experimental)
  tool                       Run and install commands provided by Python packages (experimental)
  python                     Manage Python versions and installations (experimental)
  pip                        Manage Python packages with a pip-compatible interface
  venv                       Create a virtual environment
  cache                      Manage uv's cache
  version                    Display uv's version
  generate-shell-completion  Generate shell completion
  help                       Display documentation for a command
...
```

Execution result of `cargo run -- -h` and `cargo run -- --help` 

```bash
An extremely fast Python package manager.

Usage: uv [OPTIONS] <COMMAND>

Commands:
  run      Run a command or script (experimental)
  init     Create a new project (experimental)
  add      Add dependencies to the project (experimental)
  remove   Remove dependencies from the project (experimental)
  sync     Update the project's environment (experimental)
  lock     Update the project's lockfile (experimental)
  tree     Display the project's dependency tree (experimental)
  tool     Run and install commands provided by Python packages (experimental)
  python   Manage Python versions and installations (experimental)
  pip      Manage Python packages with a pip-compatible interface
  venv     Create a virtual environment
  cache    Manage uv's cache
  version  Display uv's version
  help     Display documentation for a command
...
```
2024-08-18 08:13:29 -05:00
Charlie Marsh
5ac0b98e00
Respect release-only semantics of python_full_version when constructing markers (#6171)
## Summary

In the resolver, we use release-only semantics to normalize
`python_full_version`. So, if we see `python_full_version < '3.13'`, we
treat that as `(Unbounded, Exclude(3.13))`. `3.13b0` evaluates as `true`
to that range, so we were accepting pre-releases for these markers.

Instead, we need to exclude pre-release segments when performing these
evaluations.

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

## Test Plan

Hard to write a test for this because you need a pre-release Python
locally... so:

`echo "sqlalchemy==2.0.32" | cargo run pip compile - --python 3.13 -n`
2024-08-17 19:29:57 +00:00
Di-Is
ad8e3a2c32
Hide global option in uv generate-shell-completion (#6170)
Resolve #6152 

## Summary

## Test Plan

Execution result of `cargo run generate-shell-completion --help`

```bash
Generate shell completion

Usage: uv generate-shell-completion <SHELL>

Arguments:
  <SHELL>  The shell to generate the completion script for [possible values: bash, elvish, fish, nushell, powershell, zsh]
```

Execution result of `cargo run help generate-shell-completion`

```bash
Generate shell completion

Usage: uv generate-shell-completion <SHELL>

Arguments:
  <SHELL>
          The shell to generate the completion script for
          
          [possible values: bash, elvish, fish, nushell, powershell, zsh]
```
2024-08-17 13:34:34 -05:00
Zanie Blue
0091adfa5b
Document uv add and uv remove behavior with markers (#6163) 2024-08-16 23:16:42 +00:00
Ahmed Ilyas
268c6de7fd
Support uv add -r requirements.txt (#6005)
## Summary

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

- First commit avoids overwriting dependencies with different markers.
- Second commit supports adding from requirements files.

## Test Plan

`cargo test`
2024-08-16 21:57:45 +00:00
Ibraheem Ahmed
6cfb27c5e1
Clarify docs for python_version to python_full_version transformation (#6135)
Follow up to https://github.com/astral-sh/uv/pull/6126.
2024-08-16 17:34:13 -04:00
Zanie Blue
e1a8beb64b
Simplify version ranges reported for unavailable packages (#6155)
Now that these incompatibilities are collected into a single range
(https://github.com/astral-sh/uv/pull/6154), we can simplify the range
using the known available versions to reduce verbosity.
2024-08-16 20:56:45 +00:00
Ahmed Ilyas
3a46e48f93
Avoid overwriting dependencies with different markers in uv add (#6010)
## Summary

Splitting out https://github.com/astral-sh/uv/pull/6005

## Test Plan

`cargo test`

---------

Co-authored-by: Zanie Blue <contact@zanie.dev>
2024-08-16 20:46:47 +00:00
Zanie Blue
92ff120983
Improve resolver error messages when --offline is used (#6156) 2024-08-16 20:28:35 +00:00
Zanie Blue
ea636bbe61
Simplify available package version ranges when the name includes markers or extras (#6162)
There were different `PubGrubPackage` types so they never matched the
available versions set! Luckily, the available versions are agnostic to
the markers and optional dependencies so we can just broaden to using
`PackageName` as a lookup key.

Addresses yet another complaint in
https://github.com/astral-sh/uv/issues/5046
2024-08-16 15:21:49 -05:00
Zanie Blue
05cceee523
Collapse unavailable packages in resolver errors (#6154)
Uses my expanding tree reduction knowledge from #6092 to improve the
long-standing issue of verbose messages for unavailable packages.

Implements https://github.com/pubgrub-rs/pubgrub/issues/232, but
post-resolution instead of during resolution.

Partially addresses https://github.com/astral-sh/uv/issues/5046
Closes https://github.com/astral-sh/uv/issues/2519
2024-08-16 15:19:59 -05:00
Charlie Marsh
d643e92d66
Avoid using workspace lock_path as relative root (#6157)
## Summary

I've also made it such that these won't panic, and we gracefully
continue if we fail to validate a lockfile.

Closes https://github.com/astral-sh/uv/issues/6142.
2024-08-16 17:24:27 +00:00
Charlie Marsh
91fba4e1e6
Use FxHash in uv-auth (#6149) 2024-08-16 13:14:51 -04:00
Ibraheem Ahmed
6766124fd6
Improve performance of MarkerTree::is_disjoint (#6148)
## Summary

Resolves https://github.com/astral-sh/uv/issues/6137.
2024-08-16 13:03:26 -04:00
Zanie Blue
b93b0f2bcd
Show uv generate-shell-completion in CLI documentation reference (#6146)
We need to follow this with:

1) Hide a bunch of global arguments for this command
2) Add an about section for the command
2024-08-16 11:40:05 -05:00
Zanie Blue
d7abe827d6
Allow displaying the derivation tree (#6124)
I need this for debugging error messages.

I used an environment variable instead of a trace log so you can do
`UV_INTERNAL__SHOW_DERIVATION_TREE=1` and run a test to see the tree in
the test snapshot without further changes.

e.g.

```rust
    // Resolving should fail.
    uv_snapshot!(context.filters(), context.lock().arg("--preview").current_dir(&workspace), @r###"
    success: false
    exit_code: 1
    ----- stdout -----
    UV_INTERNAL__SHOW_DERIVATION_TREE
      root==0a0.dev0 depends on foo*
        root==0a0.dev0 depends on bar[some-extra]*
          foo==0.1.0 depends on anyio==4.1.0
            bar[some-extra]==0.1.0 depends on anyio==4.2.0
            no versions of bar[some-extra]<0.1.0 | >0.1.0

    ----- stderr -----
    Using Python 3.12.[X] interpreter at: [PYTHON-3.12]
      × No solution found when resolving dependencies:
      ╰─▶ Because only bar[some-extra]==0.1.0 is available and bar[some-extra] depends on anyio==4.2.0, we can conclude that all versions of bar[some-extra] depend on anyio==4.2.0.
          And because foo depends on anyio==4.1.0, we can conclude that foo and all versions of bar[some-extra] are incompatible.
          And because your workspace requires bar[some-extra] and foo, we can conclude that your workspace's requirements are unsatisfiable.
    "###
    );
```
2024-08-16 14:25:26 +00:00
Charlie Marsh
15dfb660ab
Bump version to v0.2.37 (#6134) 2024-08-15 22:13:03 -04:00
Zanie Blue
89efe2491b
Improve display of resolution errors for workspace member conflicts with optional dependencies (#6123)
We have bad error messages for optional (extra) dependencies and
development dependencies in workspaces:

1. We weren't showing the full package, so we'd drop `:dev` and
`[extra]` by accident
2. We didn't include derived packages, e.g., `member[extra]` in tree
processing collapse operation, so we'd include extra clauses like the
ones we removed in #6092

Also

- Reverts
f0de4f71f2
— it turns out it wasn't quite correct and it didn't seem worth using
the custom incompatibility anymore.
- Fixes a bug in the display of `package:dev` which was not showing
`:dev` for some variants (see 94d8020b58)
2024-08-15 20:50:43 -05:00
Ibraheem Ahmed
e6ddce0246
Normalize python_version markers to python_full_version (#6126)
## Summary

Normalize all `python_version` markers to their equivalent
`python_full_version` form. This avoids false positives in forking
because we currently cannot detect any relationships between the two
forms. It also avoids subtle bugs due to the truncating semantics of
`python_version`. For example, given `requires-python = ">3.12"`, we
currently simplify the marker `python_version <= 3.12` to `false`.
However, the version `3.12.1` will be truncated to `3.12` for
`python_version` comparisons, and thus it satisfies the python
requirement and evaluates to `true`.

It is possible to simplify back to `python_version` when writing markers
to the lockfile. However, the equivalent `python_full_version` markers
are often clearer and easier to simplify, so I lean towards leaving them
as `python_full_version`.

There are *a lot* of snapshot updates from this change. I'd like more
eyes on the transformation logic in `python_version_to_full_version` to
ensure that they are all correct.

Resolves https://github.com/astral-sh/uv/issues/6125.
2024-08-15 21:42:15 -04:00
Zanie Blue
1311127991
Improve debug log for interpreter requests during project commands (#6120)
While it's slightly more convenient to log this where we were, it was
pretty unhelpful e.g.

```
DEBUG Interpreter meets the requested Python: `Python >=3.9`
```

What interpreter are we referring to here?
2024-08-16 01:30:59 +00:00
Zanie Blue
fb6b3ff410
Use the proper singular form for workspace member dependencies in resolver errors (#6128) 2024-08-15 21:08:41 +00:00