Commit graph

4903 commits

Author SHA1 Message Date
Charlie Marsh
791207c14f
Add PIP_COMPATIBILITY.md to document known deviations from pip (#2244)
## Summary

Closes https://github.com/astral-sh/uv/issues/2023.
2024-03-06 21:33:27 +00:00
Bas Schoenmaeckers
e7742070c1
feat: Add netrc authentication to uv-client (#2241)
## Summary

Add netrc support to the uv-client.

closes #1405 

## Test Plan

I've added a corresponding test case to validate the correct header.
Furthermore a tested it against a real world private repository.
2024-03-06 20:48:30 +00:00
Charlie Marsh
a5d5e99496
Implement --break-system-packages (#2249)
## Summary

Per the
[`EXTERNALLY-MANAGED`](https://packaging.python.org/en/latest/specifications/externally-managed-environments/)
spec, installers SHOULD add a `--break-system-packages` flag to allow
users to override the package manager warnings raised by
`EXTERNALLY-MANAGED`. This PR adds the flag to comply with the spec, and
enable system Python installs on newer versions of certain
distributions.

While this flag feels kind of bad, it's not necessarily a change in
behavior. We _already_ allow installing into these system distributions
-- it's just that `EXTERNALLY-MANAGED` doesn't exist for distributions
that were packaged prior to the spec, so we don't run into this problem.

Closes https://github.com/astral-sh/uv/issues/2234.
2024-03-06 15:37:28 -05:00
Charlie Marsh
65e1005bfa
Stop exposing client_raw (#2250)
## Summary

This is no longer necessary as `AsyncHttpRangeReader` now accepts
`ClientWithMiddleware` -- which is good, because it means all relevant
middleware will be enforced (like offline, or `.netrc` in the future).
2024-03-06 15:37:19 -05:00
konsti
97b4526825
Update pubgrub onto upstream (#2243)
No functional changes, just pulling in the upstream changes in
preparation of new changes.
2024-03-06 16:06:35 +00:00
Michał Górny
c6af78d153
test: pip_list: Fix replacement pattern computation (#2237)
## Summary

Fix computing replacements pattern for pip_list tests to count
characters in the original directory string rather than the
regex::escape'd string. The latter yields incorrect results if the
workspace path contains characters such as `-` or `.`.

Fixes #2232

## Test Plan

`cargo test --test pip_list` in a directory named `uv-test` to provoke
the bug.
2024-03-06 08:32:07 -05:00
Charlie Marsh
3ca777673f
Make Client optional in requirements-txt (#2229) 2024-03-06 05:49:09 +00:00
samypr100
2b2de0d09e
ci: maturin version uses env var (#2225)
## Summary

Adjust maturing version to use env var for reusability in the workflow.


## Test Plan

CI `Build binaries` workflow uses correct version and passes
2024-03-05 23:23:51 -05:00
jannisko
71626e8dec
Support remote https:// requirements files (#1332) (#2081)
## Summary

Allow using http(s) urls for constraints and requirements files handed
to the CLI, by handling paths starting with `http://` or `https://`
differently. This allows commands for such as: `uv pip install -c
https://raw.githubusercontent.com/apache/airflow/constraints-2.8.1/constraints-3.8.txt
requests`.

closes #1332

## Test Plan

Testing install using a `constraints.txt` file hosted on github in the
airflow repository:

fbdc2eba8e/crates/uv/tests/pip_install.rs (L1440-L1484)

## Advice Needed

- filesystem/http dispatch is implemented at a relatively low level (at
`crates/uv-fs/src/lib.rs#read_to_string`). Should I change some naming
here so it is obvious that the function is able to dispatch?
- I kept the CLI argument for -c and -r as a PathBuf, even though now it
is technically either a path or a url. We could either keep this as is
for now, or implement a new enum for this case? The enum could then
handle dispatch to files/http.
- Using another abstraction layer like
https://docs.rs/object_store/latest/object_store/ for the
files/urls/[s3] could work as well, though I ran into a bug during
testing which I couldn't debug
2024-03-06 04:18:11 +00:00
samypr100
2ebcef9ad8
feat: cmd.exe detection heuristic (#2226)
## Summary

Follow up from discussion in https://github.com/astral-sh/uv/pull/2223

Detect CMD.exe by checking if `PROMPT` env var is set on windows,
otherwise assume it's PowerShell.

Note, this will not work if user modifies their system env vars to
include `PROMPT` by default or if they launch nested PowerShell from
Command Prompt (e.g. `Developer PowerShell for VS 2022`).

## Test Plan

Only tested locally, although we try to add some CI tests that
specifically use CMD.exe

Command Prompt
```
Microsoft Windows [Version 10.0.19044.3086]
(c) Microsoft Corporation. All rights reserved.

Z:\Users\samypr100\dev\uv>Z:\Users\samypr100\.cargo\bin\cargo.exe +stable run --color=always -- venv "Foo Bar"
    Finished dev [unoptimized + debuginfo] target(s) in 0.69s
     Running `target\debug\uv.exe venv "Foo Bar"`
Using Python 3.12.2 interpreter at: Z:\Users\samypr100\AppData\Local\Programs\Python\Python312\python.exe
Creating virtualenv at: Foo Bar
Activate with: "Foo Bar\Scripts\activate"
```

Power Shell
```
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

Try the new cross-platform PowerShell https://aka.ms/pscore6

PS Z:\Users\samypr100\dev\uv>Z:\Users\samypr100\.cargo\bin\cargo.exe +stable run --color=always -- venv "Foo Bar"
    Finished dev [unoptimized + debuginfo] target(s) in 0.63s
     Running `target\debug\uv.exe venv "Foo Bar"`
Using Python 3.12.2 interpreter at: Z:\Users\samypr100\AppData\Local\Programs\Python\Python312\python.exe
Creating virtualenv at: Foo Bar
Activate with: & "Foo Bar\Scripts\activate"
```
2024-03-06 03:29:50 +00:00
Charlie Marsh
511e32e406
Add .stdout() and .stderr() outputs to Printer (#2227)
## Summary

This adds a `.stdout()` stream to `Printer`, so that it automatically
respects `--quiet`.

Motivated by
https://github.com/astral-sh/uv/pull/2115/files#r1513753101.
2024-03-06 03:22:00 +00:00
Chan Kang
395be442fc
Implement uv pip show (#2115)
## Summary
Implementation for https://github.com/astral-sh/uv/issues/1594
The output will contain only the name, version and location of the
packages for now but it should be extendable to include other
information in the future.

Quite inexperienced with Rust, so please forgive me if there are things
that obviously don't make sense 😭

## Test Plan
Added a bunch of unit tests. The exit code behavior matches `pip`'s
behavior:
- When the package is found -> exit code 0
- When the package isn't found -> exit code 1
- When one package is found but another isn't -> exit code 0
2024-03-06 03:08:13 +00:00
Charlie Marsh
30bc16a3c1
Minor internal refactors list (#2224) 2024-03-06 01:54:21 +00:00
Simon Brugman
190a161cc5
Support for --format=freeze and --format=json in uv pip list (#1998)
Implements `pip list --format=freeze` and `pip list --format=json`

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

## Test Plan

Extended existing `pip list` tests to match output.
Need to look at escaping in the Windows test 🪟
2024-03-06 01:46:13 +00:00
konsti
df06069922
Include exit code for build failures (#2108)
`uv pip install mysqlclient==2.1.1` on python 3.12 on windows, where the
are no binary wheels:

![grafik](31f6294a-d845-4c85-b663-82a82ae925a6)

Part of #2052.
2024-03-06 01:05:50 +00:00
Charlie Marsh
65518c9c58
Escape Windows paths with spaces in venv activation command (#2223)
## Summary

Ensure that we print `& "foo bar\Scripts\activate"` if necessary.
2024-03-05 18:11:41 -05:00
Charlie Marsh
9f1bb4dee2
Show appropriate activation command based on shell detection (#2221)
## Summary

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

## Test Plan

On Nushell:

```
(uv) ~/workspace/uv> cargo run venv                                                                                                                                                                                      
Using Python 3.12.0 interpreter at: /Users/crmarsh/workspace/uv/.venv/bin/python3
Creating virtualenv at: .venv
Activate with: overlay use .venv/bin/activate.nu
```

On Bash:

```
❯ cargo run venv "foo bar"
Using Python 3.12.0 interpreter at: /Users/crmarsh/.local/share/rtx/installs/python/3.12.0/bin/python3
Creating virtualenv at: foo bar
Activate with: source 'foo bar/bin/activate'
```
2024-03-05 17:28:17 -05:00
Charlie Marsh
9e41f73e41
Respect non-sysconfig-based system Pythons (#2193)
## Summary

`pip` uses `sysconfig` for Python 3.10 and later by default; however, it
falls back to `distutils` for earlier Python versions, and distros can
actually tell `pip` to continue falling back to `distutils` via the
`_PIP_USE_SYSCONFIG` variable.

By _always_ using `sysconfig`, we're doing the wrong then when
installing into some system Pythons, e.g., on Debian prior to Python
3.10.

This PR modifies our logic to mirror `pip` exactly, which is what's been
recommended to me as the right thing to do.

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

## Test Plan

Most notably, the new Debian tests pass here (which fail on main:
https://github.com/astral-sh/uv/pull/2144).

I also added Pyston as a second stress-test.
2024-03-05 21:23:35 +00:00
Charlie Marsh
0f6fc117c1
Query interpreter to determine correct virtualenv paths (#2188)
## Summary

This PR migrates our virtualenv creation from a setup that assumes prior
knowledge of the correct paths, to a technique borrowed from
`virtualenv` whereby we use `sysconfig` and `distutils` to determine the
paths. The general trick is to grab the expected paths with `sysconfig`,
then make them all relative, then make them absolute for a given
directory.

Closes #2095.
Closes #2153.
2024-03-05 16:13:24 -05:00
Charlie Marsh
a8ac7b1eb4
Pin maturin version in CI for now (#2219)
## Summary

In v1.5.0, Maturin now produces Metadata 2.3.0, which isn't supported in
the GitHub Action:
https://github.com/pypa/gh-action-pypi-publish/pull/219.
2024-03-05 15:49:07 -05:00
Charlie Marsh
043d72646d
Bump version to v0.1.15 (#2217) 2024-03-05 14:47:10 -05:00
Charlie Marsh
34acfe4ac6
Respect py --list-paths fallback in --python python3 invocations (#2214)
## Summary

This makes `--python python3` and `--python 3.10` more consistent on
Windows.

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

## Test Plan

Ran `cargo run venv --python python3.12` with the Windows Store Python.
2024-03-05 19:28:24 +00:00
Charlie Marsh
aeb80e345b
HTML-decode URLs in HTML indexes (#2215)
## Summary

If the index lists a URL like
`https://buf.build/gen/python/hashb-foxglove-protocolbuffers-python/hashb_foxglove_protocolbuffers_python-25.3.0.1.20240226043130+465630478360-py3-none-any.whl`,
we need to decode that to
`https://buf.build/gen/python/hashb-foxglove-protocolbuffers-python/hashb_foxglove_protocolbuffers_python-25.3.0.1.20240226043130+465630478360-py3-none-any.whl`.

Closes https://github.com/astral-sh/uv/issues/2202.
2024-03-05 19:26:54 +00:00
Charlie Marsh
01ebaef4e7
Avoid Windows Store shims in --python python3-like invocations (#2212)
## Summary

We have logic in `python_query.rs` to filter out Windows Store shims
when you use invocations like `-p 3.10`, but not `--python python3`,
which is uncommon but allowed on Windows.

Closes #2211.
2024-03-05 13:47:38 -05:00
Charlie Marsh
cf94df7cb9
Expand Windows shim detection to include python3.12.exe (#2209)
## Summary

Our Windows shim detection wasn't catching shims like `python3.12.exe`.

Closes #2208.

## Test Plan

Installed Python 3.12 via the Windows Store; verified that `cargo run
venv --python 3.12` failed before but passes after this change.
2024-03-05 13:25:05 -05:00
Charlie Marsh
8620b5a52f
Make direct dependency detection respect markers (#2207)
## Summary

When determining "direct" dependencies, we need to ensure that we
respect markers. In the linked issue, the user had an optional
dependency like:

```toml
[project.optional-dependencies]
dev = [
  "setuptools>=64",
  "setuptools_scm>=8"
]
```

By not respecting markers, we tried to resolve `setuptools` to the
lowest-available version. However, since `setuptools>=64` _isn't_
enabled (since it's optional), we won't respect _that_ constraint.

To be consistent, we need to omit optional dependencies just as we will
at resolution time.

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

## Test Plan

`cargo test`
2024-03-05 17:25:06 +00:00
Charlie Marsh
7f07ada24c
Allow direct URLs in optional dependencies in editables (#2206)
See the additional test, which fails on `main`.
2024-03-05 11:57:55 -05:00
Charlie Marsh
fc55cb9a3c
Respect nested editable requirements in parser (#2204)
Closes https://github.com/astral-sh/uv/issues/2198.
2024-03-05 16:47:37 +00:00
konsti
0924185a7f
Only use compile timeout for critical section (#2199)
Follow-up to #2086: Don't use timeouts for the entire workers, but only
for the section that's about communicating with the (potentially broken)
`python` subprocess. I've also raised the timeout to 60s.
2024-03-05 17:20:04 +01:00
Charlie Marsh
0bc047866d
Error when editables don't match Requires-Python (#2194)
## Summary

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

## Test Plan

(Needs tests.)
2024-03-04 23:20:42 -05:00
konsti
2a53e789b0
Add an option to bytecode compile during installation (#2086)
Add a `--compile` option to `pip install` and `pip sync`.

I chose to implement this as a separate pass over the entire venv. If we
wanted to compile during installation, we'd have to make sure that
writing is exclusive, to avoid concurrent processes writing broken
`.pyc` files. Additionally, this ensures that the entire site-packages
are bytecode compiled, even if there are packages that aren't from this
`uv` invocation. The disadvantage is that we do not update RECORD and
rely on this comment from [PEP 491](https://peps.python.org/pep-0491/):

> Uninstallers should be smart enough to remove .pyc even if it is not
mentioned in RECORD.

If this is a problem we can change it to run during installation and
write RECORD entries.

Internally, this is implemented as an async work-stealing subprocess
worker pool. The producer is a directory traversal over site-packages,
sending each `.py` file to a bounded async FIFO queue/channel. Each
worker has a long-running python process. It pops the queue to get a
single path (or exists if the channel is closed), then sends it to
stdin, waits until it's informed that the compilation is done through a
line on stdout, and repeat. This is fast, e.g. installing `jupyter
plotly` on Python 3.12 it processes 15876 files in 319ms with 32 threads
(vs. 3.8s with a single core). The python processes internally calls
`compileall.compile_file`, the same as pip.

Like pip, we ignore and silence all compilation errors
(https://github.com/astral-sh/uv/issues/1559). There is a 10s timeout to
handle the case when the workers got stuck. For the reviewers, please
check if i missed any spots where we could deadlock, this is the hardest
part of this PR.

I've added `uv-dev compile <dir>` and `uv-dev clear-compile <dir>`
commands, mainly for my own benchmarking. I don't want to expose them in
`uv`, they almost certainly not the correct workflow and we don't want
to support them.

Fixes #1788
Closes #1559
Closes #1928
2024-03-05 03:35:24 +00:00
Charlie Marsh
93b1395daa
Fallback to non-range requests when HEAD returns 404 (#2186)
## Summary

We have at least one reported case of this happening. It's preferable
IMO to move on rather than fail hard despite sub-pbar registry behavior.

Closes https://github.com/astral-sh/uv/issues/2099.
2024-03-04 22:18:49 -05:00
Charlie Marsh
60a78812f9
Extend system-install.yml to include virtualenv operations (#2190)
Just basic stuff like: we can create a virtualenv, we can install into
it (and not affect the system Python).
2024-03-05 01:46:00 +00:00
Charlie Marsh
7e1f361bb3
Add system install test for PyPy (#2189) 2024-03-04 19:44:18 -05:00
Charlie Marsh
a3c24e7bea
Add system install test for choco (#2185)
Test installing Python via `choco`.
2024-03-04 19:37:07 -05:00
dependabot[bot]
e66afa8767
Bump insta from 1.35.1 to 1.36.1 (#2180) 2024-03-04 23:01:49 +00:00
dependabot[bot]
bc43f609b9
Bump http from 0.2.11 to 0.2.12 (#2179) 2024-03-04 22:22:45 +00:00
dependabot[bot]
5aedcffdf0
Bump log from 0.4.20 to 0.4.21 (#2178) 2024-03-04 16:16:20 -06:00
dependabot[bot]
9fcffae084
Bump anstream from 0.6.12 to 0.6.13 (#2177) 2024-03-04 16:16:10 -06:00
Charlie Marsh
fbe043b093
Respect markers on URL dependencies in editables (#2176)
Closes https://github.com/astral-sh/uv/issues/2172.
2024-03-04 22:09:08 +00:00
Charlie Marsh
70143b8626
Run Windows against Python 3.13 (#2171)
## Summary

In Python 3.13, at least in the current builds, there's no `python.exe`,
but there is `venvlauncher.exe`.

I've asked here about whether it's intended:
https://discuss.python.org/t/when-should-venv-scripts-nt-python-exe-be-present/47620.
But there's at least some evidence in CPython
[here](d457345bbc/Lib/venv/__init__.py (L270))
that we should fall back to these, and the tests pass.

Closes https://github.com/astral-sh/uv/issues/1636.
2024-03-04 21:49:17 +00:00
Charlie Marsh
14d968ac22
Set .metadata suffix on URL path (#2123)
## Summary

Ensures that we don't add the `.metadata` suffix after the fragment, if
it exists.
2024-03-04 20:51:07 +00:00
Charlie Marsh
5fed1f6259
Use simpler pip-like Scheme for install paths (#2173)
## Summary

This will make it easier to use the paths returned by `distutils.py`
(for some cases). No code or behavior changes; just removing some fields
we don't need.
2024-03-04 15:50:13 -05:00
samypr100
93f5609476
feat: add uv version to user agent (#2136)
## Summary

Closes #1977

This allows us to send uv's version in the `uv-client` User Agent
header.

Here's how request headers look like to a server now:
```
...
Accept: application/vnd.pypi.simple.v1+json, application/vnd.pypi.simple.v1+html;q=0.2, text/html;q=0.01
User-Agent: uv/0.1.13
...
```

~~I went for a mix of Option 1 and 2 from #1977.~~ Open to alternative
naming as well, not tied too strongly here to the names picked.

~~Another possibility for this new crate is that we can use it to
consolidate metadata that exists across crates to ultimately be able to
create linehaul information described in #1958, but I haven't looked
into what those changes might look like.~~

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

## Test Plan

<!-- How was it tested? -->
Added initial tests in the new crate to exercise its public API and
added a new test to uv-client to validate the headers using a 1-time
disposable server.
2024-03-04 19:48:41 +00:00
Charlie Marsh
fda691401a
Respect local freshness when auditing installed environment (#2169)
## Summary

Ensures that local dependencies function similarly to editables, in that
if they're `uv pip install`ed, we invalidate them.

Closes https://github.com/astral-sh/uv/issues/1651.
2024-03-04 19:40:52 +00:00
Charlie Marsh
8c51b59298
Allow empty values in WHEEL files (#2170)
## Summary

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

## Test Plan

`cargo run pip install "openturns==1.22"`
2024-03-04 19:39:01 +00:00
Charlie Marsh
6f94dc3c77
Centralize up-to-date checking for path installations (#2168)
## Summary

Internal-only refactor to consolidate multiple codepaths we have for
checking whether a cached or installed entry is up-to-date with a local
requirement.
2024-03-04 14:10:51 -05:00
Zanie Blue
ffb69e3f48
Expose the --exclude-newer flag (#2166)
Closes https://github.com/astral-sh/uv/issues/2088
2024-03-04 17:51:19 +00:00
Charlie Marsh
c525fdf2b5
Bump version to v0.1.14 (#2157) 2024-03-04 15:42:33 +00:00
konsti
898c3f6bcf
Better offline error message (#2110)
Error for `uv pip compile scripts/requirements/jupyter.in` without
internet:

**Before**

```
error: error sending request for url (https://pypi.org/simple/jupyter/): error trying to connect: dns error: failed to lookup address information: No such host is known. (os error 11001)
  Caused by: error trying to connect: dns error: failed to lookup address information: No such host is known. (os error 11001)
  Caused by: dns error: failed to lookup address information: No such host is known. (os error 11001)
  Caused by: failed to lookup address information:  No such host is known. (os error 11001)
```

**After**

```
error: Could not connect, are you offline?
  Caused by: error sending request for url (https://pypi.org/simple/django/): error trying to connect: dns error: failed to lookup address information: Temporary failure in name resolution
  Caused by: error trying to connect: dns error: failed to lookup address information: Temporary failure in name resolution
  Caused by: dns error: failed to lookup address information: Temporary failure in name resolution
  Caused by: failed to lookup address information: Temporary failure in name resolution
```

On linux, it would be "Temporary failure in name resolution" instead of
"No such host is known. (os error 11001)".

The implementation checks for "dne error" stringly as hyper errors are
opaque. The danger is that this breaks with a hyper update. We still get
the complete error trace since reqwest eagerly inlines errors
(https://github.com/seanmonstar/reqwest/issues/2147).

No test since i wouldn't know how to simulate this in cargo test.

Fixes #1971
2024-03-04 15:47:40 +01:00