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-0.1.0.tar.gz (11.1 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-0.1.0-cp312-cp312-win_amd64.whl (251.4 kB view details)

Uploaded CPython 3.12Windows x86-64

pubgrub_py-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (409.0 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

pubgrub_py-0.1.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (397.2 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

pubgrub_py-0.1.0-cp312-cp312-macosx_11_0_arm64.whl (356.3 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pubgrub_py-0.1.0-cp312-cp312-macosx_10_12_x86_64.whl (364.5 kB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for pubgrub_py-0.1.0.tar.gz
Algorithm Hash digest
SHA256 265a6f443a9579fb3431bb3b03c70b60a32a88dcdaf6aa13bf51faf970c7c768
MD5 b0de291e7517b484584d3fd4ebf06ef5
BLAKE2b-256 25769198abce44e61a6d70b67b436380f49ab1570d28654c27466fc2deab9a69

See more details on using hashes here.

Provenance

The following attestation bundles were made for pubgrub_py-0.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-0.1.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: pubgrub_py-0.1.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 251.4 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-0.1.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 bcadd6a7af805517d378575f1def26f0ab79a5db88d249b138d7865b251bb147
MD5 1bf473412ff1ac777f91c6b9f4a56fe4
BLAKE2b-256 ac947798f9dac0210857c5259fbc37d8a8fd37c9fa9ec49d38c99aa8cd34c1a1

See more details on using hashes here.

Provenance

The following attestation bundles were made for pubgrub_py-0.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-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pubgrub_py-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e5d43cec0b6b18b57ed8cc031af86d9c1255ceb060b981ab1ab7afe641f4582d
MD5 d8adb3350342f432cd7ba5b88d60bf19
BLAKE2b-256 2f8db1f480b431f3b194e23587d8d2ab27ac2dce86196ed7dae3c58dacc38d6d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pubgrub_py-0.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-0.1.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pubgrub_py-0.1.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 8e63888877dc6e03de3d46c1f9151fb117626327b74e01a9fd7eec99ab0ddb83
MD5 fbb3efdeb5bc7c47abc9f8d25e8186a8
BLAKE2b-256 968ee626daaca40a006095a1cad0ce2d9b71e69326a605462f81a23a5b875275

See more details on using hashes here.

Provenance

The following attestation bundles were made for pubgrub_py-0.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-0.1.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pubgrub_py-0.1.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4d614ed08d8589fed1207f0c74c622acb1344038143a064257135ad269eed105
MD5 d12ca7eeb3a72e3cc2c065265efa54f1
BLAKE2b-256 74491a350def9b309bf62ea0d82a8a9089b707a3373da8e71e143e534fb0e0c2

See more details on using hashes here.

Provenance

The following attestation bundles were made for pubgrub_py-0.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-0.1.0-cp312-cp312-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for pubgrub_py-0.1.0-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 73eba11f8d6f128c356ed1948c5371020ca0cbdd4520b08a7cc3790fb30ee635
MD5 b204cce1a1cc611ac7117c3502a21217
BLAKE2b-256 49d423d024717e020991b5da5438b2d1a7ee078888e3aabf5a89e51898f18dcc

See more details on using hashes here.

Provenance

The following attestation bundles were made for pubgrub_py-0.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