portage.dep package¶
Subpackages¶
Submodules¶
Module contents¶
- class portage.dep.Atom(s, *args, **kwargs)¶
Bases:
str
For compatibility with existing atom string manipulation code, this class emulates most of the str methods that are useful with atoms.
- _eval_qa_conditionals(use_mask, use_force)¶
- capitalize()¶
Return a capitalized version of the string.
More specifically, make the first character have upper case and the rest lower case.
- casefold()¶
Return a version of the string suitable for caseless comparisons.
- center(width, fillchar=' ', /)¶
Return a centered string of length width.
Padding is done using the specified fill character (default is a space).
- count(sub[, start[, end]]) int ¶
Return the number of non-overlapping occurrences of substring sub in string S[start:end]. Optional arguments start and end are interpreted as in slice notation.
- encode(encoding='utf-8', errors='strict')¶
Encode the string using the codec registered for encoding.
- encoding
The encoding in which to encode the string.
- errors
The error handling scheme to use for encoding errors. The default is ‘strict’ meaning that encoding errors raise a UnicodeEncodeError. Other possible values are ‘ignore’, ‘replace’ and ‘xmlcharrefreplace’ as well as any other name registered with codecs.register_error that can handle UnicodeEncodeErrors.
- endswith(suffix[, start[, end]]) bool ¶
Return True if S ends with the specified suffix, False otherwise. With optional start, test S beginning at that position. With optional end, stop comparing S at that position. suffix can also be a tuple of strings to try.
- evaluate_conditionals(use)¶
Create an atom instance with any USE conditionals evaluated. :param use: The set of enabled USE flags :type use: set :rtype: Atom :return: an atom instance with any USE conditionals evaluated
- expandtabs(tabsize=8)¶
Return a copy where all tab characters are expanded using spaces.
If tabsize is not given, a tab size of 8 characters is assumed.
- find(sub[, start[, end]]) int ¶
Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end]. Optional arguments start and end are interpreted as in slice notation.
Return -1 on failure.
- format(*args, **kwargs) str ¶
Return a formatted version of S, using substitutions from args and kwargs. The substitutions are identified by braces (‘{’ and ‘}’).
- format_map(mapping) str ¶
Return a formatted version of S, using substitutions from mapping. The substitutions are identified by braces (‘{’ and ‘}’).
- index(sub[, start[, end]]) int ¶
Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end]. Optional arguments start and end are interpreted as in slice notation.
Raises ValueError when the substring is not found.
- intersects(other)¶
Atoms with different cpv, operator or use attributes cause this method to return False even though there may actually be some intersection. TODO: Detect more forms of intersection. :param other: The package atom to match :type other: Atom :rtype: Boolean :return: True if this atom and the other atom intersect,
False otherwise.
- isalnum()¶
Return True if the string is an alpha-numeric string, False otherwise.
A string is alpha-numeric if all characters in the string are alpha-numeric and there is at least one character in the string.
- isalpha()¶
Return True if the string is an alphabetic string, False otherwise.
A string is alphabetic if all characters in the string are alphabetic and there is at least one character in the string.
- isascii()¶
Return True if all characters in the string are ASCII, False otherwise.
ASCII characters have code points in the range U+0000-U+007F. Empty string is ASCII too.
- isdecimal()¶
Return True if the string is a decimal string, False otherwise.
A string is a decimal string if all characters in the string are decimal and there is at least one character in the string.
- isdigit()¶
Return True if the string is a digit string, False otherwise.
A string is a digit string if all characters in the string are digits and there is at least one character in the string.
- isidentifier()¶
Return True if the string is a valid Python identifier, False otherwise.
Call keyword.iskeyword(s) to test whether string s is a reserved identifier, such as “def” or “class”.
- islower()¶
Return True if the string is a lowercase string, False otherwise.
A string is lowercase if all cased characters in the string are lowercase and there is at least one cased character in the string.
- isnumeric()¶
Return True if the string is a numeric string, False otherwise.
A string is numeric if all characters in the string are numeric and there is at least one character in the string.
- isprintable()¶
Return True if the string is printable, False otherwise.
A string is printable if all of its characters are considered printable in repr() or if it is empty.
- isspace()¶
Return True if the string is a whitespace string, False otherwise.
A string is whitespace if all characters in the string are whitespace and there is at least one character in the string.
- istitle()¶
Return True if the string is a title-cased string, False otherwise.
In a title-cased string, upper- and title-case characters may only follow uncased characters and lowercase characters only cased ones.
- isupper()¶
Return True if the string is an uppercase string, False otherwise.
A string is uppercase if all cased characters in the string are uppercase and there is at least one cased character in the string.
- join(iterable, /)¶
Concatenate any number of strings.
The string whose method is called is inserted in between each given string. The result is returned as a new string.
Example: ‘.’.join([‘ab’, ‘pq’, ‘rs’]) -> ‘ab.pq.rs’
- ljust(width, fillchar=' ', /)¶
Return a left-justified string of length width.
Padding is done using the specified fill character (default is a space).
- lower()¶
Return a copy of the string converted to lowercase.
- lstrip(chars=None, /)¶
Return a copy of the string with leading whitespace removed.
If chars is given and not None, remove characters in chars instead.
- static maketrans()¶
Return a translation table usable for str.translate().
If there is only one argument, it must be a dictionary mapping Unicode ordinals (integers) or characters to Unicode ordinals, strings or None. Character keys will be then converted to ordinals. If there are two arguments, they must be strings of equal length, and in the resulting dictionary, each character in x will be mapped to the character at the same position in y. If there is a third argument, it must be a string, whose characters will be mapped to None in the result.
- match(pkg)¶
Check if the given package instance matches this atom.
- Parameters
pkg (Package) – a Package instance
- Returns
True if this atom matches pkg, otherwise False
- Return type
bool
- package = True¶
- partition(sep, /)¶
Partition the string into three parts using the given separator.
This will search for the separator in the string. If the separator is found, returns a 3-tuple containing the part before the separator, the separator itself, and the part after it.
If the separator is not found, returns a 3-tuple containing the original string and two empty strings.
- removeprefix(prefix, /)¶
Return a str with the given prefix string removed if present.
If the string starts with the prefix string, return string[len(prefix):]. Otherwise, return a copy of the original string.
- removesuffix(suffix, /)¶
Return a str with the given suffix string removed if present.
If the string ends with the suffix string and that suffix is not empty, return string[:-len(suffix)]. Otherwise, return a copy of the original string.
- replace(old, new, count=- 1, /)¶
Return a copy with all occurrences of substring old replaced by new.
- count
Maximum number of occurrences to replace. -1 (the default value) means replace all occurrences.
If the optional argument count is given, only the first count occurrences are replaced.
- rfind(sub[, start[, end]]) int ¶
Return the highest index in S where substring sub is found, such that sub is contained within S[start:end]. Optional arguments start and end are interpreted as in slice notation.
Return -1 on failure.
- rindex(sub[, start[, end]]) int ¶
Return the highest index in S where substring sub is found, such that sub is contained within S[start:end]. Optional arguments start and end are interpreted as in slice notation.
Raises ValueError when the substring is not found.
- rjust(width, fillchar=' ', /)¶
Return a right-justified string of length width.
Padding is done using the specified fill character (default is a space).
- rpartition(sep, /)¶
Partition the string into three parts using the given separator.
This will search for the separator in the string, starting at the end. If the separator is found, returns a 3-tuple containing the part before the separator, the separator itself, and the part after it.
If the separator is not found, returns a 3-tuple containing two empty strings and the original string.
- rsplit(sep=None, maxsplit=- 1)¶
Return a list of the substrings in the string, using sep as the separator string.
- sep
The separator used to split the string.
When set to None (the default value), will split on any whitespace character (including \n \r \t \f and spaces) and will discard empty strings from the result.
- maxsplit
Maximum number of splits (starting from the left). -1 (the default value) means no limit.
Splitting starts at the end of the string and works to the front.
- rstrip(chars=None, /)¶
Return a copy of the string with trailing whitespace removed.
If chars is given and not None, remove characters in chars instead.
- property slot_operator_built¶
Returns True if slot_operator == “=” and sub_slot is not None. NOTE: foo/bar:2= is unbuilt and returns False, whereas foo/bar:2/2= is built and returns True.
- soname = False¶
- split(sep=None, maxsplit=- 1)¶
Return a list of the substrings in the string, using sep as the separator string.
- sep
The separator used to split the string.
When set to None (the default value), will split on any whitespace character (including \n \r \t \f and spaces) and will discard empty strings from the result.
- maxsplit
Maximum number of splits (starting from the left). -1 (the default value) means no limit.
Note, str.split() is mainly useful for data that has been intentionally delimited. With natural text that includes punctuation, consider using the regular expression module.
- splitlines(keepends=False)¶
Return a list of the lines in the string, breaking at line boundaries.
Line breaks are not included in the resulting list unless keepends is given and true.
- startswith(prefix[, start[, end]]) bool ¶
Return True if S starts with the specified prefix, False otherwise. With optional start, test S beginning at that position. With optional end, stop comparing S at that position. prefix can also be a tuple of strings to try.
- strip(chars=None, /)¶
Return a copy of the string with leading and trailing whitespace removed.
If chars is given and not None, remove characters in chars instead.
- swapcase()¶
Convert uppercase characters to lowercase and lowercase characters to uppercase.
- title()¶
Return a version of the string where each word is titlecased.
More specifically, words start with uppercased characters and all remaining cased characters have lower case.
- translate(table, /)¶
Replace each character in the string using the given translation table.
- table
Translation table, which must be a mapping of Unicode ordinals to Unicode ordinals, strings, or None.
The table must implement lookup/indexing via __getitem__, for instance a dictionary or list. If this operation raises LookupError, the character is left untouched. Characters mapped to None are deleted.
- upper()¶
Return a copy of the string converted to uppercase.
- violated_conditionals(other_use, is_valid_flag, parent_use=None)¶
Create an atom instance with any USE conditional removed, that is satisfied by other_use. :param other_use: The set of enabled USE flags :type other_use: set :param is_valid_flag: Function that decides if a use flag is referenceable in use deps :type is_valid_flag: function :param parent_use: Set of enabled use flags of the package requiring this atom :type parent_use: set :rtype: Atom :return: an atom instance with any satisfied USE conditionals removed
- with_repo(repo)¶
- with_slot(slot)¶
- property without_repo¶
- property without_slot¶
- zfill(width, /)¶
Pad a numeric string with zeros on the left, to fill a field of the given width.
The string is never truncated.
- class portage.dep.ExtendedAtomDict(value_class)¶
Bases:
portage.cache.mappings.MutableMapping
dict() wrapper that supports extended atoms as keys and allows lookup of a normal cp against other normal cp and extended cp. The value type has to be given to __init__ and is assumed to be the same for all values.
- _extended¶
- _normal¶
- _value_class¶
- clear()¶
- copy()¶
- get(key, default=None)¶
- items()¶
- iteritems()¶
- iterkeys()¶
- itervalues()¶
- keys()¶
- pop(key, *args)¶
- popitem()¶
- setdefault(cp, default=None)¶
- update(*args, **kwargs)¶
- values()¶
- class portage.dep._RequiredUseBranch(operator=None, parent=None)¶
Bases:
object
- _children¶
- _operator¶
- _parent¶
- _satisfied¶
- tounicode()¶
- class portage.dep._RequiredUseLeaf(token, satisfied)¶
Bases:
object
- _satisfied¶
- _token¶
- tounicode()¶
- portage.dep._get_atom_re(eapi_attrs)¶
- portage.dep._get_atom_wildcard_re(eapi_attrs)¶
- portage.dep._get_slot_dep_re(eapi_attrs)¶
- portage.dep._get_usedep_re(eapi_attrs)¶
- Parameters
eapi_attrs (_eapi_attrs) – The EAPI attributes from _get_eapi_attrs
- Return type
regular expression object
- Returns
A regular expression object that matches valid USE deps for the given eapi.
- portage.dep._get_useflag_re(eapi)¶
When eapi is None then validation is not as strict, since we want the same to work for multiple EAPIs that may have slightly different rules. :param eapi: The EAPI :type eapi: String or None :rtype: regular expression object :return: A regular expression object that matches valid USE flags for the
given eapi.
- portage.dep._match_slot(atom, pkg)¶
- class portage.dep._use_dep(use, eapi_attrs, enabled_flags=None, disabled_flags=None, missing_enabled=None, missing_disabled=None, conditional=None, required=None)¶
Bases:
object
- _conditional_strings = {'disabled': '!%s?', 'enabled': '%s?', 'equal': '%s=', 'not_equal': '!%s='}¶
- _eapi_attrs¶
- _eval_qa_conditionals(use_mask, use_force)¶
For repoman, evaluate all possible combinations within the constraints of the given use.force and use.mask settings. The result may seem ambiguous in the sense that the same flag can be in both the enabled and disabled sets, but this is useful within the context of how its intended to be used by repoman. It is assumed that the caller has already ensured that there is no intersection between the given use_mask and use_force sets when necessary.
- conditional¶
- disabled¶
- enabled¶
- evaluate_conditionals(use)¶
Create a new instance with conditionals evaluated.
Conditional evaluation behavior:
parent state conditional result
x x? x
- -x
x? x !x?
- -x
!x? -x
x x= x
- -x
x= -x x !x= -x
- -x
!x= x
Conditional syntax examples:
Compact Form Equivalent Expanded Form
foo[bar?] bar? ( foo[bar] ) !bar? ( foo ) foo[!bar?] bar? ( foo ) !bar? ( foo[-bar] ) foo[bar=] bar? ( foo[bar] ) !bar? ( foo[-bar] ) foo[!bar=] bar? ( foo[-bar] ) !bar? ( foo[bar] )
- missing_disabled¶
- missing_enabled¶
- required¶
- tokens¶
- violated_conditionals(other_use, is_valid_flag, parent_use=None)¶
Create a new instance with satisfied use deps removed.
- portage.dep._use_reduce_cached(depstr, uselist, masklist, matchall, excludeall, is_src_uri, eapi, opconvert, flat, is_valid_flag, token_class, matchnone, subset)¶
- portage.dep.best_match_to_list(mypkg, mylist)¶
Returns the most specific entry that matches the package given.
- Parameters
mypkg (String) – The package atom to check
mylist (List) – The list of package atoms to check against
- Return type
String
- Returns
The package atom which best matches given the following ordering: - =cpv 6 - ~cpv 5 - =cpv* 4 - cp:slot 3 - >cpv 2 - <cpv 2 - >=cpv 2 - <=cpv 2 - cp 1 - cp:slot with extended syntax 0 - cp with extended syntax -1
- portage.dep.check_required_use(required_use, use, iuse_match, eapi=None)¶
Checks if the use flags listed in ‘use’ satisfy all constraints specified in ‘required_use’.
- Parameters
required_use (String) – REQUIRED_USE string
use (List) – Enabled use flags
iuse_match (Callable) – Callable that takes a single flag argument and returns True if the flag is matched, false otherwise,
- Return type
Bool
- Returns
Indicates if REQUIRED_USE constraints are satisfied
- portage.dep.cpvequal(cpv1, cpv2)¶
- Example Usage:
>>> from portage.dep import cpvequal >>> cpvequal("sys-apps/portage-2.1","sys-apps/portage-2.1") >>> True
- Parameters
cpv1 (String) – CategoryPackageVersion (no operators) Example: “sys-apps/portage-2.1”
cpv2 (String) – CategoryPackageVersion (no operators) Example: “sys-apps/portage-2.1”
- Return type
Boolean
- Returns
True if cpv1 = cpv2
False Otherwise
Throws PortageException if cpv1 or cpv2 is not a CPV
- portage.dep.dep_getcpv(mydep)¶
Return the category-package-version with any operators/slot specifications stripped off
- Example usage:
>>> dep_getcpv('>=media-libs/test-3.0') 'media-libs/test-3.0'
- Parameters
mydep (String) – The depstring
- Return type
String
- Returns
The depstring with the operator removed
- portage.dep.dep_getkey(mydep)¶
Return the category/package-name of a depstring.
- Example usage:
>>> dep_getkey('=media-libs/test-3.0') 'media-libs/test'
- Parameters
mydep (String) – The depstring to retrieve the category/package-name of
- Return type
String
- Returns
The package category/package-name
- portage.dep.dep_getrepo(mydep)¶
Retrieve the repo on a depend.
- Parameters
mydep (String) – The depstring to retrieve the repository of
- Return type
String
- Returns
The repository name
- Example usage:
>>> dep_getrepo('app-misc/test::repository') 'repository'
- portage.dep.dep_getslot(mydep)¶
Retrieve the slot on a depend.
- Example usage:
>>> dep_getslot('app-misc/test:3') '3'
- Parameters
mydep (String) – The depstring to retrieve the slot of
- Return type
String
- Returns
The slot
- portage.dep.dep_getusedeps(depend)¶
Pull a listing of USE Dependencies out of a dep atom.
- Parameters
depend (String) – The depstring to process
- Return type
List
- Returns
List of use flags ( or [] if no flags exist )
- Example usage:
>>> dep_getusedeps('app-misc/test:3[foo,-bar]') ('foo', '-bar')
- portage.dep.dep_opconvert(deplist)¶
Iterate recursively through a list of deps, if the dep is a ‘||’ or ‘&&’ operator, combine it with the list of deps that follows..
- Example usage:
>>> test = ["blah", "||", ["foo", "bar", "baz"]] >>> dep_opconvert(test) ['blah', ['||', 'foo', 'bar', 'baz']]
- Parameters
deplist (List) – A list of deps to format
- Return type
List
- Returns
The new list with the new ordering
- portage.dep.extended_cp_match(extended_cp, other_cp)¶
Checks if an extended syntax cp matches a non extended cp
- portage.dep.extract_affecting_use(mystr, atom, eapi=None)¶
Take a dep string and an atom and return the use flags that decide if the given atom is in effect.
- Parameters
mystr (String) – The dependency string
atom (String) – The atom to get into effect
- Return type
Set of strings
- Returns
Set of use flags affecting given atom
- Example usage:
>>> extract_affecting_use('sasl? ( dev-libs/cyrus-sasl ) !minimal? ( cxx? ( dev-libs/cyrus-sasl ) )', 'dev-libs/cyrus-sasl') {'cxx', 'minimal', 'sasl'}
- portage.dep.flatten(mylist)¶
Recursively traverse nested lists and return a single list containing all non-list elements that are found.
- Parameters
mylist (List) – A list containing nested lists and non-list elements.
- Return type
List
- Returns
A single list containing only non-list elements.
- Example usage:
>>> flatten([1, [2, 3, [4]]]) [1, 2, 3, 4]
- portage.dep.get_operator(mydep)¶
Return the operator used in a depstring.
- Example usage:
>>> from portage.dep import * >>> get_operator(">=test-1.0") '>='
- Parameters
mydep (String) – The dep string to check
- Return type
String
- Returns
The operator. One of: ‘~’, ‘=’, ‘>’, ‘<’, ‘=*’, ‘>=’, or ‘<=’
- portage.dep.get_required_use_flags(required_use, eapi=None)¶
Returns a set of use flags that are used in the given REQUIRED_USE string
- Parameters
required_use (String) – REQUIRED_USE string
- Return type
Set
- Returns
Set of use flags that are used in the given REQUIRED_USE string
- portage.dep.human_readable_required_use(required_use)¶
- portage.dep.isjustname(mypkg)¶
Checks to see if the atom is only the package name (no version parts).
- Example usage:
>>> isjustname('=media-libs/test-3.0') False >>> isjustname('media-libs/test') True
- Parameters
mypkg – The package atom to check
mypkg – String or Atom
- Return type
Integer
- Returns
One of the following: 1) False if the package string is not just the package name 2) True if it is
- portage.dep.isspecific(mypkg)¶
Checks to see if a package is in =category/package-version or package-version format.
- Example usage:
>>> isspecific('media-libs/test') False >>> isspecific('=media-libs/test-3.0') True
- Parameters
mypkg (String) – The package depstring to check against
- Return type
Boolean
- Returns
One of the following: 1) False if the package string is not specific 2) True if it is
- portage.dep.isvalidatom(atom, allow_blockers=False, allow_wildcard=False, allow_repo=False, eapi=None, allow_build_id=False)¶
Check to see if a depend atom is valid
- Example usage:
>>> isvalidatom('media-libs/test-3.0') False >>> isvalidatom('>=media-libs/test-3.0') True
- Parameters
atom (String or Atom) – The depend atom to check against
- Return type
Boolean
- Returns
One of the following: 1) False if the atom is invalid 2) True if the atom is valid
- portage.dep.match_from_list(mydep, candidate_list)¶
Searches list for entries that matches the package.
- Parameters
mydep (String) – The package atom to match
candidate_list (List) – The list of package atoms to compare against
- Return type
List
- Returns
A list of package atoms that match the given package atom
- portage.dep.match_to_list(mypkg, mylist)¶
Searches list for entries that matches the package.
- Parameters
mypkg (String) – The package atom to match
mylist (List) – The list of package atoms to compare against
- Return type
List
- Returns
A unique list of package atoms that match the given package atom
- portage.dep.paren_enclose(mylist, unevaluated_atom=False, opconvert=False)¶
Convert a list to a string with sublists enclosed with parens.
- Parameters
mylist (List) – The list
- Return type
String
- Returns
The paren enclosed string
- Example usage:
>>> test = ['foobar','foo',['bar','baz']] >>> paren_enclose(test) 'foobar foo ( bar baz )'
- class portage.dep.paren_normalize(src)¶
Bases:
list
Take a dependency structure as returned by paren_reduce or use_reduce and generate an equivalent structure that has no redundant lists.
- _zap_parens(src, dest, disjunction=False)¶
- append(object, /)¶
Append object to the end of the list.
- clear()¶
Remove all items from list.
- copy()¶
Return a shallow copy of the list.
- count(value, /)¶
Return number of occurrences of value.
- extend(iterable, /)¶
Extend list by appending elements from the iterable.
- index(value, start=0, stop=9223372036854775807, /)¶
Return first index of value.
Raises ValueError if the value is not present.
- insert(index, object, /)¶
Insert object before index.
- pop(index=- 1, /)¶
Remove and return item at index (default last).
Raises IndexError if list is empty or index is out of range.
- remove(value, /)¶
Remove first occurrence of value.
Raises ValueError if the value is not present.
- reverse()¶
Reverse IN PLACE.
- sort(*, key=None, reverse=False)¶
Sort the list in ascending order and return None.
The sort is in-place (i.e. the list itself is modified) and stable (i.e. the order of two equal elements is maintained).
If a key function is given, apply it once to each list item and sort them, ascending or descending, according to their function values.
The reverse flag can be set to sort in descending order.
- portage.dep.paren_reduce(mystr, _deprecation_warn=True)¶
Take a string and convert all paren enclosed entities into sublists and split the list elements by spaces. All redundant brackets are removed.
- Example usage:
>>> paren_reduce('foobar foo? ( bar baz )') ['foobar', 'foo?', ['bar', 'baz']]
- Parameters
mystr (String) – The string to reduce
- Return type
Array
- Returns
The reduced string in an array
- portage.dep.remove_slot(mydep)¶
- Removes dep components from the right side of an atom:
slot
use
repo
And repo_name from the left side.
- Return type
String
- portage.dep.strip_empty(myarr)¶
Strip all empty elements from an array
- Parameters
myarr (List) – The list of elements
- Return type
Array
- Returns
The array with empty elements removed
- portage.dep.use_reduce(depstr, uselist=(), masklist=(), matchall=False, excludeall=(), is_src_uri=False, eapi=None, opconvert=False, flat=False, is_valid_flag=None, token_class=None, matchnone=False, subset=None)¶
Takes a dep string and reduces the use? conditionals out, leaving an array with subarrays. All redundant brackets are removed.
- Parameters
depstr (String) – depstring
uselist (Sequence) – Sequence of use enabled flags
masklist (Sequence) – Sequence of masked flags (always treated as disabled)
matchall (Bool) – Treat all conditionals as active. Used by repoman.
excludeall (Sequence) – Sequence of flags for which negated conditionals are always treated as inactive.
is_src_uri (Bool) – Indicates if depstr represents a SRC_URI
eapi (String) – Indicates the EAPI the dep string has to comply to
opconvert (Bool) – Put every operator as first element into it’s argument list
flat (Bool) – Create a flat list of all tokens
is_valid_flag (Function) – Function that decides if a given use flag might be used in use conditionals
token_class (Class) – Convert all non operator tokens into this class
matchnone (Bool) – Treat all conditionals as inactive. Used by digestgen().
subset (Sequence) – Select a subset of dependencies conditional on the given flags
- Return type
List
- Returns
The use reduced depend array