#python #pep #requirements #specifier #marker #validation #better

pep508_rs

A library for python dependency specifiers, better known as PEP 508

19 releases (7 breaking)

0.9.1 Oct 30, 2024
0.8.1 Oct 29, 2024
0.6.1 Jul 30, 2024
0.4.2 Feb 18, 2024
0.1.1 Mar 29, 2023

#341 in Development tools

Download history 22356/week @ 2024-08-22 21866/week @ 2024-08-29 24978/week @ 2024-09-05 21752/week @ 2024-09-12 21570/week @ 2024-09-19 21847/week @ 2024-09-26 20343/week @ 2024-10-03 23168/week @ 2024-10-10 22320/week @ 2024-10-17 19488/week @ 2024-10-24 18713/week @ 2024-10-31 21603/week @ 2024-11-07 22782/week @ 2024-11-14 24943/week @ 2024-11-21 26106/week @ 2024-11-28 19983/week @ 2024-12-05

97,815 downloads per month
Used in 10 crates (7 directly)

Apache-2.0 OR BSD-2-Clause

335KB
7K SLoC

Dependency specifiers (PEP 508) in Rust

Crates.io PyPI

A library for python dependency specifiers, better known as PEP 508.

Usage

In Rust

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.

Dependencies

~7.5–10MB
~168K SLoC