pkgcraft.dep package¶
Submodules¶
pkgcraft.dep.base module¶
- class pkgcraft.dep.base.Dependency(obj, eapi=None, /, set=DependencySetKind.Package)¶
Bases:
object
Dependency object.
- __init__(*args, **kwargs)¶
- conditional¶
Return the conditional UseDep for a Dependency if it exists.
- evaluate(self, enabled=())¶
Evaluate a Dependency using a given set of enabled options or by force.
- iter_conditionals(self)¶
Iterate over the conditionals of a Dependency.
- iter_flatten(self)¶
Iterate over the objects of a flattened Dependency.
- iter_recursive(self)¶
Recursively iterate over the Dependency objects of a Dependency.
- kind¶
- classmethod license(s=None)¶
Parse a string into a LICENSE dependency.
- classmethod package(s=None, eapi=None)¶
Parse a string into a package dependency.
- classmethod properties(s=None)¶
Parse a string into a PROPERTIES dependency.
- classmethod required_use(s=None)¶
Parse a string into a REQUIRED_USE dependency.
- classmethod restrict(s=None)¶
Parse a string into a RESTRICT dependency.
- set¶
- sort(self)¶
Recursively sort a Dependency.
>>> from pkgcraft.dep import Dependency >>> d = Dependency('( a/c a/b )') >>> str(d) '( a/c a/b )' >>> d.sort() >>> str(d) '( a/b a/c )'
- classmethod src_uri(s=None)¶
Parse a string into a SRC_URI dependency.
- class pkgcraft.dep.base.DependencyKind(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)¶
Bases:
IntEnum
- Enabled = 0¶
- Disabled = 1¶
- AllOf = 2¶
- AnyOf = 3¶
- ExactlyOneOf = 4¶
- AtMostOneOf = 5¶
- Conditional = 6¶
- class pkgcraft.dep.base.DependencySet(obj=None, eapi=None, /, set=DependencySetKind.Package)¶
Bases:
object
Immutable set of dependency objects.
- __init__(*args, **kwargs)¶
- difference(self, *others)¶
- evaluate(self, enabled=())¶
Evaluate a DependencySet using a given set of enabled options or by force.
- intersection(self, *others)¶
- isdisjoint(self, other)¶
- issubset(self, other)¶
- issuperset(self, other)¶
- iter_conditionals(self)¶
Iterate over the conditionals of a DependencySet.
- iter_flatten(self)¶
Iterate over the objects of a flattened DependencySet.
- iter_recursive(self)¶
Recursively iterate over the Dependency objects of a DependencySet.
- classmethod license(s=None)¶
Parse a string into a LICENSE dependency set.
- classmethod package(s=None, eapi=None)¶
Parse a string into a package dependency set.
- classmethod properties(s=None)¶
Parse a string into a PROPERTIES dependency set.
- classmethod required_use(s=None)¶
Parse a string into a REQUIRED_USE dependency set.
- classmethod restrict(s=None)¶
Parse a string into a RESTRICT dependency set.
- set¶
- classmethod src_uri(s=None)¶
Parse a string into a SRC_URI dependency set.
- symmetric_difference(self, *others)¶
- union(self, *others)¶
- class pkgcraft.dep.base.DependencySetKind(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)¶
Bases:
IntEnum
- Package = 0¶
- License = 2¶
- Properties = 3¶
- RequiredUse = 4¶
- Restrict = 5¶
- SrcUri = 1¶
- class pkgcraft.dep.base.MutableDependencySet¶
Bases:
DependencySet
Mutable set of dependency objects.
- add(self, elem)¶
- clear(self)¶
- difference_update(self, *others)¶
- discard(self, elem)¶
- intersection_update(self, *others)¶
- pop(self)¶
- remove(self, elem)¶
- sort(self)¶
Sort a DependencySet.
>>> from pkgcraft.dep import MutableDependencySet >>> d = MutableDependencySet('a/c a/b') >>> str(d) 'a/c a/b' >>> d.sort() >>> str(d) 'a/b a/c'
Dependency objects are ordered by type and sorted if possible.
>>> d = MutableDependencySet('( a/c a/b ( b/d b/c ) ) || ( a/c a/b ) a/z') >>> d.sort() >>> str(d) 'a/z ( a/c a/b ( b/d b/c ) ) || ( a/c a/b )'
- sort_recursive(self)¶
Recursively sort a DependencySet.
>>> from pkgcraft.dep import MutableDependencySet >>> d = MutableDependencySet('a/c a/b') >>> str(d) 'a/c a/b' >>> d.sort_recursive() >>> str(d) 'a/b a/c'
Dependency objects are ordered by type and recursively sorted if possible.
>>> d = MutableDependencySet('( a/c a/b ( b/d b/c ) ) || ( a/c a/b ) a/z') >>> d.sort_recursive() >>> str(d) 'a/z ( a/b a/c ( b/c b/d ) ) || ( a/c a/b )'
- symmetric_difference_update(self, *others)¶
- update(self, *others)¶
pkgcraft.dep.cpn module¶
- class pkgcraft.dep.cpn.Cpn(unicode s: str)¶
Bases:
object
Unversioned package.
- __init__()¶
Create a new Cpn object.
Valid:
>>> from pkgcraft.dep import Cpn >>> cpn = Cpn('cat/pkg') >>> cpn.category 'cat' >>> cpn.package 'pkg'
Invalid:
>>> Cpn('>cat/pkg-1') Traceback (most recent call last): ... pkgcraft.error.InvalidCpn: parsing failure: invalid cpn: >cat/pkg-1 ...
- category¶
Get the category of a Cpn.
- Returns:
the category name
- Return type:
>>> from pkgcraft.dep import Cpn >>> cpn = Cpn('cat/pkg') >>> cpn.category 'cat'
- matches(r)¶
Determine if a restriction matches a Cpn.
- Parameters:
r (Restrict) – restriction object to match against
- Returns:
True if matching, otherwise False.
- Return type:
- package¶
Get the package name of a Cpn.
- Returns:
the package name
- Return type:
>>> from pkgcraft.dep import Cpn >>> cpn = Cpn('cat/pkg') >>> cpn.package 'pkg'
- static parse(s, raised=False)¶
Determine if a string is a valid package Cpn.
This avoids any allocations, only returning the validity status.
- Parameters:
s (
str
) – the string to parseraised – if True, raise an exception when invalid
- Returns:
True if the given string represents a valid Cpn, otherwise False.
- Return type:
- Raises:
InvalidCpn – on failure if the raised parameter is set to True
>>> from pkgcraft.dep import Cpn >>> Cpn.parse('cat/pkg') True
pkgcraft.dep.cpv module¶
- class pkgcraft.dep.cpv.Cpv(unicode s: str)¶
Bases:
object
Category and package version object support.
- __init__()¶
Create a new Cpv object.
Valid:
>>> from pkgcraft.dep import Cpv >>> cpv = Cpv('cat/pkg-1-r2') >>> cpv.category 'cat' >>> cpv.package 'pkg' >>> str(cpv.version) '1-r2'
Invalid:
>>> Cpv('>cat/pkg-1') Traceback (most recent call last): ... pkgcraft.error.InvalidCpv: parsing failure: invalid cpv: >cat/pkg-1 ...
- category¶
Get the category of a Cpv.
- Returns:
the category name
- Return type:
>>> from pkgcraft.dep import Cpv >>> cpv = Cpv('cat/pkg-1-r2') >>> cpv.category 'cat'
- cpn¶
Get the Cpn of a Cpv.
>>> from pkgcraft.dep import Cpv >>> cpv = Cpv('cat/pkg-1-r2') >>> str(cpv.cpn) 'cat/pkg'
- intersects(self, other)¶
Determine if a Cpv intersects with another object.
- Parameters:
other – object to check for intersection against
- Returns:
True if intersecting, otherwise False.
- Return type:
- Raises:
TypeError – for unsupported types
>>> from pkgcraft.dep import Cpv, Dep >>> cpv = Cpv('cat/pkg-2-r1') >>> dep = Dep('>cat/pkg-1') >>> cpv.intersects(dep) and dep.intersects(cpv) True
- matches(r)¶
Determine if a restriction matches a Cpv.
- Parameters:
r (Restrict) – restriction object to match against
- Returns:
True if matching, otherwise False.
- Return type:
- p¶
Get the package and revision of a Cpv.
>>> from pkgcraft.dep import Cpv >>> cpv = Cpv('cat/pkg-1-r2') >>> cpv.p 'pkg-1'
- package¶
Get the package name of a Cpv.
- Returns:
the package name
- Return type:
>>> from pkgcraft.dep import Cpv >>> cpv = Cpv('cat/pkg-1-r2') >>> cpv.package 'pkg'
- static parse(s, raised=False)¶
Determine if a string is a valid package Cpv.
This avoids any allocations, only returning the validity status.
- Parameters:
s (
str
) – the string to parseraised – if True, raise an exception when invalid
- Returns:
True if the given string represents a valid Cpv, otherwise False.
- Return type:
- Raises:
InvalidCpv – on failure if the raised parameter is set to True
>>> from pkgcraft.dep import Cpv >>> Cpv.parse('cat/pkg-1') True
- pf¶
Get the package, version, and revision of a Cpv.
>>> from pkgcraft.dep import Cpv >>> cpv = Cpv('cat/pkg-1-r2') >>> cpv.pf 'pkg-1-r2' >>> cpv = Cpv('cat/pkg-1-r0') >>> cpv.pf 'pkg-1-r0' >>> cpv = Cpv('cat/pkg-1') >>> cpv.pf 'pkg-1'
- pr¶
Get the revision of a Cpv.
>>> from pkgcraft.dep import Cpv >>> cpv = Cpv('cat/pkg-1-r2') >>> cpv.pr 'r2' >>> cpv = Cpv('cat/pkg-1-r0') >>> cpv.pr 'r0' >>> cpv = Cpv('cat/pkg-1') >>> cpv.pr 'r0'
- pv¶
Get the version of a Cpv.
>>> from pkgcraft.dep import Cpv >>> cpv = Cpv('cat/pkg-1-r2') >>> cpv.pv '1' >>> cpv = Cpv('cat/pkg-1-r0') >>> cpv.pv '1' >>> cpv = Cpv('cat/pkg-1') >>> cpv.pv '1'
- pvr¶
Get the version and revision of a Cpv.
>>> from pkgcraft.dep import Cpv >>> cpv = Cpv('cat/pkg-1-r2') >>> cpv.pvr '1-r2' >>> cpv = Cpv('cat/pkg-1-r0') >>> cpv.pvr '1-r0' >>> cpv = Cpv('cat/pkg-1') >>> cpv.pvr '1'
- revision¶
Get the revision of a Cpv.
- Returns:
The revision if it exists or None.
- Return type:
Revision | None
>>> from pkgcraft.dep import Cpv >>> cpv = Cpv('cat/pkg-1-r2') >>> str(cpv.revision) '2' >>> cpv = Cpv('cat/pkg-1-r0') >>> str(cpv.revision) '0' >>> cpv = Cpv('cat/pkg-1') >>> cpv.revision is None True
- version¶
Get the version of a Cpv.
- Returns:
the version object
- Return type:
>>> from pkgcraft.dep import Cpv >>> cpv = Cpv('cat/pkg-1-r2') >>> str(cpv.version) '1-r2'
- with_op(self, op)¶
Create a Dep from a Cpv by applying a version operator.
- Parameters:
- Returns:
the newly created Dep
- Return type:
- Raises:
PkgcraftError – for invalid operator arguments
>>> from pkgcraft.dep import Cpv, Operator >>> cpv = Cpv('cat/pkg-1-r2')
String-based operator
>>> str(cpv.with_op('>=')) '>=cat/pkg-1-r2'
Enum-based operator
>>> str(cpv.with_op(Operator.Less)) '<cat/pkg-1-r2'
Invalid operator
>>> cpv.with_op(Operator.Approximate) Traceback (most recent call last): ... pkgcraft.error.PkgcraftError: ~ version operator can't be used with a revision
pkgcraft.dep.pkg module¶
- class pkgcraft.dep.pkg.Blocker(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)¶
Bases:
IntEnum
Package dependency blocker.
- static from_str(s)¶
- Strong = 1¶
- Weak = 2¶
- class pkgcraft.dep.pkg.Dep(unicode s: str, eapi=None, /)¶
Bases:
object
Package dependency.
- __init__()¶
Create a new package dependency.
- Parameters:
s – the package dependency string to parse
eapi – an
Eapi
constant or string identifier
- Returns:
the created package dependency instance
- Return type:
- Raises:
InvalidDep – on parsing failure
Valid
>>> from pkgcraft.dep import Dep >>> dep = Dep('=cat/pkg-1-r2:0/2::repo[a,b]') >>> dep.category 'cat' >>> dep.package 'pkg' >>> str(dep.version) '=1-r2' >>> str(dep.revision) '2' >>> dep.slot '0' >>> dep.subslot '2' >>> list(map(str, dep.use_deps)) ['a', 'b'] >>> dep.repo 'repo'
Invalid
>>> Dep('cat/pkg-1') Traceback (most recent call last): ... pkgcraft.error.InvalidDep: parsing failure: invalid dep: cat/pkg-1 ...
- blocker¶
Get the blocker of a package dependency.
- Returns:
The blocker if it exists or None.
- Return type:
Blocker | None
>>> from pkgcraft.dep import Blocker, Dep >>> dep = Dep('cat/pkg') >>> dep.blocker is None True >>> dep = Dep('!cat/pkg') >>> dep.blocker is Blocker.Weak True >>> dep = Dep('!!cat/pkg') >>> dep.blocker is Blocker.Strong True >>> dep.blocker == '!!' True
- category¶
Get the category of a package dependency.
- Returns:
the category name
- Return type:
>>> from pkgcraft.dep import Dep >>> dep = Dep('=cat/pkg-1-r2') >>> dep.category 'cat'
- cpn¶
Get the Cpn of a package dependency.
>>> from pkgcraft.dep import Dep >>> dep = Dep('=cat/pkg-1-r2') >>> str(dep.cpn) 'cat/pkg' >>> dep = Dep('cat/pkg') >>> str(dep.cpn) 'cat/pkg'
- cpv¶
Get the Cpv of a package dependency if one exists.
>>> from pkgcraft.dep import Dep >>> dep = Dep('=cat/pkg-1-r2:3/4[a,!b?]') >>> str(dep.cpv) 'cat/pkg-1-r2' >>> dep = Dep('cat/pkg') >>> dep.cpv is None True
- intersects(self, other)¶
Determine if a Dep intersects with another object.
- Parameters:
other – object to check for intersection against
- Returns:
True if intersecting, otherwise False.
- Return type:
- Raises:
TypeError – for unsupported types
>>> from pkgcraft.dep import Cpv, Dep >>> cpv = Cpv('cat/pkg-2-r1') >>> dep = Dep('>cat/pkg-1') >>> cpv.intersects(dep) and dep.intersects(cpv) True
- matches(r)¶
Determine if a restriction matches a package dependency.
- Parameters:
r (Restrict) – restriction object to match against
- Returns:
True if matching, otherwise False.
- Return type:
- modify(**kwargs)¶
Return a new Dep modifying the given attributes.
- Parameters:
kwargs (
str
|None
) – The keyword arguments must be attribute names with their corresponding string values or None for removal. Supported attribute names include the following: category, package, blocker, version, slot_dep, use_deps, and repo. Note that removing the category or package attributes will fail.- Returns:
The package dependency with the specified modifications, if none occurred the instance is returned.
- Return type:
- Raises:
MemoryError – on failed allocation
ValueError – on invalid fields
InvalidDep – if package dependency creation fails
Adding attributes:
>>> from pkgcraft.dep import Dep >>> d = Dep('cat/pkg') >>> str(d.modify(version='>=1.2.3-r4')) '>=cat/pkg-1.2.3-r4' >>> str(d.modify(package='b', repo='repo')) 'cat/b::repo' >>> str(d.modify(version='~0.1', slot_dep='2/3=', use_deps='a,b,c', repo='test')) '~cat/pkg-0.1:2/3=::test[a,b,c]'
Adding and removing attributes:
>>> d = Dep('>=cat/pkg-1.2-r3:4/5[a,b]') >>> str(d.modify(use_deps=None, repo='test')) '>=cat/pkg-1.2-r3:4/5::test' >>> str(d.modify(slot_dep='3/4=', version=None)) 'cat/pkg:3/4=[a,b]'
- no_use_deps¶
Return a new Dep without USE dependencies.
>>> from pkgcraft.dep import Dep >>> dep = Dep('>=cat/pkg-1-r2:3/4[a,!b?]') >>> str(dep.no_use_deps) '>=cat/pkg-1-r2:3/4'
If the Dep is unmodified, the original object is returned.
>>> dep = Dep('>=cat/pkg-1-r2:3/4') >>> dep.no_use_deps is dep True
- op¶
Get the version operator of a package dependency.
- Returns:
The version operator if it exists or None.
- Return type:
Operator | None
>>> from pkgcraft.dep import Operator, Dep >>> dep = Dep('cat/pkg') >>> dep.op is None True >>> dep = Dep('>=cat/pkg-1') >>> dep.op is Operator.GreaterOrEqual True >>> dep.op == '>=' True
- package¶
Get the package name of a package dependency.
- Returns:
the package name
- Return type:
>>> from pkgcraft.dep import Dep >>> dep = Dep('=cat/pkg-1-r2') >>> dep.package 'pkg'
- static parse(s, eapi=None, raised=False)¶
Determine if a string is a valid package dependency.
This avoids any allocations, only returning the validity status.
- Parameters:
s (str) – the string to parse
eapi (Eapi | str) – an
Eapi
constant or string identifierraised (bool) – if True, raise an exception when invalid
- Returns:
True if the given string represents a valid Dep, otherwise False.
- Return type:
- Raises:
InvalidDep – on failure if the raised parameter is set to True
>>> from pkgcraft.dep import Dep >>> Dep.parse('=cat/pkg-1') True
- repo¶
Get the repo of a package dependency.
- Returns:
The repository if it exists or None.
- Return type:
str | None
>>> from pkgcraft.dep import Dep >>> dep = Dep('=cat/pkg-1-r2::repo') >>> dep.repo 'repo' >>> dep = Dep('=cat/pkg-1-r2') >>> dep.repo is None True
- revision¶
Get the revision of a package dependency.
- Returns:
The revision if it exists or None.
- Return type:
Revision | None
>>> from pkgcraft.dep import Dep >>> dep = Dep('=cat/pkg-1-r2') >>> str(dep.revision) '2' >>> dep = Dep('=cat/pkg-1-r0') >>> str(dep.revision) '0' >>> dep = Dep('cat/pkg') >>> dep.revision is None True
- slot¶
Get the slot of a package dependency.
- Returns:
The slot if it exists or None.
- Return type:
str | None
>>> from pkgcraft.dep import Dep >>> dep = Dep('=cat/pkg-1-r2:3/4') >>> dep.slot '3' >>> dep = Dep('=cat/pkg-1-r2') >>> dep.slot is None True
- slot_op¶
Get the slot operator of a package dependency.
- Returns:
The slot operator if it exists or None.
- Return type:
SlotOperator | None
>>> from pkgcraft.dep import Dep >>> dep = Dep('=cat/pkg-1-r2') >>> dep.slot_op is None True >>> dep = Dep('=cat/pkg-1-r2:=') >>> dep.slot_op is SlotOperator.Equal True >>> dep = Dep('=cat/pkg-1-r2:0=') >>> dep.slot_op is SlotOperator.Equal True >>> dep = Dep('=cat/pkg-1-r2:*') >>> dep.slot_op is SlotOperator.Star True
- subslot¶
Get the subslot of a package dependency.
- Returns:
The subslot if it exists or None.
- Return type:
str | None
>>> from pkgcraft.dep import Dep >>> dep = Dep('=cat/pkg-1-r2:3/4') >>> dep.subslot '4' >>> dep = Dep('=cat/pkg-1-r2:3') >>> dep.subslot is None True >>> dep = Dep('=cat/pkg-1-r2') >>> dep.subslot is None True
- unversioned¶
Return a new Dep including only the category and package attributes.
>>> from pkgcraft.dep import Dep >>> dep = Dep('=cat/pkg-1-r2:3/4[a,!b?]') >>> str(dep.unversioned) 'cat/pkg'
If the Dep is unmodified, the original object is returned.
>>> dep = Dep('cat/pkg') >>> dep.unversioned is dep True
- use_deps¶
Get the USE dependencies of a package dependency.
- Returns:
The USE dependencies if any exist or None.
- Return type:
Set[UseDep] | None
>>> from pkgcraft.dep import Dep, UseDep >>> dep = Dep('=cat/pkg-1-r2[a,b,c]') >>> list(map(str, dep.use_deps)) ['a', 'b', 'c'] >>> dep = Dep('=cat/pkg-1-r2[-a(-),b(+)=,!c(-)?]') >>> list(map(str, dep.use_deps)) ['-a(-)', 'b(+)=', '!c(-)?'] >>> UseDep('!c(-)?') in dep.use_deps True >>> dep = Dep('=cat/pkg-1-r2') >>> dep.use_deps is None True
- version¶
Get the version of a package dependency.
- Returns:
The version if it exists or None.
- Return type:
Version | None
>>> from pkgcraft.dep import Dep >>> dep = Dep('=cat/pkg-1-r2') >>> str(dep.version) '=1-r2' >>> dep = Dep('cat/pkg') >>> dep.version is None True
- versioned¶
Return a new Dep including only the category, package, and version attributes.
Note that the version operator is also set to be ‘=’ if it exists.
>>> from pkgcraft.dep import Dep >>> dep = Dep('>=cat/pkg-1-r2:3/4[a,!b?]') >>> str(dep.versioned) '=cat/pkg-1-r2'
If the Dep is unmodified, the original object is returned.
>>> dep = Dep('cat/pkg') >>> dep.versioned is dep True >>> dep = Dep('=cat/pkg-1') >>> dep.versioned is dep True
- without(*fields)¶
Return a new Dep without the given attributes.
- Parameters:
fields (
str
) – The supported attribute names include the following: blocker, version, slot_dep, use_deps, and repo.- Returns:
The package dependency without the specified atttributes, if no modifications occurred the instance is returned.
- Return type:
- Raises:
MemoryError – on failed allocation
ValueError – on invalid fields
InvalidDep – if package dependency creation fails
>>> d = Dep('>=cat/pkg-1.2-r3:4/5[a,b]') >>> str(d.without("use_deps")) '>=cat/pkg-1.2-r3:4/5' >>> str(d.without("version")) 'cat/pkg:4/5[a,b]' >>> str(d.without("use_deps", "version")) 'cat/pkg:4/5' >>> str(d.without("use_deps", "version", "slot_dep")) 'cat/pkg'
- class pkgcraft.dep.pkg.DepCachedLru(*args, **kwargs)¶
Bases:
Dep
Package dependency with LRU-based instance caching.
>>> from pkgcraft.dep import DepCachedLru >>> s = '=cat/pkg-1-r2:3/4::repo[a,b]' >>> d1 = DepCachedLru(s) >>> d2 = DepCachedLru(s) >>> d1 is d2 True
LRU cache objects stay cached when all references are dropped.
>>> import gc >>> dep_id = repr(d2) >>> del d1, d2 >>> _ = gc.collect() >>> l = [DepCachedLru(f"=cat/pkg-{x}") for x in range(100)] >>> d = DepCachedLru(s) >>> repr(d) == dep_id True
- class pkgcraft.dep.pkg.DepCachedWeak(*args, **kwargs)¶
Bases:
Dep
Package dependency with weakref-based instance caching.
>>> from pkgcraft.dep import DepCachedWeak >>> s = '=cat/pkg-1-r2:3/4::repo[a,b]' >>> d1 = DepCachedWeak(s) >>> d2 = DepCachedWeak(s) >>> d1 is d2 True
Weak cache objects are dropped when all references are dropped.
>>> import gc >>> dep_id = repr(d2) >>> del d1, d2 >>> _ = gc.collect() >>> l = [DepCachedWeak(f"=cat/pkg-{x}") for x in range(100)] >>> d = DepCachedWeak(s) >>> repr(d) != dep_id True
pkgcraft.dep.uri module¶
pkgcraft.dep.use_dep module¶
- class pkgcraft.dep.use_dep.UseDep(unicode s: str)¶
Bases:
object
Package USE dependency.
- __init__()¶
Create a new package USE dependency.
- Parameters:
s – the USE string to parse
- Returns:
the created package USE dependency instance
- Return type:
- Raises:
PkgcraftError – on parsing failure
Valid
>>> from pkgcraft.dep import UseDep >>> u = UseDep('!use?') >>> u.flag 'use' >>> u.kind == UseDepKind.Conditional True >>> u.default is None True >>> str(u) '!use?' >>> u = UseDep('use(+)=') >>> u.flag 'use' >>> u.kind == UseDepKind.Equal True >>> u.default == True True >>> str(u) 'use(+)='
Invalid
>>> UseDep('+') Traceback (most recent call last): ... pkgcraft.error.PkgcraftError: parsing failure: invalid use dep: + ...
- default¶
- enabled¶
- flag¶
- kind¶
pkgcraft.dep.version module¶
- class pkgcraft.dep.version.Operator(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)¶
Bases:
IntEnum
- static from_str(s)¶
- Less = 1¶
- LessOrEqual = 2¶
- Equal = 3¶
- EqualGlob = 4¶
- Approximate = 5¶
- GreaterOrEqual = 6¶
- Greater = 7¶
- class pkgcraft.dep.version.Revision(unicode s: str)¶
Bases:
object
Package revision.
- __init__(*args, **kwargs)¶
- class pkgcraft.dep.version.Version(unicode s: str)¶
Bases:
object
Package version.
- __init__()¶
Create a new package version.
Simple version:
>>> from pkgcraft.dep import Operator, Version >>> v = Version('1') >>> v.revision is None True
Revisioned version:
>>> v = Version('1-r2') >>> str(v.revision) '2'
Version with operator:
>>> v = Version('>=1.2') >>> v.op is Operator.GreaterOrEqual True >>> v.op == '>=' True
Invalid version:
>>> Version('1a-1') Traceback (most recent call last): ... pkgcraft.error.InvalidVersion: parsing failure: invalid version: 1a-1 ...
- base¶
Get a version’s base.
>>> from pkgcraft.dep import Version >>> v = Version('1-r2') >>> v.base '1' >>> v = Version('>=1.2_alpha3') >>> v.base '1.2_alpha3'
- intersects(other)¶
Determine if two versions intersect.
>>> from pkgcraft.dep import Version >>> v1 = Version('>1') >>> v2 = Version('2-r1') >>> v1.intersects(v2) and v2.intersects(v1) True >>> v1 = Version('>1-r1') >>> v2 = Version('=1-r1') >>> v1.intersects(v2) or v2.intersects(v1) False
- op¶
Get a version’s operator.
>>> from pkgcraft.dep import Operator, Version >>> v = Version('1-r2') >>> v.op is None True >>> v = Version('>=1') >>> v.op is Operator.GreaterOrEqual True >>> v.op == '>=' True
- static parse(s, raised=False)¶
Determine if a string is a valid package version.
This avoids any string allocations, only returning the validity status.
- Parameters:
s (
str
) – the string to parseraised – if True, raise an exception when invalid
- Returns:
True if the given string represents a valid version, otherwise False.
- Return type:
- Raises:
InvalidVersion – on failure if the raised parameter is set to True
>>> from pkgcraft.dep import Version >>> Version.parse('1-r2') True
- revision¶
Get a version’s revision.
>>> from pkgcraft.dep import Version >>> v = Version('1-r2') >>> str(v.revision) '2' >>> v = Version('1') >>> v.revision is None True >>> v = Version('1-r0') >>> str(v.revision) '0'
- with_op(self, op)¶
Potentially create a new Version by applying an operator.
- Parameters:
- Returns:
the newly created Version (or the original object if no changes were made)
- Return type:
- Raises:
PkgcraftError – for invalid operator arguments
>>> from pkgcraft.dep import Version, Operator >>> ver = Version('1-r2')
String-based operator
>>> str(ver.with_op('>=')) '>=1-r2'
Enum-based operator
>>> str(ver.with_op(Operator.Less)) '<1-r2'
Invalid operator
>>> ver.with_op(Operator.Approximate) Traceback (most recent call last): ... pkgcraft.error.PkgcraftError: ~ version operator can't be used with a revision
Applying the existing operator returns the original Version
>>> v1 = Version('>1-r2') >>> v2 = v1.with_op(">") >>> v1 is v2 True