Commit graph

3331 commits

Author SHA1 Message Date
Charlie Marsh
1243c5e28c
Avoid URL parsing when deserializing wheels (#5235)
## Summary

This PR slots in `UrlString` for `WheelWire`, which IIUC should avoid
parsing URLs during deserialization?
2024-07-20 02:11:26 +00:00
Zanie Blue
833097b93f
Bump version to 0.2.27 (#5230) 2024-07-19 22:06:49 +00:00
Ibraheem Ahmed
bb73edb03b
Respect local versions for all user requirements (#5232)
## Summary

This fixes a few bugs introduced by
https://github.com/astral-sh/uv/pull/5104. I previously thought we could
track conflicting locals the same way we track conflicting URLs in
forks, but it turns out that ends up being very tricky. URL forks work
because we prioritize directly URL requirements. We can't prioritize
locals in the same way without conflicting with the URL prioritization
(this may be possible but it's not trivial), so we run into issues where
a correct resolution depends on the order in which dependencies are
traversed.

Instead, we track local versions across all forks in `Locals`. When
applying a local version, we apply all locals with markers that
intersect with the current fork. This way we end up applying some local
versions without creating a fork. For example, given:
```
// pyproject.toml
dependencies = [
    "torch==2.0.0+cu118 ; platform_machine == 'x86_64'",
]

// requirements.in
torch==2.0.0
.
```

We choose `2.0.0+cu118` in all cases. However, if a disjoint fork is
created based on local versions, the resolver will choose the most
compatible local when it narrows to a specific fork. Thus we correctly
respect local versions when forking:
```
// pyproject.toml
dependencies = [
    "torch==2.0.0+cu118 ; platform_machine == 'x86_64'",
    "torch==2.0.0+cpu ; platform_machine != 'x86_64'"
]

// requirements.in
torch==2.0.0
.
``` 

We should also be able to use a similar strategy for
https://github.com/astral-sh/uv/pull/5150.

## Test Plan

This fixes https://github.com/astral-sh/uv/issues/5220 locally for me,
as well as a few other bugs that were not reported yet.
2024-07-19 16:56:09 -05:00
Charlie Marsh
92e11022e7
Downgrade to winsafe v0.0.19 (#5233) 2024-07-19 17:14:57 -04:00
Charlie Marsh
a253913288
Don't apply irrelevant constraints when validating site-packages (#5231)
## Summary

The current code was checking every constraint against every
requirement, regardless of whether they were applicable. In general,
this isn't a big deal, because this method is only used as a fast-path
to skip resolution -- so we just had way more false-negatives than we
should've when constraints were applied. But it's clearly wrong :)

## Test Plan

- `uv venv`
- `uv pip install flask`
- `uv pip install --verbose flask -c constraints.txt` (with `numpy<1.0`)

Prior to this change, Flask was reported as not satisfied.
2024-07-19 20:49:22 +00:00
Zanie Blue
583a6e57f2
Write tools concept doc (#5207) 2024-07-19 14:24:43 -05:00
Ahmed Ilyas
3ee3db23d6
Check python pin compatibility with Requires-Python (#4989)
## Summary

Resolves #4969 

## Test Plan

`cargo test` and manual tests.

---------

Co-authored-by: Zanie Blue <contact@zanie.dev>
2024-07-19 18:17:41 +00:00
Charlie Marsh
7762d78281
Add color to python pin CLI (#5215)
## Summary

![Screenshot 2024-07-19 at 9 03
10 AM](https://github.com/user-attachments/assets/5668bd23-3f09-4964-bc09-9f3788f5a841)
2024-07-19 13:19:28 -04:00
Ibraheem Ahmed
12dd450a8e
Implement uv init (#4791)
## Summary

Implements the `uv init` command, which initializes a project
(`pyproject.toml`, `README.md`, `src/__init__.py`) in the current
directory, or in the given path. `uv init` also does workspace
discovery.

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

---------

Co-authored-by: Zanie Blue <contact@zanie.dev>
2024-07-19 15:11:48 +00:00
Charlie Marsh
2169902bd9
Avoid TOCTOU errors in .python-version reads (#5223)
## Summary

Not a big deal, but better to try the operation and handle the failure
case than to check if the file exists and _then_ read it.
2024-07-19 15:08:20 +00:00
Charlie Marsh
ed9b820815
Remove trailing period from user-facing messages (#5218)
## Summary

Per #5209, we only show periods in messages when the message itself
spans more than a single sentence.
2024-07-19 10:43:49 -04:00
Mathieu Kniewallner
f2e2825d1b
docs(settings): bunch of fixes and improvements (#5177)
## Summary

Spotted some issues in the settings documentation, and room for small
improvements by linking to PEPs/RFCs.

Also updating contribution documentation to mention that it's necessary
to enable the virtual environment before running `mkdocs serve`.

## Test Plan

Running documentation locally.
2024-07-19 10:32:21 -04:00
FishAlchemist
b1a350cb9f
Added a way to inspect installation scripts on Powershell(Windows) (#5157)
## Summary
### command
 ```powershell
    powershell -c "irm https://astral.sh/uv/install.ps1 | more"
 ```
Add a method to inspect installation script files that works on Windows,
it may not work on other platforms supported by PowerShell. <br>
Other platforms information:
[PowerShell differences on non-Windows platforms / General Unix
interoperability
changes](https://learn.microsoft.com/en-us/powershell/scripting/whats-new/unix-support?view=powershell-7.4#general-unix-interoperability-changes)
[Differences between Windows PowerShell 5.1 and PowerShell 7.x / Removal
of the more
function](https://learn.microsoft.com/en-us/powershell/scripting/whats-new/differences-from-windows-powershell?view=powershell-7.4#removal-of-the-more-function)
<!-- What's the purpose of the change? What does it do, and why? -->

## Test Plan
**terminal**
* Powershell Version: 5.1.22621.3880 (Windows)

![image](https://github.com/user-attachments/assets/418c10a4-f672-4c79-9d3b-7c58822316dd)
* Powershell Version: 7.4.3 (Windows)

![image](https://github.com/user-attachments/assets/9ee73310-a244-4320-a092-df8c6f0745c5)

## Result (Website)

![image](https://github.com/user-attachments/assets/3faede7d-4004-4e2c-b35a-80147532019b)

---------

Co-authored-by: Zanie Blue <contact@zanie.dev>
2024-07-19 14:28:46 +00:00
Zanie Blue
149c612026
Touchups to tools guide (#5202) 2024-07-19 14:26:54 +00:00
Di-Is
0d9d559785
Change to show only the python installed on the system if --python-preference only-system is specified (#5219)
Fix #5211

## Summary

Change to show only the python installed on the system if
`--python-preference only-system` is specified.

Below is an example of running the command before the change, showing
Python not installed on the system.

#### Before
```bash
# Check system python
$ uv python --preview list --python-preference only-system
cpython-3.12.4-linux-x86_64-gnu     <download available>
cpython-3.12.3-linux-x86_64-gnu     /usr/bin/python3.12
cpython-3.12.3-linux-x86_64-gnu     /usr/bin/python3
cpython-3.12.3-linux-x86_64-gnu     /bin/python3.12
cpython-3.12.3-linux-x86_64-gnu     /bin/python3
cpython-3.11.9-linux-x86_64-gnu     <download available>
cpython-3.10.14-linux-x86_64-gnu    <download available>
cpython-3.9.19-linux-x86_64-gnu     <download available>
cpython-3.8.19-linux-x86_64-gnu     <download available>
cpython-3.7.9-linux-x86_64-gnu      <download available>
```

This PR changes the display to show only Python installed on the system.

#### After

```bash
$ cargo run python --preview list --python-preference only-system
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.11s
     Running `target/debug/uv python list --python-preference only-system --preview`
cpython-3.12.3-linux-x86_64-gnu    /usr/bin/python3.12
cpython-3.12.3-linux-x86_64-gnu    /usr/bin/python3
cpython-3.12.3-linux-x86_64-gnu    /bin/python3.12
cpython-3.12.3-linux-x86_64-gnu    /bin/python3
```

## Test Plan
- `cargo run python list --python-preference only-system` in Ubuntu
24.04 to verify the display.
- `cargo run python list` in Ubuntu 24.04 to verify that the results
before and after the change were the same.
2024-07-19 14:15:32 +00:00
Charlie Marsh
40b962e6bb
Fix reference to uv run in uv tree CLI (#5216) 2024-07-19 13:30:40 +00:00
Charlie Marsh
729148dac9
Add --frozen to uv add, uv remove, and uv tree (#5214)
## Summary

E.g., `uv add foo --frozen` will avoid updating or even creating a
`uv.lock`.
2024-07-19 13:18:32 +00:00
Charlie Marsh
fb1a529106
Process completed Python installs and uninstalls as a stream (#5203)
## Summary

This ensures that we process Python installs and uninstalls as soon as
they complete, rather than waiting for them all to complete, then
processing them sequentially. In practice, it shouldn't be much of a
difference (since the processing is code is fairly light), but it
strikes me as more correct.
2024-07-19 12:50:38 +00:00
Danny
ef56df26bf
Support --link-mode=symlink (#5208)
## Summary

Addressing this [issue](https://github.com/astral-sh/uv/issues/5147) by
adding the capability for Symbolic linking as a link mode when
installing or syncing dependencies.
2024-07-19 08:41:18 -04:00
Charlie Marsh
bb84cbb39d
Use max rather than min to sort managed Pythons (#5205)
## Summary

See: https://github.com/astral-sh/uv/issues/5139 and
https://github.com/astral-sh/uv/pull/5201#discussion_r1683636935.

## Test Plan

Verified that 3.12 was chosen above 3.8 in:

- `cargo run -- python uninstall --all`
- `cargo run -- python install 3.8 3.12`
- `cargo run -- tool run -v httpx`
2024-07-19 12:35:17 +00:00
konsti
93ba676f2e
Log origin of version selection (#5186)
Log whether a version was picked because it was the next version or
because it was a preference (installed, lockfile or sibling fork)
2024-07-19 08:15:45 +00:00
Charlie Marsh
d54ae4e381
Use +- install output for Python versions (#5201)
## Summary

Follow-up to https://github.com/astral-sh/uv/pull/4939. Uses a format
that's closer to `uv pip install`, with some special-casing for single
Pythons.

## Test Plan

A few examples:

![Screenshot 2024-07-18 at 8 39
35 PM](https://github.com/user-attachments/assets/868d4c87-d8f4-4e5f-a52c-1f7a3e8d6a16)
![Screenshot 2024-07-18 at 8 39
46 PM](https://github.com/user-attachments/assets/3a12461e-9d9b-4c33-a685-55ca7256ff52)
![Screenshot 2024-07-18 at 8 39
27 PM](https://github.com/user-attachments/assets/1059e6d6-a445-4531-8496-59bc51d01663)
![Screenshot 2024-07-18 at 8 39
54 PM](https://github.com/user-attachments/assets/dcb69e86-8702-402b-a0cd-6f827b04a6ab)
2024-07-18 20:46:33 -04:00
Ibraheem Ahmed
360079fd05
Write project guide (#5195)
## Summary

Write the project guide that was added in
https://github.com/astral-sh/uv/pull/5135.

I tried to expand on details as much as I felt was necessary for someone
new to python package managers (which was myself a couple months ago).
2024-07-18 19:45:25 -05:00
Charlie Marsh
5d6f793101
Make Python install robust to individual failures (#5199)
## Summary

We have roughly this code for uninstalls, but for installs, we eject as
soon as we hit a failure, leaving some things in a partial state.
2024-07-18 20:31:54 -04:00
Tim Felgentreff
24a0268675
Add GraalPy support (#5141)
<!--
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

Currently, `uv` refuses to install anything on GraalPy. This is
currently blocking GraalPy testing with cibuildwheel, since manylinux
includes both `uv` and `graalpy` (but doesn't test with `uv`), whereas
cibuildwheel defaults to `uv`. See e.g.
2750618295
where it gives
```
      + python -m build /project/sample_proj --wheel --outdir=/tmp/cibuildwheel/built_wheel --installer=uv
  * Creating isolated environment: venv+uv...
  * Using external uv from /usr/local/bin/uv
  * Installing packages in isolated environment:
    - setuptools >= 40.8.0
  > /usr/local/bin/uv pip install "setuptools >= 40.8.0"
  < error: Unknown implementation: `graalpy`
```

## Test Plan

I simply based the GraalPy support on PyPy and added some small tests.
I'm open to discussing how to test this. GraalPy is available for
manylinux images and with setup-python, so we should be able to add
tests against it to the CI. I locally confirmed by installing `uv` into
a GraalPy venv and then trying things like `uv pip install Pillow` and
testing those extensions.
2024-07-18 19:28:28 -05:00
Charlie Marsh
54bca18184
Use which-retrieved path directly when spawning pager (#5198)
## Summary

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

## Test Plan

Ran `cargo run -- help pip compile` on my Windows machine, which failed
before but succeeds after this change.
2024-07-18 20:29:00 +00:00
Charlie Marsh
dfe2faa71e
Add --locked and --frozen to uv run CLI (#5196)
## Summary

You can now use `uv run --locked` to assert that the lockfile doesn't
change, or `uv run --frozen` to run without attempting to update the
lockfile at all.

Closes https://github.com/astral-sh/uv/issues/5185.
2024-07-18 18:55:17 +00:00
Charlie Marsh
6a6e3b464f
Make missing project table a tracing warning (#5194)
Closes https://github.com/astral-sh/uv/issues/5068.
2024-07-18 18:21:39 +00:00
konsti
5bcdaedf8b
Merge extras in lockfile (#5181)
As user, you specify a list of extras. Internally, we decompose this
into one virtual package per extra. We currently leak this abstraction
by writing one entry per extra to the lockfile:

```toml
[[distribution]]
name = "foo"
version = "4.39.0.dev0"
source = { editable = "." }
dependencies = [
    { name = "pandas" },
    { name = "pandas", extra = "excel" },
    { name = "pandas", extra = "hdf5" },
    { name = "pandas", extra = "html", marker = "os_name != 'posix'" },
    { name = "pandas", extra = "output-formatting", marker = "os_name == 'posix'" },
    { name = "pandas", extra = "plot", marker = "os_name == 'posix'" },
]
```

Instead, we should merge the extras into a list of extras, creating a
more concise lockfile:

```toml
[[distribution]]
name = "foo"
version = "4.39.0.dev0"
source = { editable = "." }
dependencies = [
    { name = "pandas", extra = ["excel", "hdf5"] },
    { name = "pandas", extra = ["html"], marker = "os_name != 'posix'" },
    { name = "pandas", extra = ["output-formatting", "plot"], marker = "os_name == 'posix'" },
]
```

The base package is now implicitly included, as it is in PEP 508.

Fixes #4888
2024-07-18 14:07:49 -04:00
Charlie Marsh
4a875afc07
Skip invalid tools in uv tool list (#5156)
## Summary

Makes the `tools()` return value include per-tool errors. This makes it
easy to skip (rather than failing) in `uv tool list`, _and_ improves `uv
tool uninstall` to remove those invalid tools, rather than leaving them
around. (We already had that behavior for `uv tool uninstall ruff` with
an invalid `ruff`, but `uv tool uninstall --all` just left them.)

Closes https://github.com/astral-sh/uv/issues/5151.
2024-07-18 17:56:40 +00:00
Ibraheem Ahmed
bbd65fc626
Set exact version specifiers when resolving from lockfile (#5193)
## Summary

Should resolve https://github.com/astral-sh/uv/issues/5192.

## Test Plan

@konstin can you confirm this fixes your issue?
2024-07-18 19:02:08 +02:00
konsti
7beae77283
Search for all python3.x in PATH (#5148)
Search for all `python3.x` minor versions in PATH, skipping those we
already know we can use.

For example, let's say `python` and `python3` are Python 3.10. When a
user requests `>= 3.11`, we still need to find a `python3.12` in PATH.
We do so with a regex matcher.

Fixes #4709
2024-07-18 17:00:01 +02:00
Charlie Marsh
36a0ee9822
Remove executable alias; import anstream (#5187)
Post-push review from https://github.com/astral-sh/uv/pull/5160.
2024-07-18 14:09:29 +00:00
Charlie Marsh
8484611753
Rename Error::IO to Error::Io (#5174)
## Summary

I believe this is by convention (see, e.g., in Rust itself:
https://github.com/search?q=repo%3Arust-lang%2Frust+%2F%28%3F-i%29Io%2F&type=code).
2024-07-18 04:13:45 +00:00
Zanie Blue
61a81da760
Move integration guide docs and edit Azure integration guide (#5117) 2024-07-18 03:47:32 +00:00
konsti
fbb00f701c
Warn about unconstrained direct deps in lowest resolution (#5142)
Warn when there is a direct dependency without a lower bound and
`--resolution lowest` is set.

---------

Co-authored-by: Zanie Blue <contact@zanie.dev>
2024-07-18 03:44:53 +00:00
Charlie Marsh
4f73004f95
Remove 'bare' vernacular from virtualenv crate (#5175)
## Summary

"Bare" made sense when we had a variant that seeded the environment, but
now that the crate _only_ creates a bare environment, lets drop that
terminology.
2024-07-18 02:11:16 +00:00
Charlie Marsh
564f4b2958
Use display representation for download error (#5173)
## Summary

Turns out we already have display for this.

Closes https://github.com/astral-sh/uv/issues/4914.
2024-07-18 02:05:17 +00:00
Charlie Marsh
91bf213641
Use specialized error message for invalid Python install / uninstall requests (#5171)
## Summary

Closes https://github.com/astral-sh/uv/issues/4819.
2024-07-17 20:47:55 -04:00
Charlie Marsh
622e9e8799
Add uv tool list --show-paths to show install paths (#5164)
## Summary

Closes https://github.com/astral-sh/uv/issues/4823.
2024-07-17 19:11:13 -04:00
Charlie Marsh
6a49dba30c
Enforce hashes in lockfile install (#5170)
## Summary

Hashes will be validated if present, but aren't required (since, e.g.,
some registries will omit them, as will Git dependencies and such).

Closes https://github.com/astral-sh/uv/issues/5168.
2024-07-17 23:10:37 +00:00
Charlie Marsh
218ae2c13e
Key hash policy on version, rather than package (#5169)
## Summary

First part of: https://github.com/astral-sh/uv/issues/5168.
2024-07-17 19:01:49 -04:00
Charlie Marsh
82d94838cb
Implement a --verify-hashes hash-checking mode (#4007)
## Summary

This is an alternative to `--require-hashes` which will validate a hash
if it's present, but ignore requirements that omit hashes or are absent
from the lockfile entirely.

So, e.g., transitive dependencies that are missing will _not_ error; nor
will dependencies that are included but lack a hash.

Closes https://github.com/astral-sh/uv/issues/3305.
2024-07-17 21:25:31 +00:00
Charlie Marsh
ba4e2e3d2a
Use the strongest hash in the lockfile (#5167)
## Summary

We only need to store one hash -- it should be the "strongest" hash. In
practice, most registries (like PyPI) only serve one, and we only
compute a SHA256 hash for direct URLs.

Part of: https://github.com/astral-sh/uv/issues/4924

## Test Plan

I verified that changing:

```diff
diff --git a/crates/distribution-types/src/hash.rs b/crates/distribution-types/src/hash.rs
index 553a74f55..d36c62286 100644
--- a/crates/distribution-types/src/hash.rs
+++ b/crates/distribution-types/src/hash.rs
@@ -31,7 +31,7 @@ impl<'a> HashPolicy<'a> {
     pub fn algorithms(&self) -> Vec<HashAlgorithm> {
         match self {
             Self::None => vec![],
-            Self::Generate => vec![HashAlgorithm::Sha256],
+            Self::Generate => vec![HashAlgorithm::Sha256, HashAlgorithm::Sha512],
             Self::Validate(hashes) => {
                 let mut algorithms = hashes.iter().map(HashDigest::algorithm).collect::<Vec<_>>();
                 algorithms.sort();
```

Then running `uv lock` with a URL gave me:

```toml
[[distribution]]
name = "iniconfig"
version = "2.0.0"
source = { url = "62565a6e1c/iniconfig-2.0.0-py3-none-any.whl" }
wheels = [
    { url = "62565a6e1c/iniconfig-2.0.0-py3-none-any.whl", hash = "sha512:44cc53a6c8dd7cf4d6d52bded308bcc4b4f85fff2ed081f60f7d4beaa86a7cde6d099e3976331232d4cbd472ad5d1781064725b0999c7cd3a2a4d42df687ee81" },
]
```
2024-07-17 20:38:33 +00:00
Charlie Marsh
eb24717a9b
Add uv tool dir --bin to show executable directory (#5160)
## Summary

Closes https://github.com/astral-sh/uv/issues/5159.
2024-07-17 16:30:45 -04:00
Charlie Marsh
e271d1fdde
Make registry hashes optional in the lockfile (#5166)
## Summary

If a registry doesn't include hashes, then we won't include them in the
lockfile either.

Part of: https://github.com/astral-sh/uv/issues/4924.

Closes: https://github.com/astral-sh/uv/issues/5120.
2024-07-17 16:29:49 -04:00
Charlie Marsh
8edfdbed77
Make entrypoint writes atomic to avoid overwriting symlinks (#5165)
## Summary

It turns out that if `path` is a symlink,
`File::create(path)?.write_all(content.as_ref())?` will overwrite the
_target_ file. That means an entrypoint named `python` would actually
overwrite the user's source Python executable, which is symlinked into
the virtual environment.

This PR replaces that code with our atomic write method.

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

## Test Plan

I ran through the test plan
`https://github.com/astral-sh/uv/issues/5152`, but used an executable
named `bar` linked to `foo.txt` instead...
2024-07-17 19:44:26 +00:00
Charlie Marsh
f74235bb56
Validate docs in CI (#5158)
## Summary

Closes https://github.com/astral-sh/uv/issues/5155.
2024-07-17 14:14:04 -04:00
Charlie Marsh
c9e66bf8c8
Add publish-docs to release workflow (#5153)
## Summary

Forgot to add this here. Just kicked it off manually for the last
release.
2024-07-17 17:49:09 +00:00
Charlie Marsh
70c1e5926a
Fix reference to projects.md (#5154) 2024-07-17 13:45:48 -04:00