Skip to main content

Python bindings for the PubGrub version resolution algorithm

Project description

pubgrub-py

Python bindings for the PubGrub version resolution algorithm.

PubGrub is the dependency resolution algorithm used by Dart's pub package manager, and this library provides Python access to the Rust implementation for high-performance dependency resolution.

Installation

pip install pubgrub-py

Or with maturin for development:

cd packages/pubgrub-py
maturin develop

Usage

Simple API

from pubgrub_py import resolve

# Define available packages with their versions and dependencies
available = {
    "app": {
        "1.0.0": {"lib-a": ">=1.0.0", "lib-b": ">=2.0.0"},
    },
    "lib-a": {
        "1.0.0": {},
        "1.1.0": {"shared": ">=1.0.0"},
    },
    "lib-b": {
        "2.0.0": {"shared": ">=1.0.0"},
        "2.1.0": {"shared": ">=1.5.0"},
    },
    "shared": {
        "1.0.0": {},
        "1.5.0": {},
        "2.0.0": {},
    },
}

# Resolve dependencies
result = resolve(
    requirements={"app": ">=1.0.0"},
    available=available,
)
# Returns: {"app": "1.0.0", "lib-a": "1.1.0", "lib-b": "2.1.0", "shared": "2.0.0"}

Resolver Class API

For more control, use the Resolver class directly:

from pubgrub_py import Resolver, ResolutionError

resolver = Resolver()

# Add packages one by one
resolver.add_package("app", "1.0.0", {"lib": ">=1.0.0"})
resolver.add_package("lib", "1.0.0", {})
resolver.add_package("lib", "2.0.0", {})

# Resolve
try:
    result = resolver.resolve({"app": ">=1.0.0"})
    print(result)  # {"app": "1.0.0", "lib": "2.0.0"}
except ResolutionError as e:
    print(f"Resolution failed: {e}")

Version Constraint Syntax

This library supports PEP 440 version specifiers:

Operator Example Meaning
>= >=1.0.0 Greater than or equal
<= <=2.0.0 Less than or equal
> >1.0.0 Greater than
< <2.0.0 Less than
== ==1.5.0 Exact match
!= !=1.3.0 Not equal
~= ~=1.4.0 Compatible release (>=1.4.0,<1.5.0)

Combined constraints are separated by commas: >=1.0.0,<2.0.0

Error Handling

When resolution fails, ResolutionError is raised with a human-readable explanation:

from pubgrub_py import resolve, ResolutionError

try:
    resolve(
        requirements={"a": ">=1.0.0", "b": ">=1.0.0"},
        available={
            "a": {"1.0.0": {"shared": ">=2.0.0"}},
            "b": {"1.0.0": {"shared": "<2.0.0"}},
            "shared": {"1.0.0": {}, "2.0.0": {}},
        },
    )
except ResolutionError as e:
    print(e)
    # Output explains the conflict:
    # "Because a 1.0.0 depends on shared >=2.0.0
    #  and b 1.0.0 depends on shared <2.0.0,
    #  a 1.0.0 and b 1.0.0 are incompatible."

Development

Building

# Install maturin
pip install maturin

# Build and install in development mode
cd packages/pubgrub-py
maturin develop

# Build release wheel
maturin build --release

Testing

# Run Python tests
pytest tests/

# Run Rust tests
cargo test

License

MIT

Project details


Download files

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

Source Distribution

pubgrub_py-1.1.0.tar.gz (11.5 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pubgrub_py-1.1.0-cp312-cp312-win_amd64.whl (253.0 kB view details)

Uploaded CPython 3.12Windows x86-64

pubgrub_py-1.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (410.2 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

pubgrub_py-1.1.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (398.6 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

pubgrub_py-1.1.0-cp312-cp312-macosx_11_0_arm64.whl (357.3 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pubgrub_py-1.1.0-cp312-cp312-macosx_10_12_x86_64.whl (365.6 kB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

File details

Details for the file pubgrub_py-1.1.0.tar.gz.

File metadata

  • Download URL: pubgrub_py-1.1.0.tar.gz
  • Upload date:
  • Size: 11.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pubgrub_py-1.1.0.tar.gz
Algorithm Hash digest
SHA256 bd9efb1b3152262ae5790cf07ca2ef5ccc83c13f26719223952505f7c015e492
MD5 2e84afcede9848437f41cb07b6f6761b
BLAKE2b-256 2a069632c46b33e23bd852fe3b718e4434477f0024fe8f36aa84cdaae8828c75

See more details on using hashes here.

Provenance

The following attestation bundles were made for pubgrub_py-1.1.0.tar.gz:

Publisher: release.yml on YassinCh/pubgrub-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pubgrub_py-1.1.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: pubgrub_py-1.1.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 253.0 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pubgrub_py-1.1.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 a41ad1259d21688728213ab0054eae7f8f2cfdc5bd13ebc9b39a60cfc3c188f9
MD5 925e7983065379b4eea906934689088d
BLAKE2b-256 d5d31c5dd85ce2d8c84ea88f3278ec96999527af3b439e2bc93a6482d29c6480

See more details on using hashes here.

Provenance

The following attestation bundles were made for pubgrub_py-1.1.0-cp312-cp312-win_amd64.whl:

Publisher: release.yml on YassinCh/pubgrub-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pubgrub_py-1.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pubgrub_py-1.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 daf69cedc85f08ff8315c42afd01f3ee5ccdc4ef31d5d3c6458b424fe509afd3
MD5 f2958ce34414e7cc887e1cd9e35df090
BLAKE2b-256 a67a2aa052a3407d0b476534dce3399ef5d1e0b2e03ce8b41c5c5b6243356c6c

See more details on using hashes here.

Provenance

The following attestation bundles were made for pubgrub_py-1.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on YassinCh/pubgrub-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pubgrub_py-1.1.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pubgrub_py-1.1.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 299ce62cf23c8a4c37a7b7b496e9f41641c0d700e37057b51982c97b4e56c3b3
MD5 30eff44a595a3bbd8c6cece452b60ce9
BLAKE2b-256 b21fcedd2c4c68a7905b17af1bb4969f3ca980197239618adff2ed26365aaaf7

See more details on using hashes here.

Provenance

The following attestation bundles were made for pubgrub_py-1.1.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on YassinCh/pubgrub-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pubgrub_py-1.1.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pubgrub_py-1.1.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 effcd01962189a43943b5a6f6e85721d95a6ba09be498d51d4d53bfe546b62af
MD5 30c556ac147a8e06bf90a41bb1b3b1c4
BLAKE2b-256 e2fc242bfd3ffece12bd9a4b6ac575a379bcd7735e326826e79a0f2720ef3ad7

See more details on using hashes here.

Provenance

The following attestation bundles were made for pubgrub_py-1.1.0-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: release.yml on YassinCh/pubgrub-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pubgrub_py-1.1.0-cp312-cp312-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for pubgrub_py-1.1.0-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 f42545f6f3edffa8106d17b57a17ec78a5450a1af38d6b42bd1d68cf0c1cc6bf
MD5 89cc35372ec7ebf2afb69551c0aad0d1
BLAKE2b-256 43060364cbd741121d7388b935cf932d9ea3b724aa893ca6bb73c09bfcde34df

See more details on using hashes here.

Provenance

The following attestation bundles were made for pubgrub_py-1.1.0-cp312-cp312-macosx_10_12_x86_64.whl:

Publisher: release.yml on YassinCh/pubgrub-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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