uv/crates/uv-pep508
John Mumm 2a66349e96
Check if relative URL is valid directory before treating as index (#13917)
As per #13874, passing a relative URL like `test` to `--index` for `uv
add` causes unexpected behavior if the directory does not exist. The
non-existent index is effectively ignored and uv falls back to PyPI. If
a package is found there, the spurious index is then written to
`pyproject.toml`. This doesn't happen for `--default-index` since
resolution will fail without fallback to PyPI.

This PR adds a validation step for indexes provided on the command line.
If a directory does not exist, uv will fail with an error.

Closes #13874
2025-06-09 19:28:39 +02:00
..
src Check if relative URL is valid directory before treating as index (#13917) 2025-06-09 19:28:39 +02:00
Cargo.toml Add DisplaySafeUrl newtype to prevent leaking of credentials by default (#13560) 2025-05-27 00:05:30 +02:00
Changelog.md Add uv- prefix to all internal crates (#7853) 2024-10-01 20:15:32 -04:00
License-Apache Add uv- prefix to all internal crates (#7853) 2024-10-01 20:15:32 -04:00
License-BSD Add uv- prefix to all internal crates (#7853) 2024-10-01 20:15:32 -04:00
Readme.md Use consistent commas around i.e. and e.g. (#12157) 2025-03-13 23:42:10 +00:00

Dependency specifiers (PEP 508) in Rust

Crates.io PyPI

A library for dependency specifiers, previously known as PEP 508.

Usage

use std::str::FromStr;
use pep508_rs::Requirement;

let marker = r#"requests [security,tests] >= 2.8.1, == 2.8.* ; python_version > "3.8""#;
let dependency_specification = Requirement::from_str(marker).unwrap();
assert_eq!(dependency_specification.name, "requests");
assert_eq!(dependency_specification.extras, Some(vec!["security".to_string(), "tests".to_string()]));

Markers

Markers allow you to install dependencies only in specific environments (python version, operating system, architecture, etc.) or when a specific feature is activated. E.g., you can say importlib-metadata ; python_version < "3.8" or itsdangerous (>=1.1.0) ; extra == 'security'. Unfortunately, the marker grammar has some oversights (e.g. https://github.com/pypa/packaging.python.org/pull/1181) and the design of comparisons (PEP 440 comparisons with lexicographic fallback) leads to confusing outcomes. This implementation tries to carefully validate everything and emit warnings whenever bogus comparisons with unintended semantics are made.