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.0.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-1.0.0-cp312-cp312-win_amd64.whl (251.8 kB view details)

Uploaded CPython 3.12Windows x86-64

pubgrub_py-1.0.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-1.0.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (397.4 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

pubgrub_py-1.0.0-cp312-cp312-macosx_11_0_arm64.whl (356.4 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pubgrub_py-1.0.0-cp312-cp312-macosx_10_12_x86_64.whl (364.1 kB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: pubgrub_py-1.0.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-1.0.0.tar.gz
Algorithm Hash digest
SHA256 69bc62a028d3aeeb12dd54a5a0330d29974331b5e50efec99ed44049a20468a7
MD5 023180cc75f8ab95099d1b075ac270f4
BLAKE2b-256 f51a1e4d87a0e9bf29d57f4007258b9c7851d4fa3b07f0c1c93c275c3a9ef0d1

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pubgrub_py-1.0.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 251.8 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.0.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 34ed29ec83acc1c4a0f0793f6b7208eb4fce50688338701fbca2b02426d156e0
MD5 5416f3b8d1f0429101618d5a724dd7ff
BLAKE2b-256 c94dd63f3d4c52cb9419132fd69fd5ea7a59231332871ec89b269c2b98af9616

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pubgrub_py-1.0.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9fd64c55a5df6bd4267c03904cc3eeab724a4aeeed9cd4b522e59cbc5ba73366
MD5 f6c32e44b1041a23eb9b8ff14b8218ce
BLAKE2b-256 971cee23231f9ae7025e3e874a4d91b4151f7c18696d8b89c3f4f8efbde99b27

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pubgrub_py-1.0.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 72136109f0b8be656759233dba9163a2448a6eb949b6d08da0dc7301a4453acf
MD5 01eb4191bbaa34898dd2707fb5ce16dc
BLAKE2b-256 50d7e3e52335b36d11a74a56df6ea94b5f582caafbdc3d21cd7cab0637f2da71

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pubgrub_py-1.0.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5e97d370777e9301d0ba379388655765b9364bc801ac83fd170fd054f397cd10
MD5 9bcf76cfae7e8a2882931d325d48330e
BLAKE2b-256 89b63d7fa84df9425d88158b524a05ad1e8317730df4db66a716d8c15577042c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pubgrub_py-1.0.0-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 330a163ebe44c083499320a4986e2222ff331dd6af5a5a088b7187341ad14b2e
MD5 be643103bb795a1c6a358cf71b623cdd
BLAKE2b-256 1083ff492fce33a7ca6fa5456c4151dc6f1427f0cdfc04159b66e7f38f1782bf

See more details on using hashes here.

Provenance

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