Commit graph

286 commits

Author SHA1 Message Date
Charlie Marsh
8a0e1fde33
Write trailing newline to .python-version files (#7140)
## Summary

Closes https://github.com/astral-sh/uv/issues/7135.
2024-09-06 18:03:52 -04:00
Charlie Marsh
50d7b9c38a
Pin .python-version in uv init (#6869)
## Summary

I'm not convinced that the behavior is correct as-implemented. When the
user passes a `--python >=3.8` or we discover a `requires-python` from
the workspace, we're currently writing that request out to
`.python-version`. I would probably rather that we write the resolved
patch version?

Closes https://github.com/astral-sh/uv/issues/6821.
2024-09-03 19:43:50 -04:00
eth3lbert
ad82b94856
Support file:// URLs for UV_PYTHON_INSTALL_MIRROR (#6950)
## Summary

Closes #6319.

## Test Plan

I tested with `file:///mirror`, `file://localhost/mirror`, and
`http://mirror` to confirm that it was working as expected.

``` shell-session
/private/tmp/mirror-local                                                                                                                                                                      07:08:18
:)  tree mirror 
mirror/
└── 20240814/
   └── cpython-3.12.5+20240814-aarch64-apple-darwin-install_only_stripped.tar.gz
```

<img width="626" alt="image"
src="https://github.com/user-attachments/assets/9c04224d-305c-47ee-a524-4a6abeb79da4">
2024-09-03 01:20:01 +00:00
Ed Morley
a5f1e1c765
Fix typos in docs, error messages and comments (#6910) 2024-09-01 11:37:43 +00:00
Charlie Marsh
95416ad52e
Take unowned request in PythonInstallation::find_or_download (#6868) 2024-08-30 13:49:17 +00:00
konsti
9814852295
Discover Microsoft Store Pythons (#6807)
Microsoft Store Pythons do not always register themselves in the
registry, so we port
<58ce131037/PC/launcher2.c (L1744)>
and look them up on the filesystem in known locations.

## Test Plan

So far I've confirmed that we find a store Python when I use `cargo run
python list`, can we make this a part of any of the platform tests
maybe?
2024-08-29 20:56:41 +00:00
konsti
a39eb61ade
Use windows registry to discover python (#6761)
Our current strategy of parsing the output of `py --list-paths` to get
the installed python versions on windows is brittle (#6524, missing
`py`, etc.) and it's slow (10ms last time i measured).

Instead, we should behave spec-compliant and read the python versions
from the registry following PEP 514.

It's not fully clear which errors we should ignore and which ones we
need to raise.

We're using the official rust-for-windows crates for accessing the
registry.

Fixes #1521
Fixes #6524
2024-08-29 22:48:22 +02:00
Zanie Blue
a17c1e8e40
Add test coverage for Python version discovery with prereleases (#6823)
Coverage for https://github.com/astral-sh/uv/pull/6813 — reverting that
commit causes the 3.11.0b0 test case to fail.
2024-08-29 13:29:22 -05:00
Charlie Marsh
f046e54c64
Ignore pre-release segments when discovering via requires-python (#6813)
## Summary

`3.13.0b0` should be allowed by `>=3.13`.

Closes #6798.
2024-08-29 11:45:29 -05:00
Zanie Blue
e3d5d3d26d
Avoid deadlocks when multiple uv processes lock resources (#6790)
This is achieved by updating the `LockedFile::acquire` API to be async —
as in some cases we were attempting to acquire the lock synchronously,
i.e., without yielding, which blocked the runtime.

Closes https://github.com/astral-sh/uv/issues/6691 — I tested with the
reproduction there and a local release build and no longer reproduce the
deadlock with these changes.

Some additional context in the [internal Discord
thread](1278478941)
2024-08-29 11:16:14 -05:00
github-actions[bot]
3be4fe59d7
Sync latest Python releases (#6784) 2024-08-29 03:41:07 +00:00
renovate[bot]
1309f24c43
Update Rust crate windows-sys to 0.59.0 (#5785)
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [windows-sys](https://togithub.com/microsoft/windows-rs) |
workspace.dependencies | minor | `0.52.0` -> `0.59.0` |

---

### Release Notes

<details>
<summary>microsoft/windows-rs (windows-sys)</summary>

###
[`v0.59.0`](https://togithub.com/microsoft/windows-rs/releases/tag/0.59.0)

[Compare
Source](https://togithub.com/microsoft/windows-rs/compare/0.52.0...0.59.0)

This release includes an update to the
[windows-sys](https://crates.io/crates/windows-sys) crate only. The
`windows-sys` crate is updated very infrequently and only when there is
an explicit need to do so. The 0.59.0 release includes a rollup of API
fixes, updates, and additions since the
[0.52.0](https://togithub.com/microsoft/windows-rs/releases/tag/0.52.0)
release nine months ago. Notably:

- This update introduces support for Arm64EC
([#&#8203;2957](https://togithub.com/microsoft/windows-rs/issues/2957))
- Updated bindings for the latest APIs
https://github.com/microsoft/windows-rs/tree/0.59.0/crates/libs/bindgen/default
- Derive standard traits
([#&#8203;3041](https://togithub.com/microsoft/windows-rs/issues/3041))
-   Updates to code generation to handle newer Rust warnings and lints
- Overall smaller crate and more efficient code gen to reduce build time
- Support for feature search
https://microsoft.github.io/windows-rs/features/#/0.59.0
-   MSRV is updated to 1.60

**Full Changelog**:
https://github.com/microsoft/windows-rs/compare/0.52.0...0.59.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "before 4am on Monday" (UTC),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR was generated by [Mend Renovate](https://mend.io/renovate/).
View the [repository job
log](https://developer.mend.io/github/astral-sh/uv).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40NDAuNyIsInVwZGF0ZWRJblZlciI6IjM4LjU2LjAiLCJ0YXJnZXRCcmFuY2giOiJtYWluIiwibGFiZWxzIjpbImludGVybmFsIl19-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-08-28 08:43:59 -05:00
Charlie Marsh
d86075fc1e
Add support for --trusted-host (#6591)
## Summary

This PR revives https://github.com/astral-sh/uv/pull/4944, which I think
was a good start towards adding `--trusted-host`. Last night, I tried to
add `--trusted-host` with a custom verifier, but we had to vendor a lot
of `reqwest` code and I eventually hit some private APIs. I'm not
confident that I can implement it correctly with that mechanism, and
since this is security, correctness is the priority.

So, instead, we now use two clients and multiplex between them.

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

## Test Plan

Created self-signed certificate, and ran `python3 -m http.server --bind
127.0.0.1 4443 --directory . --certfile cert.pem --keyfile key.pem` from
the packse index directory.

Verified that `cargo run pip install
transitive-yanked-and-unyanked-dependency-a-0abad3b6 --index-url
https://127.0.0.1:8443/simple-html` failed with:

```
error: Request failed after 3 retries
  Caused by: error sending request for url (https://127.0.0.1:8443/simple-html/transitive-yanked-and-unyanked-dependency-a-0abad3b6/)
  Caused by: client error (Connect)
  Caused by: invalid peer certificate: Other(OtherError(CaUsedAsEndEntity))
```

Verified that `cargo run pip install
transitive-yanked-and-unyanked-dependency-a-0abad3b6 --index-url
'https://127.0.0.1:8443/simple-html' --trusted-host '127.0.0.1:8443'`
failed with the expected error (invalid resolution) and made valid
requests.

Verified that `cargo run pip install
transitive-yanked-and-unyanked-dependency-a-0abad3b6 --index-url
'https://127.0.0.1:8443/simple-html' --trusted-host '127.0.0.2' -n` also
failed.
2024-08-27 09:36:50 -04:00
konsti
ae57d85dfb
Detect musl and error for musl pbs builds (#6643)
As described in #4242, we're currently incorrectly downloading glibc
python-build-standalone on musl target, but we also can't fix this by
using musl python-build-standalone on musl targets since the musl builds
are effectively broken.

We reintroduce the libc detection previously removed in #2381, using it
to detect which libc is the current one before we have a python
interpreter. I changed the strategy a big to support an empty `PATH`
which we use in the tests.

For simplicity, i've decided to just filter out the musl
python-build-standalone archives from the list of available archive,
given this is temporary. This means we show the same error message as if
we don't have a build for the platform. We could also add a dedicated
error message for musl.

Fixes #4242

## Test Plan

Tested manually.

On my ubuntu host, python downloads continue to pass:
```
target/x86_64-unknown-linux-musl/debug/uv python install
```

On alpine, we fail:
```
$ docker run -it --rm -v .:/io alpine /io/target/x86_64-unknown-linux-musl/debug/uv python install
  Searching for Python installations
  error: No download found for request: cpython-any-linux-x86_64-musl
```
2024-08-27 00:06:53 +00:00
Charlie Marsh
a7850d2a1c
Use separate types to represent raw vs. resolver markers (#6646)
## Summary

This is similar to https://github.com/astral-sh/uv/pull/6171 but more
expansive... _Anywhere_ that we test requirements for platform
compatibility, we _need_ to respect the resolver-friendly markers. In
fixing the motivating issue (#6621), I also realized that we had a bunch
of bugs here around `pip install` with `--python-platform` and
`--python-version`, because we always performed our `satisfy` and `Plan`
operations on the interpreter's markers, not the adjusted markers!

Closes https://github.com/astral-sh/uv/issues/6621.
2024-08-26 18:00:21 +00:00
Shantanu
6220532373
Test for .venv symlink (#6597)
For various reasons, I have a preference for out of tree virtual
environments. Things just work if I symlink, but I don't know that this
is guaranteed, so I thought I'd add a test for it. It looks like there's
another code path that matters (`FoundInterpreter::discover ->
PythonEnvironment::from_root`) for the higher level commands, but
couldn't spot a good place to test that.

Related discussion:
https://github.com/astral-sh/uv/issues/1495#issuecomment-1950442191 /
https://github.com/astral-sh/uv/issues/1578#issuecomment-1949911871
2024-08-26 11:44:19 -05:00
Charlie Marsh
0dc74f619c
Remove path-absolutize dependency (#6589)
## Summary

This is now in the standard library.
2024-08-25 12:01:07 +00:00
Zanie Blue
7502a963e1
Add support for configuring python-downloads with UV_PYTHON_DOWNLOADS (#6436)
Part of https://github.com/astral-sh/uv/issues/6406

Replaces #6416
2024-08-22 23:19:03 +00:00
Zanie Blue
7d90c29552
Fix priority for .python-versions files in uv python install (#6382)
In https://github.com/astral-sh/uv/pull/6359, I accidentally made `uv
python install` prefer `.python-version` files over `.python-versions`
files -.-, kind of niche but it's a regression.
2024-08-21 22:17:14 +00:00
Zanie Blue
2fbe12ee1b
Refactor .python-version discovery (#6359)
In preparation for more comprehensive discovery
2024-08-21 16:41:20 -05:00
Chan Kang
c9774e9c43
allow manylinux compatibility override via _manylinux module. (#6039)
## Summary
resolves https://github.com/astral-sh/uv/issues/5915, not entirely sure
if `manylinux_compatible` should be a separate field in the JSON
returned by the interpreter or there's some way to use the existing
`platform` for it.

## Test Plan
ran the below
```
rm -rf .venv
target/debug/uv venv
# commenting out the line below triggers the change..
# target/debug/uv pip install no-manylinux
target/debug/uv pip install cryptography --no-cache
```

is there an easy way to add this into the existing snapshot-based test
suite? looking around to see if there's a way that doesn't involve
something implementation-dependent like mocks.

~update: i think the output does differ between these two, so probably
we can use that.~ i lied - that "building..." output seems to be
discarded.
2024-08-21 01:57:42 +00:00
Zanie Blue
47fb902104 Apply system Python filtering to executable name requests (#4309)
Executable name requests were being treated as explicit requests to
install into system environments, but I don't think it should be as it's
implicit what environment you'll end up in. Following #4308, we allow
multiple executables to be found so we can filter here.

Concretely, this means `--system` is required to install into a system
environment discovered with e.g. `--python=python`. The flag is still
not required for cases where we're not mutating environment.
2024-08-20 11:31:46 -05:00
Zanie Blue
04e3e7ce65 Remove preview labeling for uv 0.3.0 (#6166)
- Removes "experimental" labels from command documentation
- Removes preview warnings
- Removes `PreviewMode` from most structs and methods — we could keep it
around but I figure we can propagate it again easily where needed in the
future
- Enables preview behavior by default everywhere, e.g., `uv venv` will
download Python versions
2024-08-20 11:31:46 -05:00
github-actions[bot]
d6c858b0d3
Update Pythons to include Python 3.12.5 (#6087) 2024-08-14 15:18:01 +00:00
Charlie Marsh
ae7a8d7f33
Colocate Python install cache with destination directory (#6043)
## Summary

Closes https://github.com/astral-sh/uv/issues/6036.
2024-08-12 16:15:30 -04:00
Zanie Blue
4df0fe9a01
Update the interface for declaring Python download preferences (#5936)
The loose consensus is that "fetch" doesn't have much meaning and that a
boolean flag makes more sense from the command line.

1. Adds `--allow-python-downloads` (hidden, default) and
`--no-python-downloads` to the CLI to quickly enable or disable
downloads
2. Deprecates `--python-fetch` in favor of the options from (1)
3. Removes  `python-fetch` in favor of a `python-downloads` setting
5. Adds a `never` variant to the enum, allowing even explicit installs
to be disabled via the configuration file

## Test plan

I tested this with various `pyproject.toml`-level settings and `uv venv
--preview --python 3.12.2` and `uv python install 3.12.2` with and
without the new CLI flags.
2024-08-09 13:10:19 -05:00
Charlie Marsh
21408c1f35
Enforce extension validity at parse time (#5888)
## Summary

This PR adds a `DistExtension` field to some of our distribution types,
which requires that we validate that the file type is known and
supported when parsing (rather than when attempting to unzip). It
removes a bunch of extension parsing from the code too, in favor of
doing it once upfront.

Closes https://github.com/astral-sh/uv/issues/5858.
2024-08-08 21:39:47 -04:00
Charlie Marsh
f7110e0a07
Enable mirror for python-build-standalone downloads (#5719)
## Summary

This came up again recently, so decided to do it real quick.

Closes https://github.com/astral-sh/uv/issues/5224.
2024-08-07 21:34:19 -04:00
Charlie Marsh
d0b16f9018
Ensure python-to-pythonX.Y symlink exists in downloaded Pythons (#5849)
## Summary

After installing:

```
❯ readlink "/Users/crmarsh/Library/Application Support/uv/python/cpython-3.12.4-macos-aarch64-none/bin/python"
python3.12

❯ readlink "/Users/crmarsh/Library/Application Support/uv/python/cpython-3.9.5-macos-aarch64-none/bin/python"
python3.9
```

Closes https://github.com/astral-sh/uv/issues/5838.
2024-08-06 23:03:22 -04:00
Charlie Marsh
bb6ac67df3
Use cache for Python install temporary directories (#5787)
## Summary

It's fine for this to be in the cache, I think, since we don't
necessarily need to colocate it with the Python directory.

Closes https://github.com/astral-sh/uv/issues/5747.
2024-08-05 02:32:24 +00:00
Charlie Marsh
499c368f1e
Use "pre-release" in prose and Prerelease in code (#5697)
## Summary

Closes https://github.com/astral-sh/uv/issues/5630.
2024-08-01 20:56:29 +00:00
Zanie Blue
7ef830460e
Replace --python-preference installed with managed (#5637)
Collapses the previous default into "managed" and makes the "managed"
behavior match "installed". People should use "only-managed" if they
want that behavior, it seems overly complicated otherwise.
2024-07-31 08:40:39 -05:00
Charlie Marsh
5d727cb0af
Deprecate the --isolated flag (#5466)
## Summary

This PR deprecates the `--isolated` flag. The treatment varies across
the APIs:

- For non-preview APIs, we warn but treat it as equivalent to
`--no-config`.
- For preview APIs, we warn and ignore it, with two exceptions...
- For `tool run` and `run` specifically, we don't even warn, because we
can't differentiate the command-specific `--isolated` from the global
`--isolated`.
2024-07-30 22:40:38 +00:00
Ben Beasley
dfb4e5bbc8
Add license text to fetch-download-metadata.py (#5587) 2024-07-30 08:15:23 -04:00
Maksim Bondarenkov
228a803fde
uv-python: use windows-sys instead of winapi (#5591)
<!--
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

use windows-sys bindings maintained by microsoft devs. winapi didn't has
any updates for more than 3 years

## Test Plan

cargo test. it failed locally because I don't have Python 3.12 installed
2024-07-30 11:43:04 +02:00
Charlie Marsh
37388f0987
Make directory a required argument (#5573) 2024-07-29 20:47:34 +00:00
bluss
e46c24d3cf
Implement uv run --directory (#5566)
## Summary

uv run --directory <path> means that one doesn't have to change to a
project's directory to run programs from it. It makes it possible to use
projects as if they are tool installations.

To support this, first the code reading .python-version was updated so
that
it can read such markers outside the current directory. Note the minor
change this causes (if I'm right), described in the commit.

## Test Plan

One test has been added.

## --directory

Not sure what the name of the argument should be, but it's following uv
sync's directory for now.

Other alternatives could be "--project". Uv run and uv tool run should
probably find common agreement on this (relevant for project-locked
tools).

I've implemented this same change in Rye, some time ago, and then we
went
with --pyproject `<`path to pyproject.toml file`>`. I think using
pyproject.toml file path and not directory was probably a mistake, an
overgeneralization one doesn't need.
2024-07-29 15:53:10 -04:00
Pavel Dikov
cb47aed9de
feat(venv): add relocatable flag (#5515)
## Summary

Adds a `--relocatable` CLI arg to `uv venv`. This flag does two things:

* ensures that the associated activation scripts do not rely on a
hardcoded
absolute path to the virtual environment (to the extent possible; `.csh`
and
  `.nu` left as-is)
* persists a `relocatable` flag in `pyvenv.cfg`.

The flag in `pyvenv.cfg` in turn instructs the wheel `Installer` to
create script
entrypoints in a relocatable way (use `exec` trick + `dirname $0` on
POSIX;
use relative path to `python[w].exe` on Windows).

Fixes: #3863

## Test Plan

* Relocatable console scripts covered as additional scenarios in
existing test cases.
* Integration testing of boilerplate generation in `venv`.
* Manual testing of `uv venv` with and without `--relocatable`
2024-07-29 00:10:11 +00:00
Charlie Marsh
88340fbd0d
Remove some unused methods (#5512) 2024-07-28 17:20:12 +00:00
Charlie Marsh
24859bd3ee
Upgrade to Rust 1.80.0 (#5472) 2024-07-27 01:49:47 +00:00
Charlie Marsh
561625ed8c
Use hasher to compute resolution hash (#5495)
## Summary

Addressing one TODO. This should be more efficient.
2024-07-26 23:24:09 +00:00
Charlie Marsh
8b8f34ac21
Avoid canonicalizing executables on Windows (#5446)
## Summary

If you have an executable path on a network share path (like
`\\some-host\some-share\...\python.exe`), canonicalizing it adds the
`\\?` prefix, but dunce cannot safely strip it.

This PR changes the Windows logic to avoid canonicalizing altogether. We
don't really expect symlinks on Windows, so it seems unimportant to
resolve them.

Closes: https://github.com/astral-sh/uv/issues/5440.
2024-07-26 08:57:33 -04:00
Charlie Marsh
967fcdbb83
Update bundled Pythons to include stripped variants (#5469)
## Summary

The previous update used a slightly botched release.
2024-07-26 00:34:45 +00:00
Charlie Marsh
6f45403d31
Infer missing .exe in Windows Python discovery (#5456)
## Summary

Closes https://github.com/astral-sh/uv/issues/5445.
2024-07-25 16:57:38 -04:00
Charlie Marsh
a089e20a35
Use stripped variants by default in Python install (#5451)
## Summary

Will file a separate ticket to support `--debug`.

Closes https://github.com/astral-sh/uv/issues/5447.
2024-07-25 17:29:31 +00:00
Zanie Blue
42e76e2545
Prefer "lockfile" to "lock file" (#5427)
Closes https://github.com/astral-sh/uv/issues/5415
2024-07-25 09:22:36 -05:00
Zanie Blue
7908436a76
Display Python installation key for discovered interpreters (#5365)
> DEBUG Found `cpython-3.12.1-macos-aarch64-none` at
`/Users/zb/Library/Application
Support/uv/python/cpython-3.12.1-macos-aarch64-none/bin/python3`
(managed installations)

Instead of `<implementation> <version>`

> DEBUG Found cpython 3.12.1 at `/Users/zb/Library/Application
Support/uv/python/cpython-3.12.1-macos-aarch64-none/bin/python3`
(managed installations)
2024-07-23 15:29:15 -05:00
Jo
7ddf67a72b
Add PyPy finder (#5337)
## Summary

This PR adds PyPy finder and adds PyPy to uv managed Python versions.

## Test Plan

```console
$ cargo run -- python install
```
2024-07-23 14:58:04 -05:00
Jo
96b24345eb
Allow comments in .python-version[s] (#5350)
## Summary

Do the same thing as https://github.com/astral-sh/rye/pull/1038.
2024-07-23 14:56:50 -05:00
Zanie Blue
6fe9bd8a80
Omit interpreter path during uv venv with managed Python (#5311)
e.g. 
```
❯ cargo run -q -- venv --preview
Using Python 3.12.1
Creating virtualenv at: .venv
Activate with: source .venv/bin/activate
```

instead of 

```
❯ cargo run -q -- venv --preview
Using Python 3.12.1 interpreter at: /Users/zb/Library/Application Support/uv/python/cpython-3.12.1-macos-aarch64-none/bin/python3
Creating virtualenv at: .venv
Activate with: source .venv/bin/activate
```
2024-07-23 14:20:23 -05:00