Commit graph

417 commits

Author SHA1 Message Date
Charlie Marsh
14507a1793
Add uv- prefix to all internal crates (#7853)
## Summary

Brings more consistency to the repo and ensures that all crates
automatically show up in `--verbose` logging.
2024-10-01 20:15:32 -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
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
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
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
c4c5378c0b
Add build backend scaffolding (#7662) 2024-09-24 19:23:17 +02:00
Zanie Blue
0c6117f5da
Unhide the --directory option (#7653) 2024-09-24 11:45:33 -05:00
konsti
205bf8cabe
Implement trusted publishing (#7548)
Co-authored-by: Charlie Marsh <charlie.r.marsh@gmail.com>
2024-09-24 16:07:20 +00:00
konsti
1995d20298
Add uv publish: Basic upload with username/password or keyring (#7475)
Co-authored-by: Charlie Marsh <charlie.r.marsh@gmail.com>
2024-09-24 15:33:06 +00:00
Huang, Hong-Chang
63b60bc0c8
Remove double whitespaces from the code (#7623)
Co-authored-by: konstin <konstin@mailbox.org>
2024-09-23 20:15:06 +00:00
Charlie Marsh
35d6274c31
Add a --project argument to run a command from a project (#7603)
## Summary

`uv run --project ./path/to/project` now uses the provided directory as
the starting point for any file discovery. However, relative paths are
still resolved relative to the current working directory.

Closes https://github.com/astral-sh/uv/issues/5613.
2024-09-21 20:19:49 +00:00
bluss
7a25a82fc9
Move uvx shell completion to uvx --generate-shell-completion (#7511)
## Summary

Because a problem was found with Powershell and combining the generated
completion scripts for uv and uvx, let's try separating uv and uvx
command completion scripts.

The generated powershell script template can be seen in clap_complete
source, and it starts with `using` directives, which makes it impossible
(apparently) to concatenate two of those script outputs.

As a side effect, this is available under `uv tool run
--generate-shell-completion` too.

Fixes #7482

## Test Plan

- `eval "$(cargo run --bin uvx -- --generate-shell-completion bash)"`
- Test Powershell
2024-09-20 01:27:25 +00:00
Charlie Marsh
fda227616c
Allow users to provide pre-defined metadata for resolution (#7442)
## Summary

This PR enables users to provide pre-defined static metadata for
dependencies. It's intended for situations in which the user depends on
a package that does _not_ declare static metadata (e.g., a
`setup.py`-only sdist), and that is expensive to build or even cannot be
built on some architectures. For example, you might have a Linux-only
dependency that can't be built on ARM -- but we need to build that
package in order to generate the lockfile. By providing static metadata,
the user can instruct uv to avoid building that package at all.

For example, to override all `anyio` versions:

```toml
[project]
name = "project"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = ["anyio"]

[[tool.uv.dependency-metadata]]
name = "anyio"
requires-dist = ["iniconfig"]
```

Or, to override a specific version:

```toml
[project]
name = "project"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = ["anyio"]

[[tool.uv.dependency-metadata]]
name = "anyio"
version = "3.7.0"
requires-dist = ["iniconfig"]
```

The current implementation uses `Metadata23` directly, so we adhere to
the exact schema expected internally and defined by the standards. Any
entries are treated similarly to overrides, in that we won't even look
for `anyio@3.7.0` metadata in the above example. (In a way, this also
enables #4422, since you could remove a dependency for a specific
package, though it's probably too unwieldy to use in practice, since
you'd need to redefine the _rest_ of the metadata, and do that for every
package that requires the package you want to omit.)

This is under-documented, since I want to get feedback on the core ideas
and names involved.

Closes https://github.com/astral-sh/uv/issues/7393.
2024-09-18 03:18:05 +00:00
kyoto7250
e5dd67f58e
Add support for --with-editable to uv tool (#6744)
<!--
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? -->
close #6272 

## Test Plan
<!-- How was it tested? -->
As in https://github.com/astral-sh/uv/pull/6262

---------

Co-authored-by: Zanie Blue <contact@zanie.dev>
2024-09-17 20:51:34 +00:00
Charlie Marsh
778da3350a
Add --no-editable support to uv sync and uv export (#7371)
## Summary

Closes https://github.com/astral-sh/uv/issues/5792.
2024-09-17 14:50:36 +00:00
Charlie Marsh
c87ce7aaf8
Run cargo upgrade (#7448)
Co-authored-by: konstin <konstin@mailbox.org>
2024-09-17 12:39:58 +02:00
bluss
e9378be919
Generate shell completion for uvx (#7388)
## Summary

Generate shell completion for uvx.

Create a `uvx` toplevel command just for completion by combining `uv
tool uvx` (hidden alias for `uv tool run`) with global arguments. This
explicit combination is needed otherwise global arguments are missing
(if they are missing, clap debug assertions fail when `uv tool run`
arguments refer to global arguments in directives like conflicts with).


Fixes #7258 

## Test Plan

- Tested using bash using `eval "$(cargo run --bin uv
generate-shell-completion bash)"`
2024-09-17 03:27:19 +00:00
Charlie Marsh
5f2e536925
Add support for --only-dev to uv sync and uv export (#7367)
## Summary

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

Closes https://github.com/astral-sh/uv/issues/6472.
2024-09-16 20:06:20 +00:00
Nathan McDougall
f82224124e
Fix grammatical error in CLI docs (#7353)
Fixing a grammatical error in the CLI docs, namely `in adhere with` ->
`in adherence with`.
2024-09-13 15:51:59 +00:00
Frost Ming
e1e85ab4c8
feat(cli): add --token option to self update command (#7279)
<!--
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

It often reaches the GitHub API rate limit and shows error like `error:
HTTP status client error (403 Forbidden) for url
(https://api.github.com/repos/astral-sh/uv/releases)` when running `uv
self update`.

To bypass this rate limit issue, allow user to pass a GitHub token via
`--token` or `UV_GITHUB_TOKEN` env.

## Test Plan

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

---------

Signed-off-by: Frost Ming <me@frostming.com>
2024-09-12 14:27:54 -05:00
Aditya Pratap Singh
adcb67a882
Fix documentation typos for uv build --build-constraint flag (#7330)
Summary

This pull request fixes a typo in the --build-constraints flag, which
should be singular (--build-constraint). This update ensures consistency
across the documentation and prevents potential confusion for users.

Closes #7315

## Test Plan
The change was verified by reviewing the relevant documentation files
where the flag is referenced. No functional code changes were made, so
no additional testing is required beyond confirming the documentation
update.

## Tested
The change was tested by visually inspecting the updated documentation
to confirm that the typo has been corrected
2024-09-12 14:07:33 -05:00
Charlie Marsh
3f011f3b7b
Add uv run --no-sync (#7192)
## Summary

When `--no-sync` is provided, we won't lock or sync, but we will run the
command in the project environment.

Closes https://github.com/astral-sh/uv/issues/7165.
2024-09-10 17:29:43 -04:00
Ahmed Ilyas
bbccee8bee
Allow setting a target version for uv self update (#7252)
## Summary

Resolves #6642 

## Test Plan

```console
❯ cargo build --bin uv --features self-update
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.78s
❯ cp target/debug/uv ~/.cargo/bin
❯ uv self update 0.3.4
info: Checking for updates...
success: Upgraded uv from v0.4.8 to v0.3.4! https://github.com/astral-sh/uv/releases/tag/0.3.4
❯ uv --version
uv 0.3.4 (39f3cd2a9 2024-08-26)
❯ cp target/debug/uv ~/.cargo/bin
❯ uv self update
info: Checking for updates...
success: Upgraded uv from v0.3.4 to v0.4.8! https://github.com/astral-sh/uv/releases/tag/0.4.8
❯ uv --version
uv 0.4.8 (956cadd1a 2024-09-09)
```
2024-09-10 13:35:31 +00:00
Mathieu Kniewallner
8341d810b2
docs: list supported sdist formats (#7168)
## Summary

Explicitly list the formats and extensions that uv supports, based on
[this
list](86ee8d2c01/crates/distribution-filename/src/extension.rs (L70-L77)).
Not a huge fan of adding the section in `concepts/resolution.md`, but I
did not find a better place. Alternatively we could maybe add a
dedicated page that shortly explains Python package types (wheels,
sdists), where such a section could live?

## Test Plan

Local run of the documentation.
2024-09-07 19:16:12 +00:00
Janosh Riebesell
e96eb946f9
Fix typo aaarch64->aarch64 (#7141)
copy pasted `--python-platform aaarch64-unknown-linux-gnu` [from the
docs](https://docs.astral.sh/uv/reference/cli/#uv-pip-compile) and got

> error: invalid value 'aaarch64-unknown-linux-gnu' for
'--python-platform <PYTHON_PLATFORM>'
> [possible values: windows, linux, macos, x86_64-pc-windows-msvc,
i686-pc-windows-msvc, x86_64-unknown-linux-gnu, aarch64-apple-darwin,
x86_64-apple-darwin, aarch64-unknown-linux-gnu,
aarch64-unknown-linux-musl, x86_64-unknown-linux-musl,
x86_64-manylinux_2_17, x86_64-manylinux_2_28, x86_64-manylinux_2_31,
aarch64-manylinux_2_17, aarch64-manylinux_2_28, aarch64-manylinux_2_31]
> 
>   tip: a similar value exists: 'aarch64-unknown-linux-gnu'
2024-09-06 23:25:46 +00:00
Zanie Blue
1422e18674
Fixup comment for export --output-file (#7111) 2024-09-05 20:18:39 -05:00
Charlie Marsh
6ae005b0d0
Add --no-emit-project and friends to uv export (#7110)
## Summary

Like `uv sync`, you can omit the current project (`--no-emit-project`),
a specific package (`--no-emit-package`), or the entire workspace
(`--no-emit-workspace`).

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

Closes #6995.
2024-09-06 01:01:46 +00:00
Charlie Marsh
d0f9016eda
Add --output-file to uv export (#7109)
## Summary

Closes https://github.com/astral-sh/uv/issues/7058.
2024-09-05 20:53:53 -04:00
Charlie Marsh
5b89734c85
Add --require-hashes and --verify-hashes to uv build (#7094) 2024-09-05 15:22:03 -04:00
Charlie Marsh
80f51cee06
Accept --build-constraints in uv build (#7085)
## Summary

Closes #7082.

Closes #7065.
2024-09-05 18:46:36 +00:00
Ahmed Ilyas
567e213cbb
Accept vec of packages in uv tool uninstall (#7077)
## Summary

Follow up
https://github.com/astral-sh/uv/pull/7037#discussion_r1744515370

## Test Plan

`cargo test`
2024-09-05 08:24:13 -04:00
eth3lbert
e7a7a813fb
Implement --show-version-specifiers for tool list (#7050)
## Summary

Closes #6747 .

## Test Plan

```
cargo test --test tool_list
```
2024-09-05 02:15:18 +00:00
Ahmed Ilyas
ff39950545
Allow multiple packages for uv tool upgrade/uninstall (#7037)
## Summary

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

## Test Plan

`cargo test`
2024-09-04 17:18:52 -04:00
Charlie Marsh
7aed94bed2
Add --package support to uv build (#6990)
## Summary

This PR adds `--package` support to `uv build`, such that you can use
`--package` from anywhere in a workspace to build any member.

If a source directory is provided, we use that as the workspace root.

If a file is provided, we error.

For now, `uv build` only builds the current package, making it
semantically identical to `uv sync`.
2024-09-04 15:52:21 +00:00
Charlie Marsh
5d8e99045a
Support uv build --wheel from source distributions (#6898)
## Summary

This PR allows users to run `uv build --wheel ./path/to/source.tar.gz`
to build a wheel from a source distribution. This is also the default
behavior if you run `uv build ./path/to/source.tar.gz`. If you pass
`--sdist`, we error.
2024-09-04 15:30:32 +00:00
Charlie Marsh
df84d25a7e
Implement uv build (#6895)
## Summary

This PR exposes uv's PEP 517 implementation via a `uv build` frontend,
such that you can use `uv build` to build source and binary
distributions (i.e., wheels and sdists) from a given directory.

There are some TODOs that I'll tackle in separate PRs:

- [x] Support building a wheel from a source distribution (rather than
from source) (#6898)
- [x] Stream the build output (#6912)

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

Closes https://github.com/astral-sh/uv/issues/1663.
2024-09-04 11:23:46 -04:00
Zanie Blue
1996067f81
Add note to extra and all-extras in uv sync help (#7013) 2024-09-04 15:05:21 +00: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
Andrew Gallant
d6a14464ab uv-cli: use PathBuf::from
Conversions from strings to paths are always infallible.
2024-09-03 18:41:15 -04:00
Zanie Blue
d87256bebe
Improve project handling in uv venv (#6835)
- Respect `UV_PROJECT_ENVIRONMENT` when in project root
- Add `--no-project` and `--no-workspace` to opt-out of above and
`requires-python` detection
- Rename `[NAME]` to `[PATH]` in CLI
2024-09-03 14:22:30 -05:00
Charlie Marsh
ccdf2d793b
Add --no-hashes to uv export (#6954)
## Summary

Closes https://github.com/astral-sh/uv/issues/6944.
2024-09-02 22:12:29 -04:00
Zanie Blue
97e6861b35
Fix uv init --no-project alias (#6837) 2024-08-29 17:40:19 -05:00
Andrew Gallant
9ea03ceb38
uv-cli: add worktree support to build.rs (#6825)
Previously, we were always asking Cargo to rebuild `uv-cli` if
`.git/HEAD` had changed. But in a worktree, `.git` is a file, not a
directory. And the file contains the path to git's internal worktree
state, which also has its own `HEAD` file. So in the case of a worktree,
we read the file and tell Cargo to watch the worktree-specific `HEAD`
file instead of `.git/head`.

The main thing this fixes is that, previously, in a worktree, `cargo
build` would *always* re-compile `uv` even if nothing changed.

This doesn't impact or fix anything in "typical" clones of uv though.
Only in worktrees.

Closes #6196, Closes #6197
2024-08-29 14:11:50 -04:00
Charlie Marsh
cbfc928a9c
Add uv export --format requirements.txt (#6778)
## Summary

The interface here is intentionally a bit more limited than `uv pip
compile`, because we don't want `requirements.txt` to be a system of
record -- it's just an export format. So, we don't write annotation
comments (i.e., which dependency is requested from which), we don't
allow writing extras, etc. It's just a flat list of requirements, with
their markers and hashes.

Closes #6007.

Closes #6668.

Closes #6670.
2024-08-29 17:46:42 +00:00
Ahmed Ilyas
9f0346592f
Add colors to the CLI help menu (#6280)
## Summary

Adds colors to the CLI output.

## Test Plan


<img width="526" alt="Screenshot 2024-08-21 at 00 06 40"
src="https://github.com/user-attachments/assets/88388272-659e-49d4-a641-83f64de55cf0">
<img width="879" alt="Screenshot 2024-08-21 at 00 06 57"
src="https://github.com/user-attachments/assets/26522bd3-c9cf-4359-a8d3-e5c9c72a54aa">
2024-08-28 11:43:52 -05:00
Charlie Marsh
cef3d35405
Support {package}@{version} in uv tool install (#6762)
## Summary

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

Closes https://github.com/astral-sh/uv/issues/6535.
2024-08-28 12:40:49 -04:00
Zanie Blue
bc5b069a61
Add --app and --lib options to uv init (#6689)
Changes the `uv init` experience with a focus on working for more
use-cases out of the box.

- Adds `--app` and `--lib` options to control the created project style
- Changes the default from a library with `src/` and a build backend
(`--lib`) to an application that is not packaged (`--app`)
- Hides the `--virtual` option and replaces it with `--package` and
`--no-package`
- `--no-package` is not allowed with `--lib` right now, but it could be
in the future once we understand a use-case
- Creates a runnable project
- Applications have a `hello.py` file which you can run with `uv run
hello.py`
- Packaged applications, e.g., `uv init --app --package` create a
package and script entrypoint, which you can run with `uv run hello`
- Libraries provide a demo API function, e.g., `uv run python -c "import
name; print(name.hello())"` — this is unchanged

Closes #6471
2024-08-27 18:08:09 +00:00