A library for python dependency specifiers, better known as PEP 508.
In Rust
```rust use std::str::FromStr; use pep508_rs::Requirement;
let marker = r#"requests [security,tests] >= 2.8.1, == 2.8.* ; pythonversion > "3.8""#; let dependencyspecification = Requirement::fromstr(marker).unwrap(); asserteq!(dependencyspecification.name, "requests"); asserteq!(dependencyspecification.extras, Some(vec!["security".tostring(), "tests".to_string()])); ```
In Python
```python from pep508_rs import Requirement
requests = Requirement( 'requests [security,tests] >= 2.8.1, == 2.8.* ; pythonversion > "3.8"' ) assert requests.name == "requests" assert requests.extras == ["security", "tests"] assert [str(i) for i in requests.versionor_url] == [">= 2.8.1", "== 2.8.*"] ```
Python bindings are built with maturin, but you can also use the normal pip install .
Version
and VersionSpecifier
from pep440_rs are reexported to avoid type mismatches.
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.
In python, warnings are by default sent to the normal python logging infrastructure:
```python from pep508_rs import Requirement, MarkerEnvironment
env = MarkerEnvironment.current() assert not Requirement("numpy; extra == 'science'").evaluatemarkers(env, []) assert Requirement("numpy; extra == 'science'").evaluatemarkers(env, ["science"]) assert not Requirement( "numpy; extra == 'science' and extra == 'arrays'" ).evaluatemarkers(env, ["science"]) assert Requirement( "numpy; extra == 'science' or extra == 'arrays'" ).evaluatemarkers(env, ["science"]) ```
```python from pep508_rs import Requirement, MarkerEnvironment
env = MarkerEnvironment.current() Requirement("numpy; pythonversion >= '3.9.'").evaluatemarkers(env, [])
3.9.
doesn't match PEP 440 rules"```