Commit graph

272 commits

Author SHA1 Message Date
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
Charlie Marsh
9a6f455cbf
Run cargo dev generate-all (#7664)
A rebase somewhere let this slip by.
2024-09-24 17:19:10 +00: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
You Jiacheng
a235b7d70d
Clarify behavior of of overrides in CLI reference (#7537)
## Summary
Improve the description of override-dependencies based on the statement
in `concepts/resolution.md`: "As with constraints, overrides do not add
a dependency on the package and only take effect if the package is
requested in a direct or transitive dependency."

I tested it locally, `concepts/resolution.md` is correct. It would be
better to also include this in the Reference Chapter of the docs.
2024-09-19 07:02:42 -05: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
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
Mathieu Kniewallner
211fa91c2a
docs: separate project from configuration settings (#7053)
<!--
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

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

Settings documentation reference currently doesn't separate "project
metadata" and "configuration" options, implying that it's possible to
set things like `dev-dependencies` in `uv.toml` while it's not. This is
an attempt at better separating those options, by having 2 different
sections:
- `Project metadata`, that holds configuration that can only be set in
`pyproject.toml`
- `Configuration`, that holds configuration that can be set both in
`pyproject.toml` and `uv.toml`

Here are some screenshots to show what this looks like (note that I
don't have code highlighting in the right navigation, which makes them
clunky, as first item is always bigger because of the missing "span" --
I think that's because it's an `mkdocs-material` insider feature, since
I have the same thing on `main` branch):

- Right side navigation:

<img width="241" alt="Screenshot 2024-09-05 at 01 19 50"
src="https://github.com/user-attachments/assets/012f64a4-8d34-4e34-a506-8d02dc1fbf98">

<img width="223" alt="Screenshot 2024-09-05 at 01 20 01"
src="https://github.com/user-attachments/assets/0b0fb71d-c9c3-4ee3-8f6e-cf35180b1a99">

- An option from "Project metadata" section that only applies to
`pyproject.toml`:

<img width="788" alt="Screenshot 2024-09-05 at 01 20 11"
src="https://github.com/user-attachments/assets/64349fbb-8623-4b81-a475-d6ff38c658f1">

- An option from "Configuration" section that applies both to
`pyproject.toml` and `uv.toml`:

<img width="787" alt="Screenshot 2024-09-05 at 01 20 33"
src="https://github.com/user-attachments/assets/732e43d3-cc64-4f5a-8929-23a5555d4c53">

## Test Plan

Local run of the documentation.

Co-authored-by: Charlie Marsh <charlie.r.marsh@gmail.com>
2024-09-13 20:57:51 -04: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
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
58a157a0ad
Support globs as cache keys in tool.uv.cache-keys (#7268)
## Summary

This has been asked for a few times. There are risks that these checks
could be slow, but they're buyer-beware.

Closes https://github.com/astral-sh/uv/issues/7246.
2024-09-11 15:30:59 -04: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
Charlie Marsh
4f2349119c
Add support for dynamic cache keys (#7136)
## Summary

This PR adds a more flexible cache invalidation abstraction for uv, and
uses that new abstraction to improve support for dynamic metadata.

Specifically, instead of relying solely on a timestamp, we now pass
around a `CacheInfo` struct which (as of now) contains
`Option<Timestamp>` and `Option<Commit>`. The `CacheInfo` is saved in
`dist-info` as `uv_cache.json`, so we can test already-installed
distributions for cache validity (along with testing _cached_
distributions for cache validity).

Beyond the defaults (`pyproject.toml`, `setup.py`, and `setup.cfg`
changes), users can also specify additional cache keys, and it's easy
for us to extend support in the future. Right now, cache keys can either
be instructions to include the current commit (for `setuptools_scm` and
similar) or file paths (for `hatch-requirements-txt` and similar):

```toml
[tool.uv]
cache-keys = [{ file = "requirements.txt" }, { git = true }]
```

This change should be fully backwards compatible.

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

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

Closes https://github.com/astral-sh/uv/issues/6860.
2024-09-09 20:19:15 +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
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
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
eth3lbert
c667588524
Show env option in CLI reference documentation (#6863)
## Summary

Closes #6469.

<img width="721" alt="image"
src="https://github.com/user-attachments/assets/be144e43-e02f-473e-921c-91cf00c3c8d3">
2024-09-03 12:10:49 -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
Mathieu Kniewallner
fe5f085299
chore: run cargo dev generate-all on CI and locally (#6899)
## Summary

Noticed that running `cargo dev generate-all` on `main` produced changes
and saw that that the command is not run on the CI nor as a pre-commit
hook.

Not sure if having the command running as a pre-commit hook is something
we want, so I can remove it if you prefer. I find that nice to have as
it's probably easy to forget to run it, especially for new contributors
(and it will only run if there are changes in `uv_cli` or `uv_settings`
crates).

## Test Plan

- Added `cargo dev generate-all --mode check` on the CI, which produced
[this failing
job](2951669939)
- Ran `cargo dev generate-all` locally and committed the changes, which
produced [this succeeding
job](2951674494)
2024-08-31 19:03:53 -04: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
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
Zanie Blue
aad00d22e4
Fix up reference to environment markers in resolver reference (#6773) 2024-08-28 18:00:43 -04: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
Charlie Marsh
eb14056e9c
Add support for virtual projects (#6585)
## Summary

The basic idea here is: any project can either be a package, or not
("virtual").

If a project is virtual, we don't build or install it.

A project is virtual if either of the following are true:

- `tool.uv.virtual = true` is set.
- `[build-system]` is absent.

The concept of "virtual projects" only applies to workspace member right
now; it doesn't apply to `path` dependencies which are treated like
arbitrary Python source trees.

TODOs that should be resolved prior to merging:

- [ ] Documentation
- [ ] How do we reconcile this with "virtual workspace roots" which are
a little different -- they omit `[project]` entirely and don't even have
a name?
- [x] `uv init --virtual` should create a virtual project rather than a
virtual workspace.
- [x] Running `uv sync` in a virtual project after `uv init --virtual`
shows `Audited 0 packages in 0.01ms`, which is awkward. (See:
https://github.com/astral-sh/uv/pull/6588.)

Closes https://github.com/astral-sh/uv/issues/6511.
2024-08-27 13:42:46 -04: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
Mathieu Kniewallner
fd17f6d902
docs: use python to highlight requirements and use more content tabs (#6549)
## Summary

It appears that using `python` for code blocks containing requirements
works quite well.

![Screenshot from 2024-08-23
23-23-05](https://github.com/user-attachments/assets/38c92ef7-1f5e-40eb-8ea4-7024c8180bc4)

![Screenshot from 2024-08-23
23-23-31](https://github.com/user-attachments/assets/940dc7d5-22a8-4cd8-b54a-d56542d4345c)

Also using more content tabs for cases where we need to differentiate
macOS/Linux from Windows.

## Test Plan

Local run of the documentation.
2024-08-27 06:05:14 -05:00
Charlie Marsh
1ae2c3f142
Respect tool.uv.environments in pip compile --universal (#6663)
## Summary

We now respect the `environments` field in `uv pip compile --universal`,
e.g.:

```toml
[tool.uv]
environments = ["platform_system == 'Emscripten'"]
```

Closes https://github.com/astral-sh/uv/issues/6641.
2024-08-26 23:58:17 +00:00
Di-Is
154ea243d0
Add docs for constraint-dependencies and override-dependencies (#6596)
Add missing portions of documents reported in #6518 and #5248(Comment).

## Summary

<img width="600" alt="override"
src="https://github.com/user-attachments/assets/062f0036-8672-4c68-b21c-aebdeb79b58b">

<img width="600" alt="constraint"
src="https://github.com/user-attachments/assets/f5ef1aa2-0662-4352-a1a0-3af1127fb7fb">
2024-08-26 23:40:06 +00:00
Charlie Marsh
023acbe4b0
Avoid un-strict syncing by-default for build isolation (#6606)
## Summary

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

Closes https://github.com/astral-sh/uv/issues/6599.
2024-08-26 14:04:58 -04:00
Charlie Marsh
5b3e654dc9
Show --editable on the uv add CLI (#6608)
## Summary

`false` is the default, so like other booleans, we should show the
non-default.
2024-08-25 15:01:39 +00:00
Zanie Blue
6cf5d13183
Include virtual environment interpreters in uv python find (#6521)
Previously, we excluded these and only looked at system interpreters.
However, it makes sense for this to match the typical Python discovery
experience. We could consider swapping the default... I'm not sure what
makes more sense. If we change the default (as written now) — this could
arguably be a breaking change.
2024-08-23 21:06:57 +00:00
Zanie Blue
d1cbcb30e3
Add uv sync --no-install-package to skip installation of specific packages (#6540)
Extends #6538 / #6539
See #4028

Allows excluding arbitrary packages from the sync.
2024-08-23 20:48:04 +00:00