astral-uv:zanie/validate-package-name

Last commit made on 2023-11-01
Get this branch:
git clone -b zanie/validate-package-name https://git.launchpad.net/astral-uv

Branch merges

Branch information

Name:
zanie/validate-package-name
Repository:
lp:astral-uv

Recent commits

ac906c6... by Zanie <email address hidden>

Add `PackageName::validate`

3d5f824... by Zanie Blue <email address hidden>

Add validation of extra names (#257)

Extends #254

Adds validation of extra names provided by users in `pip-compile` e.g.

```
error: invalid value 'foo!' for '--extra <EXTRA>': Extra names must start and end with a
letter or digit and may only contain -, _, ., and alphanumeric characters
```

We'll want to add something similar to `PackageName`. I'd be curious to
improve the AP, making the unvalidated nature of `::normalize` clear?
Perhaps worth pursuing later though as I don't have a better idea.

2652caa... by Charlie Marsh <email address hidden>

Add support for URL dependencies (#251)

## Summary

This PR adds support for resolving and installing dependencies via
direct URLs, like:

```
werkzeug @ https://files.pythonhosted.org/packages/ff/1d/960bb4017c68674a1cb099534840f18d3def3ce44aed12b5ed8b78e0153e/Werkzeug-2.0.0-py3-none-any.whl
```

These are fairly common (e.g., with `torch`), but you most often see
them as Git dependencies.

Broadly, structs like `RemoteDistribution` and friends are now enums
that can represent either registry-based dependencies or URL-based
dependencies:

```rust
/// A built distribution (wheel) that exists as a remote file (e.g., on `PyPI`).
#[derive(Debug, Clone)]
#[allow(clippy::large_enum_variant)]
pub enum RemoteDistribution {
    /// The distribution exists in a registry, like `PyPI`.
    Registry(PackageName, Version, File),
    /// The distribution exists at an arbitrary URL.
    Url(PackageName, Url),
}
```

In the resolver, we now allow packages to take on an extra, optional
`Url` field:

```rust
#[derive(Debug, Clone, Eq, Derivative)]
#[derivative(PartialEq, Hash)]
pub enum PubGrubPackage {
    Root,
    Package(
        PackageName,
        Option<DistInfoName>,
        #[derivative(PartialEq = "ignore")]
        #[derivative(PartialOrd = "ignore")]
        #[derivative(Hash = "ignore")]
        Option<Url>,
    ),
}
```

However, for the purpose of version satisfaction, we ignore the URL.
This allows for the URL dependency to satisfy the transitive request in
cases like:

```
flask==3.0.0
werkzeug @ https://files.pythonhosted.org/packages/c3/fc/254c3e9b5feb89ff5b9076a23218dafbc99c96ac5941e900b71206e6313b/werkzeug-3.0.1-py3-none-any.whl
```

There are a couple limitations in the current approach:

- The caching for remote URLs is done separately in the resolver vs. the
installer. I decided not to sweat this too much... We need to figure out
caching holistically.
- We don't support any sort of time-based cache for remote URLs -- they
just exist forever. This will be a problem for URL dependencies, where
we need some way to evict and refresh them. But I've deferred it for
now.
- I think I need to redo how this is modeled in the resolver, because
right now, we don't detect a variety of invalid cases, e.g., providing
two different URLs for a dependency, asking for a URL dependency and a
_different version_ of the same dependency in the list of first-party
dependencies, etc.
- (We don't yet support VCS dependencies.)

fa9f8df... by Zanie Blue <email address hidden>

Fix test snapshot filter when runtime is greater than 1s (#267)

Tests would sometimes flake with this locally e.g. "1.50s" was not
filtered correctly.

Verified with

```diff
diff --git a/crates/puffin-cli/src/commands/pip_compile.rs b/crates/puffin-cli/src/commands/pip_compile.rs
index 0193216..2d6f8af 100644
--- a/crates/puffin-cli/src/commands/pip_compile.rs
+++ b/crates/puffin-cli/src/commands/pip_compile.rs
@@ -150,6 +150,8 @@ pub(crate) async fn pip_compile(
         result => result,
     }?;

+ std::thread::sleep(std::time::Duration::from_secs(1));
+
     let s = if resolution.len() == 1 { "" } else { "s" };
     writeln!(
         printer,
```

079b685... by Charlie Marsh <email address hidden>

Use distributions for `Reporter` signatures (#266)

bee1b0f... by Charlie Marsh <email address hidden>

Avoid re-parsing wheel filename in source distribution tree (#265)

aff26f2... by Charlie Marsh <email address hidden>

Reuse distribution structs in Resolver's `source_distribution.rs` (#264)

4be9ba4... by Zanie Blue <email address hidden>

Remove implicit clone from `ExtraName` and document requirement in `PackageName` (#262)

per discussion in #137

https://discord.com/channels/1039017663004942429/1148719284013510676/1169000261746962473

0dc7e63... by Zanie Blue <email address hidden>

Default to `puffin venv` path to `.venv` (#261)

Closes https://github.com/astral-sh/puffin/issues/236

e00d208... by Zanie Blue <email address hidden>

Add documentation to `PackageName::normalize` (#263)