Commit graph

3365 commits

Author SHA1 Message Date
konsti
d7feaadcbf
Reduce file reading boilerplace in tests (#7832) 2024-10-01 15:39:59 +02:00
konsti
8177974439
Follow-up: Add gitignore to dist directory (#7840) 2024-10-01 15:38:37 +02:00
Tim de Jager
50116efb10
expose FlatDistributions struct in public API (#7833)
Would it be okay to expose this struct? We currently use our own
ResolveProvider, and it would be nice to use the `FlatDistributions` for
easy `VersionMap` creation.

Thanks!
2024-10-01 07:46:32 -05:00
konstin
f68e3dfd9d Add gitignore to dist directory
The build artifacts in `dist` are not meant to be checked in, so we're adding a gitignore to this directory, like `.venv`.
2024-10-01 14:18:26 +02:00
Charlie Marsh
1602b5c8d7
Remove unnecessary index location methods (#7826) 2024-10-01 04:44:53 +00:00
Charlie Marsh
462a13c45a
Respect tool.uv.environments for legacy virtual workspace roots (#7824)
## Summary

Closes https://github.com/astral-sh/uv/issues/7821.
2024-09-30 20:52:56 -04:00
Charlie Marsh
b6de417c94
Use serde-untagged to improve some untagged enum error messages (#7822)
## Summary

This is related to https://github.com/astral-sh/uv/issues/7817, but
doesn't close it.
2024-09-30 23:40:21 +00:00
bluss
67769a4985
packaged app: use executable named for the project and main function (#7670)
## Summary

Create a function main as the default for a packaged app. Configure the
default executable as:

`example-packaged-app = "example_packaged_app:main"`

Which is often what you want - the executable has the same name as the
app.
The purpose is to more often hit what the user wants, so they don't have
to even rename the command to start developing.

## Test Plan

- existing tests are updated
2024-09-30 17:19:36 -05:00
Charlie Marsh
f67347e72c
Allow multiple source entries for each package in tool.uv.sources (#7745)
## Summary

This PR enables users to provide multiple source entries in
`tool.uv.sources`, e.g.:

```toml
[tool.uv.sources]
httpx = [
  { git = "https://github.com/encode/httpx", tag = "0.27.2", marker = "sys_platform == 'darwin'" },
  { git = "https://github.com/encode/httpx", tag = "0.24.1", marker = "sys_platform == 'linux'" },
]
```

The implementation is relatively straightforward: when we lower the
requirement, we now return an iterator rather than a single requirement.
In other words, the above is transformed into two requirements:

```txt
httpx @ git+https://github.com/encode/httpx@0.27.2 ; sys_platform == 'darwin'
httpx @ git+https://github.com/encode/httpx@0.24.1 ; sys_platform == 'linux'
```

We verify (at deserialization time) that the markers are
non-overlapping.

Closes https://github.com/astral-sh/uv/issues/3397.
2024-09-30 21:16:44 +00:00
Charlie Marsh
71d5661bd8
Add a custom suggestion for uv add dotenv (#7799)
## Summary

This was brought up on Twitter recently. `dotenv` hasn't been updated in
years and doesn't build successfully anymore. Users almost always mean
to install `python-dotenv`. I think we can add helpful hints here to
point users in the right direction.

## Test Plan

![Screenshot 2024-09-29 at 9 27
27 PM](https://github.com/user-attachments/assets/72585860-9d98-4478-9eac-2c17ac06178b)
2024-09-30 17:00:31 +00:00
Jo
da9e85cc6a
Fix uv tree --invert for platform dependencies (#7808)
## Summary

`click` has one dependency of `colorama` only on Windows, `uv tree
--invert` should not include `colorama` on non-Windows platforms, but
currently:

```console
$ uv init
$ uv add click
$ uv tree --invert --python-platform macos
colorama v0.4.6
```

it should:
```console
$ uv tree --invert --python-platform macos
click v8.1.7
    └── project v0.1.0
```
2024-09-30 12:45:24 -04:00
Charlie Marsh
7435ee3b24
Allow spaces in path requirements (#7767)
## Summary

This PR modifies our parsing to allow spaces in URLs. I don't know if
this is a correct change... But we now parse URLs until we see:

- A newline.
- A semicolon (marker) or hash (comment), _preceded_ by a space. We
parse the URL until the last
  non-whitespace character (inclusive).
- A semicolon (marker) or hash (comment) _followed_ by a space. We treat
this as an error, since
the end of the URL is ambiguous (e.g., `https://foo.com; marker`) would
be a URL that ends in `;`).

Closes https://github.com/astral-sh/uv/issues/6032.
2024-09-30 12:38:38 -04:00
Ahmed Ilyas
5d165b5607
uv build builds into a top-level dist dir in workspaces (#7813)
## Summary

Resolves #7812 

## Test Plan

`cargo test`
2024-09-30 12:17:26 -04:00
Charlie Marsh
b6ce39f45e
Remove lossy resolution-to-requirements conversion in install plan (#7798)
## Summary

This is a longstanding piece of technical debt. After we resolve, we
have a bunch of `ResolvedDist` entries. We then convert those to
`Requirement` (which is lossy -- we lose information like "the index
that the package was resolved to"), and then back to `Dist`.
2024-09-30 10:13:09 -04:00
renovate[bot]
a7038e1b4a
Update Rust crate flate2 to v1.0.34 (#7788) 2024-09-29 21:00:38 -04:00
Charlie Marsh
66d7ec541a
Avoid reusing cached downloaded binaries with --no-binary (#7772)
## Summary

Historically, we've allowed the use of wheels that were downloaded from
PyPI even when the user passes `--no-binary`, if the wheel exists in the
cache. This PR modifies the cache lookup code such that we respect
`--no-build` and `--no-binary` in those paths.

Closes https://github.com/astral-sh/uv/issues/2154.
2024-09-29 17:34:52 +00:00
Charlie Marsh
c415251aa2
Use file stem when parsing cached wheel names (#7773)
## Summary

I noticed that we were including `http` (the file extension) in the
platform tags when reading from the cache:

![Screenshot 2024-09-28 at 9 40
15 PM](https://github.com/user-attachments/assets/d80ed351-1257-42b5-8292-0b11a50c767d)

Probably harmless, but wrong.
2024-09-29 12:05:15 -04:00
konsti
884b5a3c80
No jemalloc on freebsd (#7780) 2024-09-29 17:49:07 +02:00
Jp
ada6b36635
Correctly trims values during wheel WHEEL file parsing (#7770)
## Summary

My last changes (#6616) used by mistake == instead of !=.
😥 Making values currently never trimmed despite
what we wanted.
Values should now be trimmed if needed.

Also removes the trim of the header name, because if a header contains
spaces, the header will be skipped by the mailparse crate in the first
place.

## Test Plan
- A unit test has been added to validate that we correctly trim values.
- A unit test has been added to validate the header names containing
spaces are skipped.
2024-09-28 20:08:22 -04:00
Charlie Marsh
9312a08009
Reject self-dependencies in uv add (#7766)
## Summary

However, adding a recursive extra _is_ allowed.

Closes https://github.com/astral-sh/uv/issues/7731.
2024-09-28 16:02:11 -04:00
Charlie Marsh
9363ecfd31
Retain empty extras on workspace members (#7762)
## Summary

I'm not sure why we drop these but it seems incorrect.
2024-09-28 14:34:34 -04:00
adisbladis
9f981c934a
Add UV_NO_SYNC environment variable (#7752)
## Summary

I have a workflow where I want use `uv` as a dependency solver only, and
manage my environments with external tooling (Nix).

## Test Plan

Manually tested. Automated testing seems excessive for such a trivial
change.

## Problems

It's still not as useful as I'd like it to be.
`uv` uncondtionally creates a virtual environment, something I would
expect that `--no-sync` should disable.
This looks a bit more tricky to achieve and I'm not sure about how to
best structure it.
2024-09-28 12:03:45 -04:00
Jo
0dbf9ae4a7
Support uv run -m foo to run a module (#7754)
## Summary

This is another attempt using `module: bool` instead of `module:
Option<String>` following #7322.
The original PR can't be reopened after a force-push to the branch, I've
created this new PR.

Resolves #6638
2024-09-28 10:07:21 -05:00
Jiahao Yuan
1cae78dd03
Fix encoding mismatch between python child process and uv (#7757)
## Summary

This PR fixes #7733. According to [CPython documentation on
`sys.stdout`](https://docs.python.org/3.12/library/sys.html#sys.stdout),
when `stdout`/`stderr` is non-character device like pipe, the encoding
will be set to system locale on windows. However, on the Rust side
`stdout_reader` and `stderr_reader` expect them to be encoded in UTF-8
and will fail when child process write non-ASCII character to
stdout/stderr, e.g., build directory name containing non-ASCII
character.

Both
[CPython3](https://docs.python.org/3.12/using/cmdline.html#envvar-PYTHONIOENCODING)
and [PyPy](https://doc.pypy.org/en/default/man/pypy3.1.html#environment)
support environment variable `PYTHONIOENCODING`. When it is set to
`utf-8`, python will use UTF-8 encoding for `stdin`/`stdout`/`stderr`.
Since `stdin` is not used by the spawned python process and we expect
`stdout`/`stderr` to use UTF-8, this fix should work as expected.
<!-- What's the purpose of the change? What does it do, and why? -->

## Test Plan

I only tested it on my computer with CPython 3.12 and 3.7. With the fix
applied I confirmed that [the case I
described](https://github.com/astral-sh/uv/issues/7733#issuecomment-2380416093)
is fixed.

I'm using Windows 11 with system locale set to code page 936.
2024-09-28 12:39:37 +00:00
Charlie Marsh
d2e7b40cec
Bump version to v0.4.17 (#7742) 2024-09-27 13:28:38 -04:00
Zanie Blue
41dbd97860
Tweaks to the uvx help menu when no command is provided (#7740)
Follow-up to #7641 with some minor changes to the implementation and a
simplification of the output
2024-09-27 13:02:22 -04:00
Ahmed Ilyas
e85cd26a7a
Indicate which package failed in the error message for uv build --all (#7736)
## Summary

Small follow up to https://github.com/astral-sh/uv/pull/7724

## Test Plan

`cargo test`

---------

Co-authored-by: Charlie Marsh <charlie.r.marsh@gmail.com>
2024-09-27 12:42:34 +00:00
Ahmed Ilyas
805f1bd6f5
Add uv build --all option (#7724)
## Summary

Resolves #7705 

## Test Plan

`cargo test` and tested locally.

The snapshots were unstable due to the packages being built in a
non-deterministic order, so I used the quiet flag to suppress the
output.

Another question is whether we should label the build output to indicate
which package it belongs to?
2024-09-27 02:46:06 +00:00
Zanie Blue
ed1684a0e4
Add uv build --no-build-logs to silence the build backend logs (#7675)
Extends https://github.com/astral-sh/uv/pull/7674

The build backend can be pretty verbose, it seems nice to be able to
turn that off?
2024-09-26 23:39:47 +00:00
Kemal Akkoyun
3ce34035c8
uvx/uv tool run: Add context message before listing available tools when no arguments are provided (#7641)
## Summary

Adds a helpful context message when `uvx` is run without arguments
To clarify, it is displaying the installed tools.

This addresses confusion, such as the one highlighted in issue #7348,
by making the output more user-friendly and informative.

Related #4024 

## Test Plan

Updated the test snapshots to include the new output.
Running the tests locally with `cargo nextest run` confirms that the
tests pass.
The CI pipeline should also pass.

### Manuel Testing

**uvx**
```shell
# Make sure you have the updated version of uv installed on your path.
# cargo install --path ./crates/uv --force
❯ uvx
Provide a command to invoke with `uvx <command>` or `uvx --from <package> <command>`.

The following tools are already installed:

black v24.8.0
- black
- blackd
ruff v0.6.7
- ruff

See `uvx --help` for more information.
```

**uv tool list**
```shell
# Make sure you have the updated version of uv installed on your path.
# cargo install --path ./crates/uv --force
❯ uv tool list
black v24.8.0
- black
- blackd
ruff v0.6.7
- ruff
```

**uv tool run**
```shell
# Make sure you have the updated version of uv installed on your path.
# cargo install --path ./crates/uv --force
❯ uv tool run
Provide a command to invoke with `uv tool run <command>` or `uv tool run --from <package> <command>`.

The following tools are already installed:

black v24.8.0
- black
- blackd
ruff v0.6.7
- ruff

See `uv tool run --help` for more information.
```
---

Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com>

---------

Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com>
2024-09-26 15:35:08 -05:00
Charlie Marsh
fe88c10813
Remove unused thiserror variants in resolver (#7717)
## Summary

While looking at something else, I noticed that these are not used.
2024-09-26 16:36:52 +00:00
konsti
d536dfe67e
Escape glob patterns (#7709) 2024-09-26 14:54:29 +00:00
Aarni Koskela
ed940300f7
Don't create Python bytecode files during interpreter discovery (#7707) 2024-09-26 13:52:10 +00:00
Liam
c8357b7bf2
Allow unused mut in graph resolution conflicts (#7701) 2024-09-26 09:17:43 +00:00
Jo
0c801f8f4b
Initialize a Git repository in uv init (#5476)
## Summary

Similiar to `cargo init --vcs <VCS>`, this PR adds the `--vcs <VCS>`
flag for `uv init`, allowing to create a version control system during
initialization. By default, `uv init` will create a Git repository if
the `--vcs` flag is not provided. Use `--vcs none` to disable this
feature.

Currently, only Git is supported. While Cargo also supports hg, pijul,
and fossil, this initial PR only includes Git. We can add more later if
there are any user requests.

---------

Co-authored-by: Charlie Marsh <charlie.r.marsh@gmail.com>
2024-09-26 02:40:39 +00:00
tfsingh
6e9ecde9c2
Add support for uv init --script (#7565)
This PR adds support for ```uv init --script```, as defined in issue
#7402 (started working on this before I saw jbvsmo's PR). Wanted to
highlight a few decisions I made that differ from the existing PR:

1. ```--script``` takes a path, instead of a path/name. This potentially
leads to a little ambiguity (I can certainly elaborate in the docs,
lmk!), but strictly allowing ```uv init --script path/to/script.py```
felt a little more natural than allowing for ```uv init --script path/to
--name script.py``` (which I also thought would prompt more questions
for users, such as should the name include the .py extension?)
2. The request is processed immediately in the ```init``` method,
sharing logic in resolving which python version to use with ```uv add
--script```. This made more sense to me — since scripts are meant to
operate in isolation, they shouldn't consider the context of an
encompassing package should one exist (I also think this decision makes
the relative codepaths for scripts/packages easier to follow).
3. No readme — readme felt a little excessive for a script, but I can of
course add it in!

---------

Co-authored-by: João Bernardo Oliveira <jbvsmo@gmail.com>
2024-09-25 22:48:01 +00:00
konsti
9004364de3
Rename uv-build to uv-build-frontend (#7688)
uv will soon support both a build frontend (`uv build`) and a build
backend (`build-system = "uv"`). To avoid the name clash, I'm renaming
the `uv-build` crate to `uv-build-frontend`. In a follow-up PR, I will
add a `uv-build-backend` crate with the build backend implementation.
2024-09-25 14:17:54 -04:00
tfsingh
106633a5e5
Add support for upgrading Python in tool environments (#7605)
This PR adds support for upgrading the build environment of tools with
the addition of a ```--python``` argument to ```uv upgrade```, as
specified in #7471.

Some things to note:
- I added support for individual packages — I didn't think there was a
good reason for ```--python``` to only apply to all packages
- Upgrading with ```--python``` also upgrades the package itself — I
think this is fair as if a user wants to _strictly_ switch the version
of Python being used to build a tool's environment they can use ```uv
install```. This behavior can of course be modified if others don't
agree!

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

Closes https://github.com/astral-sh/uv/issues/7471.
2024-09-25 17:40:28 +00:00
konsti
f5601e2610
Clean up "performance allocators" and "performance flate2" backends (#7686)
Co-authored-by: Amos Wenger <amos@bearcove.net>
2024-09-25 15:41:40 +00:00
Zanie Blue
12ab7d1ab7
Respect --quiet flag in uv build (#7674)
I noticed this was not respected, seems like an oversight.
2024-09-25 08:23:43 -05:00
Topher Anderson
84e5f6e871
Regression fix: don't prefetch source dists with unbounded lower-bound ranges (#7683)
#7226 modified the check to skip prefetching of source dists without
proper minimum-version bounds, and wound up flipping the boolean
expression. This change flips the some/none expression so that the
intended skip happens as expected.

Fixes #7680.
2024-09-25 08:35:19 -04:00
Zanie Blue
bef72a8880
Display skipped managed interpreters during Python discovery (#7668)
e.g.

```
❯ cargo run -- python find 3.11rc2 -v
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.14s
     Running `target/debug/uv python find 3.11rc2 -v`
DEBUG uv 0.4.15
DEBUG Searching for Python 3.11rc2 in managed installations or system path
DEBUG Found `cpython-3.12.1-macos-aarch64-none` at `/Users/zb/workspace/uv/.venv/bin/python3` (active virtual environment)
DEBUG Found `cpython-3.12.1-macos-aarch64-none` at `/Users/zb/workspace/uv/.venv/bin/python3` (virtual environment)
DEBUG Searching for managed installations at `/Users/zb/.local/share/uv/python`
DEBUG Skipping incompatible managed installation `cpython-3.13.0rc2-macos-aarch64-none`
DEBUG Skipping incompatible managed installation `cpython-3.12.1-macos-aarch64-none`
DEBUG Skipping incompatible managed installation `cpython-3.11.7-macos-aarch64-none`
DEBUG Skipping incompatible managed installation `cpython-3.10.13-macos-aarch64-none`
DEBUG Skipping incompatible managed installation `cpython-3.9.18-macos-aarch64-none`
DEBUG Skipping incompatible managed installation `cpython-3.8.18-macos-aarch64-none`
DEBUG Skipping incompatible managed installation `cpython-3.8.12-macos-aarch64-none`
DEBUG Skipping incompatible managed installation `pypy-3.9.19-macos-aarch64-none`
DEBUG Found `cpython-3.12.1-macos-aarch64-none` at `/Users/zb/workspace/uv/.venv/bin/python` (search path)
DEBUG Found `cpython-3.12.1-macos-aarch64-none` at `/Users/zb/workspace/uv/.venv/bin/python3` (search path)
DEBUG Found `cpython-3.12.6-macos-aarch64-none` at `/opt/homebrew/bin/python3` (search path)
DEBUG Found `cpython-3.11.10-macos-aarch64-none` at `/opt/homebrew/bin/python3.11` (search path)
DEBUG Found `cpython-3.9.6-macos-aarch64-none` at `/usr/bin/python3` (search path)
error: No interpreter found for Python 3.11rc2 in virtual environments, managed installations, or system path
```
2024-09-24 14:41:41 -05:00
Zanie Blue
e81ed8ec5d
Bump version to 0.4.16 (#7669) 2024-09-24 14:39:21 -05:00
Zanie Blue
e6cd6c9b01
Use the first pre-release discovered when only pre-release Python versions are available (#7666) 2024-09-24 18:00:28 +00:00
Zanie Blue
a53ddaa24a
Require opt-in to use alternative Python implementations (#7650)
Closes #7118 

This only really affects managed interpreters, as we exclude alternative
Python implementations from the search path during the
`VersionRequest::executable_names` part of discovery.
2024-09-24 12:52:15 -05:00
Charlie Marsh
538b0f1099
Remove serde::Serialize implementations for rkyv-able structs (#7663)
## Summary

Random, but I noticed that we can remove a ton of serialize and
deserialize derives by using `rkyv` for the flat-index caches. (We
already use `rkyv` for these same structs in the registry cache.)
2024-09-24 13:23:47 -04:00
konsti
c4c5378c0b
Add build backend scaffolding (#7662) 2024-09-24 19:23:17 +02:00
Zanie Blue
bcd14ec799
Display Python implementation when creating environments (#7652)
e.g.

```
❯ cargo run -q -- venv -p pypy
Using PyPy 3.9.19
Creating virtual environment at: .venv
Activate with: source .venv/bin/activate
```
2024-09-24 11:45:52 -05:00
Zanie Blue
0c6117f5da
Unhide the --directory option (#7653) 2024-09-24 11:45:33 -05:00
konsti
5da73a24cb
Rename MetadataResolver to ResolutionMetadata (#7661) 2024-09-24 16:25:19 +00:00