Commit graph

2660 commits

Author SHA1 Message Date
Charlie Marsh
b9b41d4a38
Include newly-added optional dependencies in lockfile (#5686)
## Summary

When we add a new optional group in `uv add`, we never to update the
`pyproject.toml` before locking. Otherwise, we use the stale
`pyproject.toml` and omit the optional group.

Closes https://github.com/astral-sh/uv/issues/5687.
2024-08-01 12:41:37 -04:00
Zanie Blue
0f30c69624
Move settings reference to reference section (#5689)
Joining #5685 in a dedicated reference section
2024-08-01 16:20:30 +00:00
Zanie Blue
f107406727
Generate CLI reference for documentation (#5685)
Loosely based on [Cargo's
format](https://github.com/rust-lang/cargo/blob/master/src/doc/src/commands/cargo-build.md)

<img width="896" alt="Screenshot 2024-08-01 at 9 44 03 AM"
src="https://github.com/user-attachments/assets/7c016bb3-2b54-46af-8ea8-ce82e07a0e30">

Future work includes:

- Grouping options
- Enforcing some sort of specific command ordering
- Showing possible values for enums
- Adding "long_about" to commands for more context
2024-08-01 16:04:16 +00:00
eth3lbert
9788496c51
Grouping GlobalArgs to dedicated heading (#5665)
## Summary

Part of #4454 .

## Test Plan

test cases included.

---------

Co-authored-by: Zanie Blue <contact@zanie.dev>
2024-08-01 10:01:22 -05:00
Charlie Marsh
b9866b3ee8
Avoid unwrap when serializing receipts (#5678) 2024-07-31 22:57:16 -04:00
Ahmed Ilyas
5bded73c48
uvx warn when no executables are available (#5675)
## Summary

Resolves #5623 

## Test Plan

`cargo test`
2024-07-31 17:27:41 -05:00
Charlie Marsh
ff2b810fdf
Fix non-registry serialization for receipts (#5668)
## Summary

Fixes a bug in #5494. The `RequirementSourceWire` representation was
ambiguous, and so the order of the fields meant that all variants were
mapped to `Registry` when deserializing. (So the snapshots were right,
but behaviors were wrong.)
2024-07-31 21:09:54 +00:00
Charlie Marsh
2b9a4f673e
Initialize the cache in uv init (#5669)
## Summary

We now query the Python interpreter here, which means we need cache
access.
2024-07-31 19:46:12 +00:00
Charlie Marsh
f8e2d2f54d
Remove lingering executables after failed installs (#5666)
## Summary

This could still be made more robust, but it's not critical, since you
can always `--force`. It's good to handle this case, though, since we
have an explicit error for it.

Closes https://github.com/astral-sh/uv/issues/5490.
2024-07-31 15:27:24 -04:00
Charlie Marsh
4b8a127c54
Avoid persisting uv add calls that result in resolver errors (#5664)
## Summary

Closes https://github.com/astral-sh/uv/issues/5622.
2024-07-31 13:27:34 -04:00
eth3lbert
54398fa7bc
Show help specific options in uv help (#5516)
## Summary

Resolves #5221 

## Test Plan

Test case included.
2024-07-31 12:10:57 -05:00
Pavel Dikov
d05f2b258b
fix(venv): make relocatable activation scripts support ksh (#5640)
It transpires that detecting the directory a script was sourced from is
non-trivial across `bash`, `ksh` and `zsh`.

The previous version was a one-liner and supported `bash` and `zsh` but
not `ksh`.

It is possible to keep the one-liner and add `ksh` support, but that is
mutually-exclusive with `zsh`.

Therefore, the only way to square this circle is to add an `if` block. A
silver lining here is that although longer, the script is probably
easier to follow as there is less code-golfing going on.
2024-07-31 12:18:11 -04:00
Charlie Marsh
f266fb711c
Use full requirement when serializing receipt (#5494)
## Summary

The current receipt doesn't capture quite enough information. For
example, it doesn't differentiate between editable and non-editable
requirements. This PR instead uses the full `Requirement` type. I think
we should use a custom representation like we do in the lockfile, but
I'm just using the default representation to demonstrate the idea.
2024-07-31 16:16:39 +00:00
Charlie Marsh
bf8934e3e4
Use intersection rather than union for requires-python (#5644)
## Summary

As-is, if you have a workspace with mixed `requires-python`
requirements, resolution will _never_ succeed, since we'll use the union
as the `requires-python` bound (i.e., take the lowest value), and fail
when we see the package that only supports some more narrow range.

This PR modifies the behavior to take the intersection (i.e., the
highest value), so if you have one package that supports Python 3.12 and
later, and another that supports Python 3.8 and later, we lock for
Python 3.12. If you try to sync or run with Python 3.8, we raise an
error, since the lockfile will be incompatible with that request.

Konsti has a write-up in https://github.com/astral-sh/uv/issues/5594
that outlines what could be a longer-term strategy.

Closes https://github.com/astral-sh/uv/issues/5578.
2024-07-31 16:08:53 +00:00
Charlie Marsh
dfec262586
Capture portable path serialization in a struct (#5652)
## Summary

I need to reuse this in #5494, so want to abstract it out and make it
reusable.
2024-07-31 16:00:37 +00:00
konsti
2247b0f540
Check idempotence in packse lock scenarios (#5485)
Add tests for the instabilities fix.

Part of
https://github.com/astral-sh/uv/issues/5180#issuecomment-2247696198

Closes #5180
2024-07-31 15:39:16 +00:00
konsti
38c6033010
Use fork markers and fork preferences in resolution with lockfile (#5481)
By resolving for each fork from the lockfile individually and by adding
using preferences for the current fork, we solve the instability #5180.
I've tested the locally and will add the packse test scenarios upstack.

Part of
https://github.com/astral-sh/uv/issues/5180#issuecomment-2247696198
2024-07-31 15:18:58 +00:00
Charlie Marsh
176e9c4deb
Add --package to uv sync (#5656)
## Summary

Closes https://github.com/astral-sh/uv/issues/5008.
2024-07-31 15:16:48 +00:00
Andrew Gallant
5b8ed92f95 uv-client: switch heuristic freshness lifetime to hard-coded value
The comment in the code explains the bulk of this:

```rust
// We previously computed this heuristic freshness lifetime by
// looking at the difference between the last modified header and
// the response's date header. We then asserted that the cached
// response ought to be "fresh" for 10% of that interval.
//
// It turns out that this can result in very long freshness
// lifetimes[1] that lead to uv caching too aggressively.
//
// Since PyPI sets a max-age of 600 seconds and since we're
// principally just interacting with Python package indices here,
// we just assume a freshness lifetime equal to what PyPI has.
//
// Note though that a better solution here is for the index to
// support proper HTTP caching headers (ideally Cache-Control, but
// Expires also works too, as above).
```

We also remove the `heuristic_percent` field on `CacheConfig`. Since
that's actually part of the cache itself, we bump the simple cache
version.

Finally, we add some more `trace!` calls that should hopefully make
diagnosing issues related to the freshness lifetime a bit easier in the
future.

Fixes #5351
2024-07-31 08:12:11 -07:00
Charlie Marsh
c2a6cb391b
Prioritize forks based on upper bounds (#5643)
## Summary

Given a fork like:

```
pylint < 3 ; sys_platform == 'darwin'
pylint > 2 ; sys_platform != 'darwin'
```

Solving the top branch will typically yield a solution that also
satisfies the bottom branch, due to maximum version selection (while the
inverse isn't true).

To quote an example from the docs:

```rust
// If there's no difference, prioritize forks with upper bounds. We'd prefer to solve
// `numpy <= 2` before solving `numpy >= 1`, since the resolution produced by the former
// might work for the latter, but the inverse is unlikely to be true due to maximum
// version selection. (Selecting `numpy==2.0.0` would satisfy both forks, but selecting
// the latest `numpy` would not.)
```

Closes https://github.com/astral-sh/uv/issues/4926 for now.
2024-07-31 11:05:12 -04:00
Charlie Marsh
f268b7c90a
Prioritize forks based on Python narrowing (#5642)
## Summary

First part of: https://github.com/astral-sh/uv/issues/4926. We should
solve forks that _don't_ expand the world of supported versions (e.g.,
`python_version >= '3.11'` enables us to select new packages, since we
narrow the supported version range).
2024-07-31 10:29:14 -04:00
Vigilans
0dcec9eba8
Detect python version from python project by default in uv venv (#5592)
<!--
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

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

`uv venv` should support adopting python version specified in
`requires-python` from `pyproject.toml`. This allows customization on
the venv setup when syncing from python project.

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

It also serves as a workaround to close
https://github.com/astral-sh/uv/issues/5258.

## Test Plan

<!-- How was it tested? -->

1. Run `uv venv` in folder with `pyroject.toml` specifying
`requries-python = "<3.10"`. Python 3.9 is selected for venv.
2. Change to `requries-python = "<3.11"` and run `uv venv` again. Python
3.10 is selected now.
3. Switch to a folder without `pyproject.toml` then run `uv venv`.
Python 3.12 is selected now.

---------

Co-authored-by: Charlie Marsh <charlie.r.marsh@gmail.com>
Co-authored-by: Zanie Blue <contact@zanie.dev>
2024-07-31 13:54:16 +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
konsti
981661c4af
Update pubgrub (#5649)
We improved the API structure in pubgrub, and also update to generally
keep up with upstream.
2024-07-31 12:54:11 +00:00
Charlie Marsh
2574f5b3fd
Omit transitive development dependencies from workspace lockfile (#5646)
## Summary

Omit development dependencies from (e.g.) path dependencies.

Closes https://github.com/astral-sh/uv/issues/5593.
2024-07-30 22:32:33 -04:00
Charlie Marsh
38c232e466
Bump version to v0.2.32 (#5641) 2024-07-30 18:56:39 -04: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
Charlie Marsh
67b3bfa213
Add --isolated support to uv run (#5471)
## Summary

The culmination of #4730. We now have `uv run --isolated` which always
uses a fresh environment (but includes the workspace dependencies as
needed). This enables you to test with strict isolation (e.g., `uv run
--isolated -p foo` will ensure that `foo` is unable to import anything
that isn't an actual dependency).

Closes #5430.
2024-07-30 19:27:47 +00:00
Charlie Marsh
ff3bcbb639
Reframe use of --isolated in tool run (#5470)
## Summary

This PR gets rid of the global `--isolated` flag (which serves a bunch
of independent responsibilities right now) on `uv tool run` in favor of
a dedicated `--isolated` flag, which tells uv to avoid re-using an
existing tool environment for this invocation. We'll add the same thing
to `uv run`, to avoid using the base project environment.

This will become a bit clearer in #5466, when we deprecate the
`--isolated` flag on the preview APIs.
2024-07-30 15:09:53 -04:00
Zanie Blue
8545ae2312
Rename more use of "lock file" to "lockfile" (#5629) 2024-07-30 19:09:43 +00:00
Charlie Marsh
d6c319a368
Suppress resolver output by default in uv run and uv tool run (#5580)
## Summary

The idea here is that we hide all resolver output (the grayed out
resolver messages, plus the list of environment modifications) by
default in `uv run` and `uv tool run`. You can pass `--show-resolution`
to re-enable them.

Closes https://github.com/astral-sh/uv/issues/5458.
2024-07-30 18:11:52 +00:00
Charlie Marsh
f7494f24cf
Remove --isolated usages from the uv python API (#5468) 2024-07-30 17:52:53 +00:00
Charlie Marsh
f1b3d2e1e1
Add --no-workspace and --no-project in lieu of --isolated (#5465)
## Summary

Right now, `--isolated` is read from `uv run` and `uv init` to avoid
discovering the current workspace (or project). This PR moves that
behavior to a dedicated `--no-workspace` flag for `uv init`, and
`--no-project` for `uv run`. They could use the same flag, but
`--no-project` feels confusing for `uv init`, and `--no-workspace` seems
confusing for `uv run` (especially so once you read the documentation,
where we refer to the thing you're omitting as the project).

Closes https://github.com/astral-sh/uv/issues/5429.
2024-07-30 13:40:35 -04:00
eth3lbert
fc78561fa1
Add git-ref group for uv add (#5502)
## Summary

This PR allows us to reject specifying more than one git-ref at the cli
level.

## Test Plan

Test cases included.
2024-07-30 09:40:28 -05:00
Charlie Marsh
dfa780d6f5
Re-enable requires-python narrowing in forks (#5583)
See: https://github.com/astral-sh/uv/issues/4669
See: https://github.com/astral-sh/uv/issues/4668
See: https://github.com/astral-sh/uv/pull/4902
2024-07-30 10:06:59 -04:00
Charlie Marsh
3e2ae93d6c
Improve order implementation for Python bound (#5599)
## Summary

We shouldn't unequivocally treat exclusions as greater than
inclusions...
2024-07-30 10:05:54 -04:00
Andrew Gallant
4e748363f8 uv-resolver: fix marker propagation
This PR represents a different approach to marker propagation in an
attempt to unblock #4640. In particular, instead of propagating markers
when forks are created, we wait until resolution is complete to
propagate all markers to all dependencies in each fork. This ends up
being both more robust (we should never miss anything) and simpler to
implement because it doesn't require mutating a `PubGrubPackage` (which
was pretty annoying). I think the main downside here is that this can
sometimes add markers where they aren't needed.

This actually winds up making quite a few snapshot changes. I went
through each of them. Some of them look like legitimate bug fixes. Some
of them look like superfluous additions. And some of them look like they
would be removed if we had perfect marker normalization. But I don't
think any of the changes are _wrong_.
2024-07-30 06:16:03 -07:00
Charlie Marsh
750b3a7c8c
Avoid setting executable permissions on files we might not own (#5582)
## Summary

If we just created an entrypoint script, we can of course set the
permissions (we just created it). However, if we're copying from the
cache, we might _not_ own the file. In that case, if we need to change
the permissions (we shouldn't, since the script is likely already
executable -- we set the permissions when we unzip, but I guess they
could _not_ be properly set in the zip itself), we have to copy it.

Closes https://github.com/astral-sh/uv/issues/5581.
2024-07-30 12:32:52 +00:00
Ben Beasley
dfb4e5bbc8
Add license text to fetch-download-metadata.py (#5587) 2024-07-30 08:15:23 -04:00
konsti
dedd913603
Add forks to lockfile, don't read them yet (#5480)
Add the forks to the lockfile, without using them yet, which we'll add
in the next PR.

Please review commit-by-commit

Part of
https://github.com/astral-sh/uv/issues/5180#issuecomment-2247696198
2024-07-30 11:11:18 +00: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
Ben Beasley
c0d3da8b6a
Add LICENSE for cloneable_seekable_reader.rs from ripunzip (#5585) 2024-07-29 22:15:48 -04:00
Charlie Marsh
c46adee48d
Make --directory a global argument (#5579)
## Summary

Cargo makes this global (and uses the same technique). It's still hidden
so we can always decide to remove it.
2024-07-29 19:43:55 -04:00
eth3lbert
3e329029bc
List installed tools when no command is provided to uv tool run (#5553)
## Summary

Part of #4024 

## Test Plan

Test cases included.
2024-07-29 22:12:31 +00:00
Charlie Marsh
ecb85c9894
Statically link liblzma (#5577)
## Summary

Found via https://github.com/indygreg/PyOxidizer/issues/585.

Closes https://github.com/astral-sh/uv/issues/5572.
2024-07-29 21:46:43 +00:00
Charlie Marsh
51a03738a2
Use cached current directory everywhere (#5574) 2024-07-29 17:03:45 -04: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
Charlie Marsh
cf94a10054
Skip copying to empty entries in seekable zip (#5571)
## Summary

We cannot do this when streaming, since we may not have the metadata for
the entry.

Closes https://github.com/astral-sh/uv/issues/5565.
2024-07-29 19:00:19 +00:00
Charlie Marsh
f70501a22e
Use a consistent buffer size when writing out zip files (#5570) 2024-07-29 14:45:33 -04:00