Commit graph

1488 commits

Author SHA1 Message Date
Ibraheem Ahmed
fa53de9223
Avoid Removing Quotes From Requirement Markers (#3214)
## Summary

Avoid removing quotes from markers, e.g. `numpy (>=1.19) ;
python_version >= "3.7"` should not be rewritten. Fixes
https://github.com/astral-sh/uv/issues/2551.

This PR also makes fixups a bit more flexible internally for fixes that
aren't simple to implement with a pure regex replacement, like this one.
https://github.com/astral-sh/uv/pull/1529 fixed a similar problem but
the current regex is still not smart enough to avoid all markers
completely (like `python_version`).

## Test Plan

Added a few unit tests.
2024-04-23 14:07:51 -04:00
konsti
70ee3b7cd2
An enum and backticks for lookahead error (#3216)
Mostly a small refactor, adds backticks to be coherent with #3004.
2024-04-23 17:28:10 +00:00
konsti
4a49ff4372
Rename ancillary direct url types to parsed url (#3211)
Followup to #3187. Renaming only
2024-04-23 14:51:23 +00:00
Zanie Blue
645d0399fd
Bump version to 0.1.37 (#3208) 2024-04-23 14:35:27 +00:00
Zanie Blue
b8302d44de
Improve tracing for keyring provider (#3207) 2024-04-23 09:23:21 -05:00
Zanie Blue
598a67cf31
Fix fetch of credentials when cache is seeded with username (#3206)
Fixes the failure to lookup credentials in
https://github.com/astral-sh/uv/issues/3205

The issue is that we seed the cache with the index URL which includes a
username but no password. We did not ensure that a password was present
in the cached credentials before attempting a request with them. Now,
the cache will not return credentials when a username is provided and
the cached credentials have no password — the cached credentials are
useless in that case.

Tested with a Google Artifact Registry and keyring

```
RUST_LOG=uv=trace cargo run -q -- pip install requests --index-url https://oauth2accesstoken@us-central1-python.pkg.dev/<project>/pypi/simple/ --no-cache --keyring-provider subprocess -v
```
2024-04-23 09:02:29 -05:00
哇呜哇呜呀咦耶
65efaf70da
Make KeyringProvider::fetch_* async (#3089)
To resolve #3073
2024-04-23 07:58:00 -05:00
Charlie Marsh
ad923b71a7
Improve --python-platform documentation (#3202)
See:
https://github.com/astral-sh/uv/pull/3154#pullrequestreview-2016083883
2024-04-23 02:42:30 +00:00
renovate[bot]
054fa3e439
Update Rust crate zip to v1 (#3175) 2024-04-22 22:17:44 -04:00
Charlie Marsh
14f05f27b3
Add ticks around error messages more consistently (#3004)
## Summary

I found some of these too bare (e.g., when they _just_ show a package
name with no other information). For me, this makes it easier to
differentiate error message copy from data. But open to other opinions.
Take a look at the fixture changes and LMK!
2024-04-22 23:58:36 +00:00
Charlie Marsh
8536e63438
Add --python-platform to sync and install commands (#3154)
## Summary

pip supports providing a `--platform` to `pip install`, which can be
used to seed an environment (e.g., for use in a container or otherwise).
This PR adds `--python-platform` to our commands to support a similar
workflow. It has some caveats, which are documented on the CLI.

Closes #2079.
2024-04-22 19:31:55 -04:00
konsti
d10903f0a4
30s default http read timeout (#3182)
Since we're now using read timeouts and not total timeouts, we can use a
lower threshold, a single read shouldn't take 5 min (and not even 10s).

The 10s value is somewhat arbitrary.

Like #3144, this is a breaking change in some sense.
2024-04-22 19:05:44 -04:00
Zanie Blue
b9419e67aa
Add preview mode and use for warning in uv run (#3192)
Adds hidden `--preview` / `--no-preview` flags with `UV_PREVIEW`
environment variable support. Copies the `PreviewMode` type from Ruff.

Does a little bit of extra work to port `uv run` to the new settings
model.

Note we allow `uv run` invocations without preview and only use its
presence to toggle an experimental warning.

## Test plan

```
❯ cargo run -q -- run --no-workspace -- python --version
warning: `uv run` is experimental and may change without warning.
Python 3.12.2
❯ cargo run -q -- run --no-workspace --preview -- python --version
Python 3.12.2
❯ UV_PREVIEW=1 cargo run -q -- run --no-workspace -- python --version
Python 3.12.2
```
2024-04-22 15:41:15 -05:00
Zanie Blue
78cd9991d7
Bump version to 0.1.36 (#3193) 2024-04-22 13:55:55 -05:00
renovate[bot]
04eaee7e19
Update Rust crate pyo3 to 0.21.0 (#2911) 2024-04-22 18:27:22 +00:00
Zanie Blue
f98eca8843
Fix authentication for URLs with a shared realm (#3130)
In #2976 I made some changes that led to regressions:

- We stopped tracking URLs that we had not seen credentials for in the
cache
- This means the cache no longer returns a value to indicate we've seen
a realm before
- We stopped seeding the cache with URLs 
- Combined with the above, this means we no longer had a list of
locations that we would never attempt to fetch credentials for
- We added caching of credentials found on requests
- Previously the cache was only populated from the seed or credentials
found in the netrc or keyring
- This meant that the cache was populated for locations that we
previously did not cache, i.e. GitHub artifacts(?)

Unfortunately this unveiled problems with the granularity of our cache.
We cache credentials per realm (roughly the hostname) but some realms
have mixed authentication modes i.e. different credentials per URL or
URLs that do not require credentials. Applying credentials to a URL that
does not require it can lead to a failed request, as seen in #3123 where
GitHub throws a 401 when receiving credentials.

To resolve this, the cache is expanded to supporting caching at two
levels:

- URL, cached URL must be a prefix of the request URL
- Realm, exact match required

When we don't have URL-level credentials cached, we attempt the request
without authentication first. On failure, we'll search for realm-level
credentials or fetch credentials from external services. This avoids
providing credentials to new URLs unless we know we need them.

Closes https://github.com/astral-sh/uv/issues/3123
2024-04-22 13:06:57 -05:00
Charlie Marsh
41b29b2dc4
Add support for embedded Python on Windows (#3161)
## Summary

References:
-
cad550030a/src/virtualenv/create/via_global_ref/builtin/cpython/cpython3.py (L58-L68)
- https://github.com/pypa/virtualenv/pull/2353
- https://github.com/pypa/virtualenv/issues/2368

Closes https://github.com/astral-sh/uv/issues/1656.
2024-04-22 13:34:27 -04:00
Charlie Marsh
792a917a97
Restrict observed requirements to direct when --no-deps is specified (#3191)
## Summary

This PR avoids: (1) using the lookahead resolver when `--no-deps` is
specified (we'll never use those requirements), and (2) including any
transitive requirements when searching for allowed URLs, etc., when
`--no-deps` is specified.

Closes https://github.com/astral-sh/uv/issues/3183.
2024-04-22 17:17:58 +00:00
Charlie Marsh
a4f125ca34
Avoid waiting for metadata for --no-deps editables (#3188)
## Summary

We don't emit a request for this, so we shouldn't wait for it either --
we already have the metadata!

Closes https://github.com/astral-sh/uv/issues/3184.
2024-04-22 16:29:19 +00:00
konsti
725004dcf1
Rename the second direct url to parsed url (#3187)
Previously, we got `pypi_types::DirectUrl` (the pypa spec
direct_url.json format) and `distribution_types::DirectUrl` (an enum of
all the url types we support). This lead me to confusion, so i'm
renaming the latter one to the more appropriate `ParsedUrl`.
2024-04-22 14:38:27 +00:00
konsti
82c4772e89
Move unnamed requirements to their own pep508_rs module and requirements-txt (#3186)
Another refactoring in preparation of using a richer requirements type.
No functional changes, only moves code around
2024-04-22 14:02:39 +00:00
konsti
f29c991e21
Dedicated error type for direct url parsing (#3181)
Add a dedicated error type for direct url parsing. This change is broken
out from the new uv requirement type, which uses direct url parsing
internally.
2024-04-22 11:57:36 +00:00
Grzegorz Bokota
7efd13ca33
Add UV_CONSTRAINT environment variable to provide value for --constraint (#3162)
## Summary

This PR is adding `UV_CONSTRAINT` environment variable as analogous to
`PIP_CONSTRAINT` to allow providing constraint file via environment
variable. Implementing this will simplify adoption of uv in testing
procedure in projects that I'm involved (testing using tox).

This was my motivation for opening #1841 that is closed in favor of
#1789 which was closed without implementing this feature.

In this implementation, I have used space as a separator as analogous to
`pip`. This introduces an obvious problem if the path contains space.
Another option could be to use standard separator (`:` - UNIX like, `;`
- Windows). Which one did you prefer?

## Test Plan

It is my first contribution and first rust coding experience. It will be
nice if one could point how I should implement testing this.
2024-04-20 17:32:28 -04:00
Charlie Marsh
bf1036832f
Fix venvlauncher.exe reference in venv creation (#3160)
I can't get this to reproduce on GitHub Actions -- maybe the builds
there differ, or maybe the builds changed since we added this fix? I'll
check locally, but regardless, this is a typo.

Closes #3158.
2024-04-20 14:16:47 +00:00
Charlie Marsh
b4ee7d7359
Bump version to v0.1.35 (#3153) 2024-04-19 19:58:15 -04:00
Charlie Marsh
4a98839c1d
Move argument normalization into settings construction (#3103)
## Summary

No behavior changes, but the idea here is that we move the argument
normalization code (e.g., create an `Upgrade` struct from `--upgrade`
and `--upgrade-package`) into the `settings.rs` file, where we build the
common settings structs.

This reduces a lot of the logic and duplication across commands in
`main.rs`.
2024-04-19 23:45:08 +00:00
Charlie Marsh
fda378fd29
Avoid preferring constrained over unconstrained packages (#3148)
## Summary

pip prefers somewhat-constrained over unconstrained packages... but only
if they're at equal depths in the tree. We don't have a way to track the
latter property yet (I've added a TODO), so for now, we should remove
this constraint -- it seems to be counter-productive.

I've filed https://github.com/astral-sh/uv/issues/3149 as a follow-up.

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

## Test Plan

- `git clone https://github.com/drivendataorg/zamba.git`
- `cat "-e .[tests]" > req.in`
- `cargo run venv && cargo run pip compile req.in --refresh -n
--python-platform linux --python-version 3.8`
2024-04-19 23:30:08 +00:00
Charlie Marsh
70b6bde254
Add --python-platform to configuration (#3147)
## Summary

Just for consistency with `--python-version`.
2024-04-19 23:08:03 +00:00
Charlie Marsh
5e4e2fa0bf
Rename --platform to --python-platform (#3146)
## Summary

`--platform` is a flag that exists in `pip` and it has a different
meaning. (Not breaking as this hasn't been released yet anyway.)
2024-04-19 22:24:23 +00:00
Zanie Blue
4046b2bcfa
Allow uv run to execute Python scripts directly (#3110)
e.g. `uv run foo.py` implies `python foo.py`

Future work includes #3096
2024-04-19 21:29:57 +00:00
Zanie Blue
91e32fec6f
Bump astral-test commit snapshots (#3145)
I added distributions to these projects so the commit changed.

We could pin but we want to test for resolution... so we don't. These
are pretty static so this should be rare.
2024-04-19 21:20:34 +00:00
Charlie Marsh
9f2bc19eaf
Enforce HTTP timeouts on a per-read (rather than per-request) basis (#3144)
## Summary

This leverages the new `read_timeout` property, which ensures that (like
pip) our timeout is not applied to the _entire_ request, but rather, to
each individual read operation.

Closes: #1921.

See: #1912.
2024-04-19 16:49:53 -04:00
Zanie Blue
31765c05bd
Default to python when uv run does not recieve a command (#3109)
This means that a bare `uv run` invocation drops you into a REPL.

This behavior is internally controversial, and may best be served by a
dedicated `uv repl` command. I would imagine it's important to fail if
no command is given in _some_ circumstances, but those may be resolved
by _not_ doing this if we do not detect a TTY.

Regardless, I'm interested in giving this a try for a bit during this
experimental phase.
2024-04-19 15:15:38 +00:00
Zanie Blue
9bcc1943cc
Allow workspace requirements to be ignored during uv run (#3108) 2024-04-19 14:52:04 +00:00
Zanie Blue
01a7b7a088
Read base requirements from pyproject.toml in uv run (#3101)
In addition to the requested requirements, we include requirements from
a `pyproject.toml` file if it exists and install the current directory.

Closes https://github.com/astral-sh/uv/issues/3104
2024-04-19 14:36:03 +00:00
Zanie Blue
becb12642a
Add uv run --with <pkg> to run a command with ephemeral requirements (#3077)
Holy cow does installation / resolution take a ton of options. We
side-step most of them here.

If the current environment satisfies the requirements, it is used.
Otherwise, we create a new environment with the requested dependencies.
2024-04-19 09:23:26 -05:00
Jack Cherng
7a163ba9f1
Fix uv pip compile with UV_SYSTEM_PYTHON=1 (#3136)
## Summary

Following up 

- https://github.com/astral-sh/uv/pull/3113
- https://github.com/astral-sh/uv/pull/3115

It looks like `uv pip compile` command with `UV_SYSTEM_PYTHON` is missed
because these two PRs are close in time. And thus resulting in


```bash
$ uv --version
uv 0.1.34 (9259eceeb 2024-04-19)
$ UV_SYSTEM_PYTHON=1 uv pip compile --upgrade requirements.in -o requirements.txt
error: invalid value '1' for '--system'
  [possible values: true, false]

For more information, try '--help'.
```

Signed-off-by: Jack Cherng <jfcherng@gmail.com>
2024-04-19 08:48:55 -04:00
Charlie Marsh
93559d5c2a
Add a --platform argument to enable resolving against a target platform (#3111)
## Summary

I've wanted to try this for a long time, so decided to give it a shot.
The basic idea is that you can provide a target triple (e.g.,
`--platform x86_64-pc-windows-msvc`) and resolve against that platform,
rather than the currently-running platform. It's functionally similar to
`--python-version`, though a bit simpler since there's no need to engage
with `Requires-Python`.

Our infrastructure is well-setup for this and so, in the end, it's
actually pretty straightforward: for each triple, we just need to
override the markers and platform tags.
2024-04-18 22:57:41 -04:00
Charlie Marsh
9259eceebc
Bump version to v0.1.34 (#3134) 2024-04-19 02:15:04 +00:00
Charlie Marsh
a241bc79b1
Add priorities for editables (#3133)
## Summary

We weren't setting a priority for editables, so they were being visited
last.

I think there's still a problem whereby we're not aggressive enough in
visiting recursive extras (and, in fact, that's making it really hard to
write a test -- I wrote a test, but the most-reduced case still fails,
and I'd need to add a layer of indirection to make it
fail-on-main-but-pass-on-this-branch), but that problem likely already
existed on main prior to #3087, so I just want to get this quick fix out
now.

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

## Test Plan

- `git clone https://github.com/cda-tum/mqt-core.git`
- `cargo run venv`
- `cargo run pip install 'scikit-build-core[pyproject]>=0.8.1'
'setuptools_scm>=7' 'pybind11>=2.12' --resolution=lowest-direct`
- `cargo run pip install --no-build-isolation
'-ve.[test,qiskit,evaluation,coverage]' --resolution=lowest-direct`
2024-04-19 02:04:58 +00:00
Charlie Marsh
2e88bb6f1b
Add a proxy layer for extras (#3100)
Given requirements like:

```
black==23.1.0
black[colorama]
```

The resolver will (on `main`) add a dependency on Black, and then try to
use the most recent version of Black to satisfy `black[colorama]`. For
sake of example, assume `black==24.0.0` is the most recent version. Once
the selects this most recent version, it'll fetch the metadata, then
return the dependencies for `black==24.0.0` with the `colorama` extra
enabled. Finally, it will tack on `black==24.0.0` (a dependency on the
base package). The resolver will then detect a conflict between
`black==23.1.0` and `black==24.0.0`, and throw out
`black[colorama]==24.0.0`, trying to next most-recent version.

This is both wasteful and can cause problems, since we're fetching
metadata for versions that will _never_ satisfy the resolver. In the
`apache-airflow[all]` case, I also ran into an issue whereby we were
attempting to build very old versions of `apache-airflow` due to
`apache-airflow[pandas]`, which in turn led to resolution failures.

The solution proposed here is that we create a new proxy package with
exactly two dependencies: one on `black` and one of `black[colorama]`.
Both of these packages must be at the same version as the proxy package,
so the resolver knows much _earlier_ that (in the above example) the
extra variant _must_ match `23.1.0`.
2024-04-19 01:04:59 +00:00
Zanie Blue
822ae19879
Restore seeding of authentication cache from index URLs (#3124)
Roughly reverts
f7820ceaa7
to reduce possible race conditions for pre-authenticated index URLs

Part of:

- https://github.com/astral-sh/uv/issues/3123
- https://github.com/astral-sh/uv/issues/3122
2024-04-18 19:48:21 -05:00
Charlie Marsh
5ca5d7da67
Add test for avoiding irrelevant extras (#3107)
## Summary

This PR adds a test that currently leads to an error, but should
successfully resolve as of https://github.com/astral-sh/uv/pull/3100.

The core idea is that if we have a pinned package, we shouldn't try to
build other versions of that package if we have an unconstrained variant
with an extra.
2024-04-19 00:47:27 +00:00
Charlie Marsh
3c9d925531
Avoid treating localhost URLs as local file paths (#3132)
## Summary

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

## Test Plan

- `python -m http.server`
- `cargo run pip install
"http://localhost:8000/werkzeug-3.0.2-py3-none-any.whl"`
- `cargo run pip install
"http://localhost:8000/werkzeug-3.0.2-py3-none-any.whl"`
2024-04-19 00:37:33 +00:00
Charlie Marsh
0ce039d1f9
Remove Option<bool> for --no-cache (#3129)
## Summary

This was unintended. We ended up reverting `Option<bool>` everywhere,
but I missed this once since it's in a separate file.

(If you use `Option<bool>`, Clap requires a value, like `--no-cache
true`.)

## Test Plan

`cargo run pip install flask --no-cache`
2024-04-18 22:56:46 +00:00
Charlie Marsh
822e3dc0c5
Add UV_REQUIRE_HASHES environment variable (#3125)
Closes https://github.com/astral-sh/uv/issues/3117.
2024-04-18 21:07:08 +00:00
konsti
c9eefc0833
Reset default -v level to debug (#3120)
Fixup from
https://github.com/astral-sh/uv/pull/2815/files#diff-9b6f8f13cfc3c9d7ef554182fa52c7466fa6037da54a97c03855b6068b481848L127-R127
2024-04-18 13:34:04 +00:00
Charlie Marsh
7688f464c8
Allow --python and --system on pip compile (#3115)
## Summary

I think these are useful to have for consistency, though the `--system`
variant requires some new threading.

Closes: https://github.com/astral-sh/uv/issues/2242.
2024-04-18 04:55:49 +00:00
Charlie Marsh
37aefbd199
Use BoolishValueParser for boolean environment variables (#3113)
## Summary

Right now, we only accept _exactly `UV_NATIVE_TLS=true` and
`UV_NATIVE_TLS=false`. `BoolishValueParser` accepts a wider range of
values:

```rust
/// True values are `y`, `yes`, `t`, `true`, `on`, and `1`.
pub(crate) const TRUE_LITERALS: [&str; 6] = ["y", "yes", "t", "true", "on", "1"];

/// False values are `n`, `no`, `f`, `false`, `off`, and `0`.
pub(crate) const FALSE_LITERALS: [&str; 6] = ["n", "no", "f", "false", "off", "0"];
```

I tend to use `0` and `1` personally so this surprised me.
2024-04-18 00:37:38 -04:00
Chan Kang
8c7d0a31e6
Hide password in the index printed via --emit-index-annotation (#3112)
## Summary

resolves https://github.com/astral-sh/uv/issues/3106

## Test Plan

added a simple test where the password provided in `UV_INDEX_URL` is
hidden in the output as expected.
2024-04-18 03:59:44 +00:00