Commit graph

388 commits

Author SHA1 Message Date
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
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
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
efbc9fb78d
Add support for benchmarking uv sync and uv lock (#5524)
## Summary

This PR adds support for `uv lock` and `uv sync` in the standardized
benchmarks script.

Part of: https://github.com/astral-sh/uv/issues/5263.

## Test Plan

For example:

```sh
python scripts/bench/__main__.py --uv-project --benchmark resolve-cold ./scripts/requirements/trio.in --verbose
```
2024-07-28 21:09:08 +00:00
Charlie Marsh
88340fbd0d
Remove some unused methods (#5512) 2024-07-28 17:20:12 +00:00
Jo
ae11317cc0
Make pip list --editable conflicts with --exlcude-editable (#5506)
## Summary

I think it makes no sense to allow `--editable` and `--exclude-editable`
at the same time.

## Test Plan
```console
$ cargo run -- pip list --editable --exclude-editable
error: the argument '--editable' cannot be used with '--exclude-editable'

Usage: uv.exe pip list --editable

For more information, try '--help'.

```
2024-07-27 08:26:46 -04:00
Ahmed Ilyas
e8d7c0cb58
Editable installs for uv tool (#5454)
## Summary

Resolves #5436. 

## Test Plan

`cargo test` 

```console
❯ ./target/debug/uv tool install -e ~/black
warning: `uv tool install` is experimental and may change without warning
Resolved 6 packages in 894ms
   Built black @ file:///Users/ahmedilyas/black
Prepared 1 package in 468ms
Installed 6 packages in 6ms
 + black==24.4.3.dev23+g7e2afc9 (from file:///Users/ahmedilyas/black)
 + click==8.1.7
 + mypy-extensions==1.0.0
 + packaging==24.1
 + pathspec==0.12.1
 + platformdirs==4.2.2
Installed 2 executables: black, blackd
```

venv has the `.pth` files.
```console
❯ eza /Users/ahmedilyas/Library/Application\ Support/uv/tools/black/lib/python3.12/site-packages/
_black.pth       _virtualenv.py                         click                  mypy_extensions-1.0.0.dist-info  packaging                 pathspec                   platformdirs
_virtualenv.pth  black-24.4.3.dev23+g7e2afc9.dist-info  click-8.1.7.dist-info  mypy_extensions.py               packaging-24.1.dist-info  pathspec-0.12.1.dist-info  platformdirs-4.2.2.dist-info
```

---------

Co-authored-by: Charlie Marsh <charlie.r.marsh@gmail.com>
2024-07-26 16:30:15 -04:00
Charlie Marsh
d51b429837
Add --no-config to replace --isolated (#5463)
## Summary

I'll deprecate `--isolated` separately, since it _is_ still used for
some other behaviors.

Closes #5428.
2024-07-25 19:58:36 -04:00
Charlie Marsh
d0919329fd
Make --reinstall imply --refresh (#5425)
## Summary

It's hard for me to imagine a scenario in which a user passed
`--reinstall`, but wanted us to keep respecting cached data for a
package. For example, to actually "rebuild and reinstall" an editable
today, you have to pass both `--reinstall` and `--refresh`.

This PR makes `--reinstall` imply `--refresh`, so we always validate
that the cached data is fresh.

Closes https://github.com/astral-sh/uv/issues/5424.
2024-07-25 09:45:58 -04:00
Charlie Marsh
4bc04f91e9
Add --ci mode to uv cache prune (#5391)
## Summary

Users can now run `uv cache prune --ci` (open to feedback on the name of
that flag) to remove all pre-built wheels from the cache, leaving behind
zipped, built wheels (which tend to be the most expensive assets to
re-create). This should greatly increase cache performance in CI
environments, since uploading unzipped wheels can actually hurt
performance if you're persisting the uv cache.

Closes https://github.com/astral-sh/uv/issues/5282.
2024-07-24 19:34:19 +00:00
Jo
7bcafec778
Add uv init --virtual (#5396)
## Summary

Add `uv init --virtual` to create an explicit virtual workspace.

Relates to #5338
2024-07-24 18:52:33 +00:00
Charlie Marsh
8942ec36c0
Mark --raw-sources as conflicting with sources-specific arguments (#5378)
## Summary

We should error on, e.g., `--raw-sources --tag 0.0.1`.
2024-07-23 22:03:01 +00:00
Charlie Marsh
76566b09be
Reject Git CLI arguments with non-Git sources (#5377)
## Summary

Closes https://github.com/astral-sh/uv/issues/5335.
2024-07-23 21:48:50 +00:00
Charlie Marsh
2cdcc61da9
Support requirements.txt files in uv tool install and uv tool run (#5362)
## Summary

Closes https://github.com/astral-sh/uv/issues/5347.
Closes https://github.com/astral-sh/uv/issues/5348.
2024-07-23 20:06:17 +00:00
Zanie Blue
5f1f9c8293
Add support for requirements files in uv run (#4973)
Closes https://github.com/astral-sh/uv/issues/4824.

---------

Co-authored-by: Charlie Marsh <charlie.r.marsh@gmail.com>
2024-07-23 12:51:09 -04:00
Charlie Marsh
0f8186d9ad
Add requires-python to uv init (#5322)
## Summary

Prefers, in order:

- The major-minor version of an interpreter discovered via `--python`.
- The `requires-python` from the workspace.
- The major-minor version of the default interpreter.

If the `--python` request is a version or a version range, we use that
without fetching an interpreter.

Closes https://github.com/astral-sh/uv/issues/5299.
2024-07-23 16:02:40 +00:00
Chan Kang
12518a01a4
Implement --show-version-specifiers for tree (#5240)
## Summary
resolves https://github.com/astral-sh/uv/issues/5217

## Test Plan
existing tests pass (should be perfectly backwards compatible) + added a
few tests to cover the new functionality. in particular, in addition to
the simple use of `--show-version-specifiers`, its interaction with
`--invert` and `--package` flags are tested.
2024-07-20 18:31:16 +00:00
Jo
0611c7b59e
Add uv add --no-editable (#5246)
## Summary

Resolves #5241

## Test Plan

```sh
# create a workspace with sub-packages `pkg-a` and `pkg-b`

$ cd ./pkg-b
$ cargo run -- add ./pkg-a --no-editable

$ cat ./pyproject.toml
[project]
name = "pkg-b"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
dependencies = [
    "pkg-a",
]

[tool.uv]
dev-dependencies = []

[tool.uv.sources]
pkg-a = { workspace = true, editable = false }
```
2024-07-20 09:11:34 -04:00
Ibraheem Ahmed
12dd450a8e
Implement uv init (#4791)
## Summary

Implements the `uv init` command, which initializes a project
(`pyproject.toml`, `README.md`, `src/__init__.py`) in the current
directory, or in the given path. `uv init` also does workspace
discovery.

Resolves https://github.com/astral-sh/uv/issues/1360.

---------

Co-authored-by: Zanie Blue <contact@zanie.dev>
2024-07-19 15:11:48 +00:00
Charlie Marsh
ed9b820815
Remove trailing period from user-facing messages (#5218)
## Summary

Per #5209, we only show periods in messages when the message itself
spans more than a single sentence.
2024-07-19 10:43:49 -04:00
Charlie Marsh
729148dac9
Add --frozen to uv add, uv remove, and uv tree (#5214)
## Summary

E.g., `uv add foo --frozen` will avoid updating or even creating a
`uv.lock`.
2024-07-19 13:18:32 +00:00
Charlie Marsh
dfe2faa71e
Add --locked and --frozen to uv run CLI (#5196)
## Summary

You can now use `uv run --locked` to assert that the lockfile doesn't
change, or `uv run --frozen` to run without attempting to update the
lockfile at all.

Closes https://github.com/astral-sh/uv/issues/5185.
2024-07-18 18:55:17 +00:00
Charlie Marsh
36a0ee9822
Remove executable alias; import anstream (#5187)
Post-push review from https://github.com/astral-sh/uv/pull/5160.
2024-07-18 14:09:29 +00:00
Charlie Marsh
622e9e8799
Add uv tool list --show-paths to show install paths (#5164)
## Summary

Closes https://github.com/astral-sh/uv/issues/4823.
2024-07-17 19:11:13 -04:00
Charlie Marsh
82d94838cb
Implement a --verify-hashes hash-checking mode (#4007)
## Summary

This is an alternative to `--require-hashes` which will validate a hash
if it's present, but ignore requirements that omit hashes or are absent
from the lockfile entirely.

So, e.g., transitive dependencies that are missing will _not_ error; nor
will dependencies that are included but lack a hash.

Closes https://github.com/astral-sh/uv/issues/3305.
2024-07-17 21:25:31 +00:00
Charlie Marsh
eb24717a9b
Add uv tool dir --bin to show executable directory (#5160)
## Summary

Closes https://github.com/astral-sh/uv/issues/5159.
2024-07-17 16:30:45 -04:00
konsti
3e93255ac9
Document that --universal implies --no-strip-markers (#5121)
Prompted by
https://github.com/python-trio/trio/pull/3032#discussion_r1679435422.
2024-07-17 15:54:21 +00:00
Silvano Cerza
426736f7ed
Add --no-progress global option to hide all progress animations (#5098)
## Summary

Fixes #5082.

Adds a new `Printer::NoProgress` that is identical to `Printer::Default`
but doesn't draw any progress bar.

## Test Plan

It seems to me that as of now it's not possible to use `insta-cmd` to
get any progress bar in the comparable output of command.

Best way to test this would be to run any command that usually shows
progress indicators like `uv pip install` with and without
`--no-progress` options.
2024-07-16 16:48:57 -05:00
Charlie Marsh
7211e62132
Add reference documentation for pip settings (#5125)
## Summary

Third part of https://github.com/astral-sh/uv/issues/5093.
2024-07-16 21:14:27 +00:00
Charlie Marsh
f7c52fdbfb
Add reference documentation for global settings (#5123)
## Summary

Second part of: https://github.com/astral-sh/uv/issues/5093.
2024-07-16 20:50:04 +00:00
Charlie Marsh
616a61a244
Add reference documentation for resolver settings (#5122)
## Summary

First part of https://github.com/astral-sh/uv/issues/5093.

Remaining:

- Global settings
- `pip`-specific settings (some will be copied-over from here)
- Auto-generating the "Possible values" for enums
2024-07-16 16:39:22 -04:00
Charlie Marsh
a4cb21e081
Add a command to append uv's binary directory to PATH (#4975)
## Summary

I'll open follow-up tickets for Windows support.

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

## Test Plan

```
❯ cargo run tool install flask
Resolved 7 packages in 353ms
Prepared 7 packages in 392ms
Installed 7 packages in 17ms
 + blinker==1.8.2
 + click==8.1.7
 + flask==3.0.3
 + itsdangerous==2.2.0
 + jinja2==3.1.4
 + markupsafe==2.1.5
 + werkzeug==3.0.3
Installed 1 executable: flask
warning: /Users/crmarsh/.local/bin is not on your PATH. To use installed tools, run:
  export PATH="/Users/crmarsh/.local/bin:$PATH"
```

Then:

```
❯ which flask
flask not found
```

Then:

```
❯ cargo run tool ensurepath
warning: `uv tool ensurepath` is experimental and may change without warning.
Updated configuration file: /Users/crmarsh/workspace/puffin/bar
Restart your shell for the changes to take effect.
```

Then:
```
❯ which flask
/Users/crmarsh/.local/bin/flask
```
2024-07-12 22:09:34 +00:00
Silvano Cerza
2ccb7ed305
Add --no-pager option in help command (#5007)
## Summary

Fixes #4941.

This PR adds a `--no-pager` option in `help` command to explicitly
disable the pager.

I noted that the template used for the text printed when calling `help`
with no argument or option doesn't show any option. It made sense before
this PR since `help` didn't have any available option. Though I'm unsure
if it makes sense to update the template as it would make it extremely
verbose as all the global options would be shown too.

I leave the decision to you.

## Test Plan

I ran `cargo run -- help` to verify `--isolated` was visible and it.
I ran clippy with `cargo clippy --workspace --all-targets --all-features
--locked -- -D warnings` as CI does.

I also ran tests locally with:
```
cargo nextest run \
            --features python-patch \
            --workspace \
            --status-level skip --failure-output immediate-final --no-fail-fast -j 12 --final-status-level slow
```
2024-07-12 11:11:50 -05:00
Silvano Cerza
663c190c2d
Unhide --isolated global argument (#5005)
## Summary

This PR makes the `--isolated` global argument visible, previously it
was hidden.
Fixes #4981.

## Test Plan

I ran `cargo run -- help` to verify `--isolated` was visible and it is.
I ran clippy with `cargo clippy --workspace --all-targets --all-features
--locked -- -D warnings` as CI does.

I also ran tests locally with:
```
cargo nextest run \
            --features python-patch \
            --workspace \
            --status-level skip --failure-output immediate-final --no-fail-fast -j 12 --final-status-level slow
```
2024-07-12 09:34:00 -05:00
Caíque Porfirio
9643fb99d1
Rename python install --force parameter to --reinstall (#4999)
## Summary

Rename the `--force` parameter of `uv python install` to `--reinstall`.

Closes #4961.
2024-07-12 01:06:54 +00:00
Zanie Blue
e0fae8e6f4
Add uv python pin (#4950)
Adds a `uv python pin` command to write to a `.python-version` file.

We support all of our Python version request formats. We also support a
`--resolved` flag to pin to a specific interpreter instead of the
provided version. We canonicalize the request with #4949, it's not just
printed verbatim. We always attempt to find the interpreter so we can
warn if it's not available. With `--resolved`, if we can't find the
interpreter we fail. If no arguments are provided, we'll attempt to
display the current pin.

In the future:

- We should confirm that this satisfies the `Requires-Python` metadata
if a `pyproject.toml` is present
- We should support writing to a `uv.python-version` field if
`pyproject.toml` or `uv.toml` are present
- We should support finding and updating the "nearest" Python version
file (looking in ancestors)
- We should support finding version files in workspaces
- We should support some sort of global pin
2024-07-10 16:52:24 +00:00
Jo
42ccce9641
Fix index_strategy doc (#4955)
## Summary

There is a missing `)` after `first_match`.
2024-07-10 08:54:23 -05:00
Charlie Marsh
23eb42deed
Allow constraints to be provided in --upgrade-package (#4952)
## Summary

Allows, e.g., `--upgrade-package flask<3.0.0`.

Closes https://github.com/astral-sh/uv/issues/1964.
2024-07-09 20:09:13 -07:00
Charlie Marsh
540ff24302
Perform lock in uv sync by default (#4839)
## Summary

- `uv sync` will now lock by default.
- `uv sync --locked` will lock, and error if the generated lock does not
match `uv.lock` on-disk.
- `uv sync --frozen` will skip locking and just use `uv.lock`.

Closes https://github.com/astral-sh/uv/issues/4812.
Closes https://github.com/astral-sh/uv/issues/4803.
2024-07-09 15:18:30 -07:00
Charlie Marsh
55e1a7e011
Enable --all to uninstall all managed tools (#4937)
## Summary

Like #4932 but for tools.
2024-07-09 19:26:17 +00:00
Charlie Marsh
0a04108a15
Enable --all to uninstall all managed Pythons (#4932)
## Summary

Allows `--all` as an alternative to specifying specific targets.

## Test Plan

Verified that `cargo run python uninstall` still fails.

```
❯ cargo run python uninstall --all
   Compiling uv-cli v0.0.1 (/Users/crmarsh/workspace/puffin/crates/uv-cli)
   Compiling uv v0.2.23 (/Users/crmarsh/workspace/puffin/crates/uv)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 2.86s
     Running `target/debug/uv python uninstall --all`
warning: `uv python uninstall` is experimental and may change without warning.
Searching for Python installations
Found existing installation: cpython-3.9.18-macos-aarch64-none
Found existing installation: cpython-3.8.18-macos-aarch64-none
Found existing installation: cpython-3.8.12-macos-aarch64-none
Found existing installation: cpython-3.12.1-macos-aarch64-none
Found existing installation: cpython-3.11.7-macos-aarch64-none
Found existing installation: cpython-3.10.13-macos-aarch64-none
Uninstalled cpython-3.10.13-macos-aarch64-none
Uninstalled cpython-3.11.7-macos-aarch64-none
Uninstalled cpython-3.12.1-macos-aarch64-none
Uninstalled cpython-3.8.12-macos-aarch64-none
Uninstalled cpython-3.8.18-macos-aarch64-none
Uninstalled cpython-3.9.18-macos-aarch64-none
Uninstalled 6 versions in 479ms
```
2024-07-09 18:15:16 +00:00
Charlie Marsh
92290d8dcb
Respect resolver settings in uv remove (#4930)
## Summary

Closes https://github.com/astral-sh/uv/issues/4925
2024-07-09 17:46:31 +00:00
Zanie Blue
5f20bdb2ee
Implement uv help manually instead of using Clap default (#4906)
Extends #4772 

Implements `uv help` ourselves so we can do things like #4909 
Adds hints to use `uv help` for more details during short help display.
2024-07-09 17:43:13 +00:00
Zanie Blue
0bf562f197
Display short help menu when --help is used (#4772)
I feel like I'm always drowning in the help output from `uv` because we
have so many options.

I basically agree with the commentary in
https://github.com/clap-rs/clap/issues/4687 that having different
behaviors for `-h` and `--help` is surprising. I think `--help` is more
obvious for users and I want to optimize for that experience.

This roughly matches the help menus in Cargo and pip.

The `uv help` command can be used for long help. In #4906 and #4909 we
improve that command.

Extends #4904 which adds test cases for the existing behavior.
2024-07-09 17:12:01 +00:00
Ibraheem Ahmed
dc7ad3abdb
Implement uv tree (#4708)
## Summary

Implements the `uv tree`, which displays dependencies from the lockfile
as a tree. Resolves https://github.com/astral-sh/uv/issues/4699.
2024-07-08 18:07:48 +00:00