Skip to main content

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

Project description

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()]));

In Python

from pep508_rs import Requirement

requests = Requirement(
    'requests [security,tests] >= 2.8.1, == 2.8.* ; python_version > "3.8"'
)
assert requests.name == "requests"
assert requests.extras == ["security", "tests"]
assert [str(i) for i in requests.version_or_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

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:

from pep508_rs import Requirement, MarkerEnvironment

env = MarkerEnvironment.current()
assert not Requirement("numpy; extra == 'science'").evaluate_markers(env, [])
assert Requirement("numpy; extra == 'science'").evaluate_markers(env, ["science"])
assert not Requirement(
    "numpy; extra == 'science' and extra == 'arrays'"
).evaluate_markers(env, ["science"])
assert Requirement(
    "numpy; extra == 'science' or extra == 'arrays'"
).evaluate_markers(env, ["science"])
from pep508_rs import Requirement, MarkerEnvironment

env = MarkerEnvironment.current()
Requirement("numpy; python_version >= '3.9.'").evaluate_markers(env, [])
# This will log: 
# "Expected PEP 440 version to compare with python_version, found '3.9.', "
# "evaluating to false: Version `3.9.` doesn't match PEP 440 rules"

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

pep508_rs-0.3.0-cp38-abi3-win_amd64.whl (1.0 MB view hashes)

Uploaded CPython 3.8+ Windows x86-64

pep508_rs-0.3.0-cp38-abi3-musllinux_1_2_x86_64.whl (1.3 MB view hashes)

Uploaded CPython 3.8+ musllinux: musl 1.2+ x86-64

pep508_rs-0.3.0-cp38-abi3-musllinux_1_2_i686.whl (1.3 MB view hashes)

Uploaded CPython 3.8+ musllinux: musl 1.2+ i686

pep508_rs-0.3.0-cp38-abi3-musllinux_1_2_armv7l.whl (1.5 MB view hashes)

Uploaded CPython 3.8+ musllinux: musl 1.2+ ARMv7l

pep508_rs-0.3.0-cp38-abi3-musllinux_1_2_aarch64.whl (1.5 MB view hashes)

Uploaded CPython 3.8+ musllinux: musl 1.2+ ARM64

pep508_rs-0.3.0-cp38-abi3-manylinux_2_34_x86_64.whl (1.2 MB view hashes)

Uploaded CPython 3.8+ manylinux: glibc 2.34+ x86-64

pep508_rs-0.3.0-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.5 MB view hashes)

Uploaded CPython 3.8+ manylinux: glibc 2.17+ s390x

pep508_rs-0.3.0-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.4 MB view hashes)

Uploaded CPython 3.8+ manylinux: glibc 2.17+ ppc64le

pep508_rs-0.3.0-cp38-abi3-manylinux_2_17_ppc64.manylinux2014_ppc64.whl (1.4 MB view hashes)

Uploaded CPython 3.8+ manylinux: glibc 2.17+ ppc64

pep508_rs-0.3.0-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.3 MB view hashes)

Uploaded CPython 3.8+ manylinux: glibc 2.17+ ARMv7l

pep508_rs-0.3.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.3 MB view hashes)

Uploaded CPython 3.8+ manylinux: glibc 2.17+ ARM64

pep508_rs-0.3.0-cp37-abi3-win_amd64.whl (1.0 MB view hashes)

Uploaded CPython 3.7+ Windows x86-64

pep508_rs-0.3.0-cp37-abi3-musllinux_1_2_x86_64.whl (1.3 MB view hashes)

Uploaded CPython 3.7+ musllinux: musl 1.2+ x86-64

pep508_rs-0.3.0-cp37-abi3-musllinux_1_2_i686.whl (1.3 MB view hashes)

Uploaded CPython 3.7+ musllinux: musl 1.2+ i686

pep508_rs-0.3.0-cp37-abi3-musllinux_1_2_armv7l.whl (1.3 MB view hashes)

Uploaded CPython 3.7+ musllinux: musl 1.2+ ARMv7l

pep508_rs-0.3.0-cp37-abi3-musllinux_1_2_aarch64.whl (1.2 MB view hashes)

Uploaded CPython 3.7+ musllinux: musl 1.2+ ARM64

pep508_rs-0.3.0-cp37-abi3-manylinux_2_34_x86_64.whl (1.2 MB view hashes)

Uploaded CPython 3.7+ manylinux: glibc 2.34+ x86-64

pep508_rs-0.3.0-cp37-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.3 MB view hashes)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ s390x

pep508_rs-0.3.0-cp37-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.2 MB view hashes)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ ppc64le

pep508_rs-0.3.0-cp37-abi3-manylinux_2_17_ppc64.manylinux2014_ppc64.whl (1.3 MB view hashes)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ ppc64

pep508_rs-0.3.0-cp37-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.0 MB view hashes)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ ARMv7l

pep508_rs-0.3.0-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.1 MB view hashes)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ ARM64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page