Commit graph

4903 commits

Author SHA1 Message Date
Charlie Marsh
49937a386d
Remove unconstrained version error from requirements (#3443)
## Summary

It's not clear to me that this should exist at all, but it's causing
errors in projects that don't use `tool.uv.sources`, so we should
definitely remove it for now.
2024-05-07 20:04:44 -04:00
DaniPopes
c59cb1381a
Use into_par_iter instead of par_bridge (#3435)
## Summary

Use the native rayon range iterator instead of bridging the standard
library's.
2024-05-07 19:38:35 +00:00
Charlie Marsh
d665410d59
Move PyO3 derive down (#3434)
## Summary

For some reason the current order is breaking the IntelliJ LSP.
2024-05-07 18:16:28 +00:00
Charlie Marsh
e8b423de77
Use top-level --isolated for uv run (#3431)
## Summary

We already have a global `--isolated`, which means "ignore any on-disk
configuration". I think we should reuse this for the "ignore the
workspace" setting in `uv run`, rather than `--no-workspace`.

I've also merged the existing `--isolated` and `--no-workspace`
behaviors in `uv run` into a single flag. We may not need separate flags
for this, since the current intent seems to be "ignore the workspace
environment"? Though we could always re-add later.

Closes https://github.com/astral-sh/uv/issues/3421.
2024-05-07 13:30:02 -04:00
Charlie Marsh
7fe9f0a3dd
Bump version to v0.1.40 (#3433) 2024-05-07 17:29:29 +00:00
Charlie Marsh
f8a7813add
Rename --force to --allow-existing (#3416)
## Summary

We've found `--force` to be a confusing name here. (Not breaking as this
hasn't shipped in a release.)
2024-05-07 17:11:31 +00:00
konsti
f8901e9989
Always activate non-pep508-extensions (#3428)
Avoid compilation errors when running partial tests due to that feature
being missing.
2024-05-07 16:13:09 +00:00
Alex Waygood
3830e90770
Tell renovate not to try to update GitHub runners (#3427) 2024-05-07 16:09:21 +00:00
Ahmed Ilyas
388dba4815
add compat arg --user error message to pip install (#3424)
Resolves [#3419](https://github.com/astral-sh/uv/issues/3419)

## Summary

Add compatargs to pip install command and hint the user to create a venv
for --user arg.

## Test Plan

Tested it locally.

```bash
cargo run pip install --user flask
   Compiling uv v0.1.39 (/home/ahmedilyas/uv/crates/uv)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 8.96s
     Running `target/debug/uv pip install --user flask`
error: pip install's `--user` is unsupported (use a virtual environment instead).
```
2024-05-07 14:59:53 +00:00
konsti
55f6e4e66b
Make Requirement generic over url type (#3253)
This change allows switching out the url type for requirements. The
original idea was to allow different types for different requirement
origins, so that core metadata reads can ban non-pep 508 requirements
while we only allow them for requirements.txt. This didn't work out
because we expect `&Requirement`s from all sources to match.

I also tried to split `pep508_rs` into a PEP 508 compliant crate and
into our extensions, but they are to tightly coupled.

I think this change is an improvement still as it reduces the hardcoded
dependence on `VerbatimUrl`.
2024-05-07 16:45:49 +02:00
Zanie Blue
8e86cd0c73
Add hint to use a venv to pip sync --user (#3418) 2024-05-07 08:50:23 -05:00
konsti
24f38d7c22
Preserve given for tool.uv.sources paths (#3412)
We now correctly emit relative paths in `uv pip compile` with
`tool.uv.sources` path inputs.

`tool.uv.sources` is mainly intended to be used with the uv lock file
over requirements.txt, but it's good to have basic `uv pip` support
working.

Fixes #3366
2024-05-07 09:00:02 +00:00
Shantanu
18516b4e41
List and uninstall legacy editables (#3415) 2024-05-07 03:51:50 +00:00
Ibraheem Ahmed
94cf604574
Remove unnecessary uses of DashMap and Arc (#3413)
## Summary

All of the resolver code is run on the main thread, so a lot of the
`Send` bounds and uses of `DashMap` and `Arc` are unnecessary. We could
also switch to using single-threaded versions of `Mutex` and `Notify` in
some places, but there isn't really a crate that provides those I would
be comfortable with using.

The `Arc` in `OnceMap` can't easily be removed because of the uv-auth
code which uses the
[reqwest-middleware](https://docs.rs/reqwest-middleware/latest/reqwest_middleware/trait.Middleware.html)
crate, that seems to adds unnecessary `Send` bounds because of
`async-trait`. We could duplicate the code and create a `OnceMapLocal`
variant, but I don't feel that's worth it.
2024-05-06 22:30:43 -04:00
konsti
2c84af15b8
Rename distribution_types::VersionOrUrl to VersionOrUrlRef (#3254)
This is more consistent with the other `*Ref` types and reduces
confusion with the real `VersionOrUrl` type.
2024-05-06 14:15:56 -04:00
Charlie Marsh
e9490b92b5
Upgrade cargo-dist to v0.14.0 (#3414) 2024-05-06 13:48:41 -04:00
Charlie Marsh
ed27dde8a2
Revise comment on virtualenv discovery from cwd (#3406)
See:
37d229b2c2..cd53a28181 (r1590746360)
2024-05-06 14:07:11 +00:00
Charlie Marsh
26045e5f59
Respect and enable uninstalls of existing .egg-info packages (#3380)
## Summary

Users often find themselves dropped into environments that contain
`.egg-info` packages. While we won't support installing these, it's not
hard to support identifying them (e.g., in `pip freeze`) and
_uninstalling_ them.

Closes https://github.com/astral-sh/uv/issues/2841.
Closes #2928.
Closes #3341.

## Test Plan

Ran `cargo run pip freeze --python
/opt/homebrew/Caskroom/miniforge/base/envs/TEST/bin/python`, with an
environment that includes `pip` as an `.egg-info`
(`/opt/homebrew/Caskroom/miniforge/base/envs/TEST/lib/python3.12/site-packages/pip-24.0-py3.12.egg-info`):

```
cffi @ file:///Users/runner/miniforge3/conda-bld/cffi_1696001825047/work
pip==24.0
pycparser @ file:///home/conda/feedstock_root/build_artifacts/pycparser_1711811537435/work
setuptools==69.5.1
wheel==0.43.0
```

Then ran `cargo run pip uninstall`, verified that `pip` was uninstalled,
and no longer listed in `pip freeze`.
2024-05-06 09:47:28 -04:00
konsti
098944fc7d
Improve non-git error message (#3403)
The boxing changes are due to clippy
2024-05-06 13:28:05 +02:00
konsti
d0c3146ef6
Restore verbatim in error message (#3402)
Fixup for
https://github.com/astral-sh/uv/pull/3263#discussion_r1589718035
2024-05-06 11:17:06 +00:00
konsti
b2f6b92e3b
Move pep508-rs Cursor into its own module (#3401) 2024-05-06 10:13:27 +00:00
Shantanu
95f31f2266
Better error for unsupported Python version (#3398)
Fixes #3371

It seems like uv doesn't proactively enforce 3.8+ and in most cases just
issues a warning. This PR keeps that property, only adding the new check
when it is known to fail. I checked the imports in this file and the
other ones seem fine.
2024-05-06 11:12:36 +02:00
konsti
9de49c8a60
Make pubgrub an allowed ident (#3399)
Followup to #3361, fix some backtick-quoting.
2024-05-06 09:10:37 +00:00
renovate[bot]
1efaf3fd31
Update Rust crate junction to v1.1.0 (#3393) 2024-05-06 02:41:15 +00:00
renovate[bot]
aec9573d42
Update Rust crate mailparse to 0.15.0 (#3394) 2024-05-06 02:29:55 +00:00
renovate[bot]
c125ce394a
Update Rust crate rmp-serde to v1.3.0 (#3395) 2024-05-06 02:29:24 +00:00
renovate[bot]
c1370cab1b
Update pre-commit dependencies (#3391) 2024-05-06 02:18:51 +00:00
renovate[bot]
5a8d13a05a
Update Rust crate axoupdater to 0.6.0 (#3392) 2024-05-06 02:12:42 +00:00
renovate[bot]
1cf07ebf08
Update Rust crate zip to v1.1.4 (#3390) 2024-05-06 02:12:21 +00:00
renovate[bot]
409f38c7f5
Update Rust crate tokio-util to v0.7.11 (#3389) 2024-05-06 02:09:04 +00:00
renovate[bot]
cce8e0dd7d
Update Rust crate test-log to v0.2.16 (#3388) 2024-05-06 02:06:27 +00:00
renovate[bot]
c06266874e
Update Rust crate serde to v1.0.200 (#3387) 2024-05-06 02:04:30 +00:00
renovate[bot]
e6efe48d52
Update Rust crate cargo-util to v0.2.11 (#3386) 2024-05-06 02:02:11 +00:00
renovate[bot]
0042533dc3
Update Rust crate base64 to v0.22.1 (#3385) 2024-05-06 02:01:09 +00:00
renovate[bot]
a9756872e6
Update Rust crate anstream to v0.6.14 (#3384) 2024-05-06 02:00:17 +00:00
Charlie Marsh
7e17dd10a3
Add UV_CUSTOM_COMPILE_COMMAND to environment variable docs (#3382)
Closes https://github.com/astral-sh/uv/issues/3381.
2024-05-05 23:33:27 +00:00
Godefroid Chapelle
ef92c38486
Detect current venv when uv is invoked from within a virtualenv (#3379)
Fixes #3378.
2024-05-05 22:53:25 +00:00
Charlie Marsh
6d73db2b1e
Use Cow for source call (#3377) 2024-05-05 02:21:24 +00:00
Charlie Marsh
37635fda56
Update activation scripts from virtualenv (#3376)
## Summary

Refreshes some of the activation scripts, and fixes some bugs in
`activate_this.py` that were likely the rest of some erroneous
copy-pasting.

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

## Test Plan

```
❯ python
Python 3.12.0 (main, Feb 28 2024, 09:44:16) [Clang 15.0.0 (clang-1500.1.0.2.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import httpx
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'httpx'
>>> activator = '.venv/bin/activate_this.py'
>>> with open(activator) as f:
...     exec(f.read(), {'__file__': activator})
...
>>> import httpx
```
2024-05-04 23:30:00 +00:00
Charlie Marsh
2a212eb6a9
Add branch and tag variants to Git reference (#3374)
## Summary

Closes https://github.com/astral-sh/uv/issues/3368.
2024-05-04 21:13:11 +00:00
Charlie Marsh
69e99b3502
Use canonical URLs in satisfaction check (#3373)
## Summary

Closes https://github.com/astral-sh/uv/issues/3367.
2024-05-04 12:44:25 +00:00
Charlie Marsh
8adf5b11ab
Fix Git URL construction in tool.uv.sources (#3365)
## Summary

We were including the `git+` prefix twice:

```
DEBUG At least one requirement is not satisfied: boltons @ git+git+https://github.com/mahmoud/boltons@57fbaa9b673ed85b32458b31baeeae230520e4a0@57fbaa9b673ed85b32458b31baeeae230520e4a0
```

## Test Plan

Extended the test to include a Git URL; verified that we don't trigger a
reinstall.
2024-05-04 03:02:14 +00:00
konsti
44858bc28d
Use preview mode for tool.uv.sources (#3277)
Only allow using `tool.uv.sources` with preview mode, the design isn't
finalized yet.

Not sure what to label this, do we want a preview section and label for
the release notes?
2024-05-04 02:47:47 +00:00
Charlie Marsh
363e808724
Tweak some of the tool.uv.sources error messages for consistency (#3364) 2024-05-04 02:38:47 +00:00
Charlie Marsh
100935f4f1
Respect editable = true setting in sources map (#3363)
## Summary

We need to partition the editable and non-editable requirements. As-is,
`editable = true` requirements were still being installed as
non-editable.
2024-05-04 02:17:55 +00:00
Charlie Marsh
a63018591e
Unset target when creating virtual environments (#3362)
## Summary

We were writing the build dependencies into the `--target` directory,
which both made builds fail and led to them leaking into the user's
directory.

Closes https://github.com/astral-sh/uv/issues/3349.
2024-05-03 23:21:23 +00:00
konsti
4f87edbe66
Add basic tool.uv.sources support (#3263)
## Introduction

PEP 621 is limited. Specifically, it lacks
* Relative path support
* Editable support
* Workspace support
* Index pinning or any sort of index specification

The semantics of urls are a custom extension, PEP 440 does not specify
how to use git references or subdirectories, instead pip has a custom
stringly format. We need to somehow support these while still stying
compatible with PEP 621.

## `tool.uv.source`

Drawing inspiration from cargo, poetry and rye, we add `tool.uv.sources`
or (for now stub only) `tool.uv.workspace`:

```toml
[project]
name = "albatross"
version = "0.1.0"
dependencies = [
  "tqdm >=4.66.2,<5",
  "torch ==2.2.2",
  "transformers[torch] >=4.39.3,<5",
  "importlib_metadata >=7.1.0,<8; python_version < '3.10'",
  "mollymawk ==0.1.0"
]

[tool.uv.sources]
tqdm = { git = "https://github.com/tqdm/tqdm", rev = "cc372d09dcd5a5eabdc6ed4cf365bdb0be004d44" }
importlib_metadata = { url = "https://github.com/python/importlib_metadata/archive/refs/tags/v7.1.0.zip" }
torch = { index = "torch-cu118" }
mollymawk = { workspace = true }

[tool.uv.workspace]
include = [
  "packages/mollymawk"
]

[tool.uv.indexes]
torch-cu118 = "https://download.pytorch.org/whl/cu118"
```

See `docs/specifying_dependencies.md` for a detailed explanation of the
format. The basic gist is that `project.dependencies` is what ends up on
pypi, while `tool.uv.sources` are your non-published additions. We do
support the full range or PEP 508, we just hide it in the docs and
prefer the exploded table for easier readability and less confusing with
actual url parts.

This format should eventually be able to subsume requirements.txt's
current use cases. While we will continue to support the legacy `uv pip`
interface, this is a piece of the uv's own top level interface. Together
with `uv run` and a lockfile format, you should only need to write
`pyproject.toml` and do `uv run`, which generates/uses/updates your
lockfile behind the scenes, no more pip-style requirements involved. It
also lays the groundwork for implementing index pinning.

## Changes

This PR implements:
* Reading and lowering `project.dependencies`,
`project.optional-dependencies` and `tool.uv.sources` into a new
requirements format, including:
  * Git dependencies
  * Url dependencies
  * Path dependencies, including relative and editable
* `pip install` integration
* Error reporting for invalid `tool.uv.sources`
* Json schema integration (works in pycharm, see below)
* Draft user-level docs (see `docs/specifying_dependencies.md`)

It does not implement:
* No `pip compile` testing, deprioritizing towards our own lockfile
* Index pinning (stub definitions only)
* Development dependencies
* Workspace support (stub definitions only)
* Overrides in pyproject.toml
* Patching/replacing dependencies

One technically breaking change is that we now require user provided
pyproject.toml to be valid wrt to PEP 621. Included files still fall
back to PEP 517. That means `pip install -r requirements.txt` requires
it to be valid while `pip install -r requirements.txt` with `-e .` as
content falls back to PEP 517 as before.

## Implementation

The `pep508` requirement is replaced by a new `UvRequirement` (name up
for bikeshedding, not particularly attached to the uv prefix). The still
existing `pep508_rs::Requirement` type is a url format copied from pip's
requirements.txt and doesn't appropriately capture all features we
want/need to support. The bulk of the diff is changing the requirement
type throughout the codebase.

We still use `VerbatimUrl` in many places, where we would expect a
parsed/decomposed url type, specifically:
* Reading core metadata except top level pyproject.toml files, we fail a
step later instead if the url isn't supported.
* Allowed `Urls`.
* `PackageId` with a custom `CanonicalUrl` comparison, instead of
canonicalizing urls eagerly.
* `PubGrubPackage`: We eventually convert the `VerbatimUrl` back to a
`Dist` (`Dist::from_url`), instead of remembering the url.
* Source dist types: We use verbatim url even though we know and require
that these are supported urls we can and have parsed.

I tried to make improve the situation be replacing `VerbatimUrl`, but
these changes would require massive invasive changes (see e.g.
https://github.com/astral-sh/uv/pull/3253). A main problem is the ref
`VersionOrUrl` and applying overrides, which assume the same
requirement/url type everywhere. In its current form, this PR increases
this tech debt.

I've tried to split off PRs and commits, but the main refactoring is
still a single monolith commit to make it compile and the tests pass.

## Demo

Adding
d1ae3b85d5/pyproject.json
as json schema (v7) to pycharm for `pyproject.toml`, you can try the IDE
support already:


![pycharm](599082c7-6be5-41c1-a3cd-516092382f8d)


[dove.webm](c293c272-c80b-459d-8c95-8c46a8d198a1)
2024-05-03 21:10:50 +00:00
samypr100
2ffb252498
Update Rust to v1.78 (#3361)
## Summary

Updates rust to 1.78 in `rust-toolchain.toml`

See: https://blog.rust-lang.org/2024/05/02/Rust-1.78.0.html

### Potential blockers

* homebre still on 1.77 -
https://github.com/Homebrew/homebrew-core/pull/170649
* conda-forge still on 1.77 - https://anaconda.org/conda-forge/rust
2024-05-03 20:07:13 +00:00
Andrew Gallant
1089abda3f
require serde and rkyv everywhere; remove optional serde and rkyv features (#3345)
In *some* places in our crates, `serde` (and `rkyv`) are optional
dependencies. I believe this was done out of reasons of "good sense,"
that is, it follows a Rust ecosystem pattern where serde integration
tends to be an opt-in crate feature. (And similarly for `rkyv`.)

However, ultimately, `uv` itself requires `serde` and `rkyv` to
function. Since our crates are strictly internal, there are limited
consumers for our crates without `serde` (and `rkyv`) enabled. I think
one possibility is that optional `serde` (and `rkyv`) integration means
that someone can do this:

    cargo test -p pep440_rs

And this will run tests _without_ `serde` or `rkyv` enabled. That in
turn could lead to faster iteration time by reducing compile times. But,
I'm not sure this is worth supporting. The iterative compilation times
of
individual crates are probably fast enough in debug mode, even with
`serde` and `rkyv` enabled. Namely, `serde` and `rkyv` themselves
shouldn't need to be re-compiled in most cases. On `main`:

```
from-scratch: `cargo test -p pep440_rs --lib` 0.685
incremental: `cargo test -p pep440_rs --lib` 0.278s
from-scratch: `cargo test -p pep440_rs --features serde,rkyv --lib` 3.948s
incremental: `cargo test -p pep440_rs --features serde,rkyv --lib` 0.321s
```

So while a from-scratch build does take significantly longer, an
incremental build is about the same.

The benefit of doing this change is two-fold:

1. It brings out crates into alignment with "reality." In particular,
   some crates were _implicitly_ relying on `serde` being enabled
   without explicitly declaring it. This technically means that our
   `Cargo.toml`s were wrong in some cases, but it is hard to observe it
   because of feature unification in a Cargo workspace.
2. We no longer need to deal with the cognitive burden of writing
   `#[cfg_attr(feature = "serde", ...)]` everywhere.
2024-05-03 10:21:03 -04:00
konsti
714adebbd7
Avoid stack overflows on more windows tests (#3344)
Fix windows CI by increasing the debug stack size on windows:
*
2455300039
*
2455094999
*
2455094926
*
2455081040
2024-05-03 12:21:00 +00:00