Dep-Logic Python Library
Dep-Logic is a Python library that provides a robust API for working with package version specifiers and dependencies, supporting logical operations (AND, OR) on them. It is currently at version 0.5.2 and sees active development with several releases per year.
Warnings
- breaking The primary import path for `Specifier` and `SpecifierSet` changed from `dep_logic.specifier` to `dep_logic` directly.
- breaking The `Dependency` API was significantly reworked. The `DependencySpecifier` class was removed, and `Dependency` now takes a `name` and `specifier` directly upon initialization.
- breaking The `specifier` attribute of `Dependency` objects became non-optional.
- gotcha Be aware of the difference between `&` (intersection/AND) and `|` (union/OR) for specifiers. Intersection requires a version to satisfy ALL combined conditions, while union requires it to satisfy ANY.
Install
-
pip install dep-logic
Imports
- Specifier
from dep_logic import Specifier
- SpecifierSet
from dep_logic import SpecifierSet
- Dependency
from dep_logic import Dependency
Quickstart
from dep_logic import Specifier, SpecifierSet, Dependency
# Define specifiers
spec1 = Specifier(">=1.0.0,<2.0.0")
spec2 = Specifier("~=1.5.0") # equivalent to >=1.5.0,==1.*,==1.5.*, <1.6.0 for a minor release
# Perform logical operations
combined_spec_and = spec1 & spec2 # Intersection
combined_spec_or = spec1 | spec2 # Union
print(f"Specifier 1: {spec1}")
print(f"Specifier 2: {spec2}")
print(f"Intersection (AND): {combined_spec_and}")
print(f"Union (OR): {combined_spec_or}")
# Check if a version satisfies a specifier
assert combined_spec_and.contains("1.5.2")
assert not combined_spec_and.contains("1.0.0")
# Define a dependency
my_dependency = Dependency("my_package", Specifier(">=1.0.0,<2.0.0"))
print(f"Dependency: {my_dependency}")