Package portage :: Package dep
[hide private]

Package dep

source code

Submodules [hide private]

Classes [hide private]
  basestring
str(object='') -> string
  paren_normalize
Take a dependency structure as returned by paren_reduce or use_reduce and generate an equivalent structure that has no redundant lists.
  _use_dep
  Atom
For compatibility with existing atom string manipulation code, this class emulates most of the str methods that are useful with atoms.
  ExtendedAtomDict
dict() wrapper that supports extended atoms as keys and allows lookup of a normal cp against other normal cp and extended cp.
  _RequiredUseLeaf
  _RequiredUseBranch
Functions [hide private]
 
_get_slot_dep_re(eapi_attrs) source code
 
_match_slot(atom, pkg) source code
 
_get_atom_re(eapi_attrs) source code
 
_get_atom_wildcard_re(eapi_attrs) source code
regular expression object
_get_usedep_re(eapi_attrs)
Returns: A regular expression object that matches valid USE deps for the given eapi.
source code
regular expression object
_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.
source code
 
cpvequal(cpv1, cpv2)
@param cpv1: CategoryPackageVersion (no operators) Example: "sys-apps/portage-2.1" @type cpv1: String @param cpv2: CategoryPackageVersion (no operators) Example: "sys-apps/portage-2.1" @type cpv2: String @rtype: Boolean @return: 1.
source code
Array
strip_empty(myarr)
Strip all empty elements from an array
source code
Array
paren_reduce(mystr, _deprecation_warn=True)
Take a string and convert all paren enclosed entities into sublists and split the list elements by spaces.
source code
String
paren_enclose(mylist, unevaluated_atom=False, opconvert=False)
Convert a list to a string with sublists enclosed with parens.
source code
List
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)
Takes a dep string and reduces the use? conditionals out, leaving an array with subarrays.
source code
List
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..
source code
List
flatten(mylist)
Recursively traverse nested lists and return a single list containing all non-list elements that are found.
source code
 
extended_cp_match(extended_cp, other_cp)
Checks if an extended syntax cp matches a non extended cp
source code
String
get_operator(mydep)
Return the operator used in a depstring.
source code
String
dep_getcpv(mydep)
Return the category-package-version with any operators/slot specifications stripped off
source code
String
dep_getslot(mydep)
Retrieve the slot on a depend.
source code
String
dep_getrepo(mydep)
Retrieve the repo on a depend.
source code
 
remove_slot(mydep)
Removes dep components from the right side of an atom: * slot * use * repo And repo_name from the left side.
source code
List
dep_getusedeps(depend)
Pull a listing of USE Dependencies out of a dep atom.
source code
Boolean
isvalidatom(atom, allow_blockers=False, allow_wildcard=False, allow_repo=False, eapi=None)
Check to see if a depend atom is valid
source code
Integer
isjustname(mypkg)
Checks to see if the atom is only the package name (no version parts).
source code
Boolean
isspecific(mypkg)
Checks to see if a package is in =category/package-version or package-version format.
source code
String
dep_getkey(mydep)
Return the category/package-name of a depstring.
source code
List
match_to_list(mypkg, mylist)
Searches list for entries that matches the package.
source code
String
best_match_to_list(mypkg, mylist)
Returns the most specific entry that matches the package given.
source code
List
match_from_list(mydep, candidate_list)
Searches list for entries that matches the package.
source code
 
human_readable_required_use(required_use) source code
Set
get_required_use_flags(required_use, eapi=None)
Returns a set of use flags that are used in the given REQUIRED_USE string
source code
Bool
check_required_use(required_use, use, iuse_match, eapi=None)
Checks if the use flags listed in 'use' satisfy all constraints specified in 'constraints'.
source code
Set of strings
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.
source code
String
extract_unpack_dependencies(src_uri, unpackers)
Return unpack dependencies string for given SRC_URI string.
source code
Variables [hide private]
  _slot_separator = u':'
  _slot_loose = u'([\w+./*=-]+)'
  _use = u'\[.*\]'
  _op = u'([=~]|[><]=?)'
  _repo_separator = u'::'
  _repo_name = u'[\w][\w-]*'
  _repo_name_re = re.compile(r'(?u)^\w[\w-]*$')
  _repo = u'(?:::([\w][\w-]*))?'
  _extended_cat = u'[\w+*][\w+.*-]*'
  _slot_dep_re_cache = {False: re.compile(r'(?ux)^([\w\+][\w\+\....
  _atom_re_cache = {False: re.compile(r'(?ux)^(?P<without_use>(?...
  _atom_wildcard_re_cache = {True: re.compile(r'(?u)((?P<simple>...
  _usedep_re_cache = {}
  _useflag_re_cache = {False: re.compile(r'^[A-Za-z0-9][A-Za-z0-...
  _extended_cp_re_cache = {}
  __package__ = 'portage.dep'

Imports: re, sys, warnings, chain, _encodings, _unicode_decode, _unicode_encode, _get_eapi_attrs, InvalidAtom, InvalidData, InvalidDependString, _, catpkgsplit, catsplit, vercmp, ververify, _cp, _cpv, _pkg_str, _slot, _unknown_repo, _vr, portage, _unicode, _slot_operator, cmp_sort_key, dep_check, writemsg


Function Details [hide private]

_get_usedep_re(eapi_attrs)

source code 
Parameters:
  • eapi_attrs (_eapi_attrs) - The EAPI attributes from _get_eapi_attrs
Returns: regular expression object
A regular expression object that matches valid USE deps for the given eapi.

_get_useflag_re(eapi)

source code 

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.

Parameters:
  • eapi (String or None) - The EAPI
Returns: regular expression object
A regular expression object that matches valid USE flags for the given eapi.

cpvequal(cpv1, cpv2)

source code 


@param cpv1: CategoryPackageVersion (no operators) Example: "sys-apps/portage-2.1"
@type cpv1: String
@param cpv2: CategoryPackageVersion (no operators) Example: "sys-apps/portage-2.1"
@type cpv2: String
@rtype: Boolean
@return:
1.  True if cpv1 = cpv2
2.  False Otherwise
3.  Throws PortageException if cpv1 or cpv2 is not a CPV

Example Usage:
>>> from portage.dep import cpvequal
>>> cpvequal("sys-apps/portage-2.1","sys-apps/portage-2.1")
>>> True

strip_empty(myarr)

source code 

Strip all empty elements from an array

Parameters:
  • myarr (List) - The list of elements
Returns: Array
The array with empty elements removed

paren_reduce(mystr, _deprecation_warn=True)

source code 

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
Returns: Array
The reduced string in an array

paren_enclose(mylist, unevaluated_atom=False, opconvert=False)

source code 

Convert a list to a string with sublists enclosed with parens.

Example usage:

>>> test = ['foobar','foo',['bar','baz']]
>>> paren_enclose(test)
'foobar foo ( bar baz )'
Parameters:
  • mylist (List) - The list
Returns: String
The paren enclosed string

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)

source code 

Takes a dep string and reduces the use? conditionals out, leaving an array with subarrays. All redundant brackets are removed.

Parameters:
  • deparray (String) - depstring
  • uselist (List) - List of use enabled flags
  • masklist (List) - List of masked flags (always treated as disabled)
  • matchall (Bool) - Treat all conditionals as active. Used by repoman.
  • excludeall (List) - List 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().
Returns: List
The use reduced depend array

dep_opconvert(deplist)

source code 

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 - A list of deps to format
  • mydep (List)
Returns: List
The new list with the new ordering

flatten(mylist)

source code 

Recursively traverse nested lists and return a single list containing all non-list elements that are found.

Example usage:

>>> flatten([1, [2, 3, [4]]])
[1, 2, 3, 4]
Parameters:
  • mylist (List) - A list containing nested lists and non-list elements.
Returns: List
A single list containing only non-list elements.

get_operator(mydep)

source code 

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
Returns: String
The operator. One of: '~', '=', '>', '<', '=*', '>=', or '<='

dep_getcpv(mydep)

source code 

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
Returns: String
The depstring with the operator removed

dep_getslot(mydep)

source code 

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
Returns: String
The slot

dep_getrepo(mydep)

source code 

Retrieve the repo on a depend.

Example usage:

>>> dep_getrepo('app-misc/test::repository')
'repository'
Parameters:
  • mydep (String) - The depstring to retrieve the repository of
Returns: String
The repository name

dep_getusedeps(depend)

source code 

Pull a listing of USE Dependencies out of a dep atom.

Example usage:

>>> dep_getusedeps('app-misc/test:3[foo,-bar]')
('foo', '-bar')
Parameters:
  • depend (String) - The depstring to process
Returns: List
List of use flags ( or [] if no flags exist )

isvalidatom(atom, allow_blockers=False, allow_wildcard=False, allow_repo=False, eapi=None)

source code 

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
Returns: Boolean
One of the following: 1) False if the atom is invalid 2) True if the atom is valid

isjustname(mypkg)

source code 

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
Returns: Integer
One of the following: 1) False if the package string is not just the package name 2) True if it is

isspecific(mypkg)

source code 

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
Returns: Boolean
One of the following: 1) False if the package string is not specific 2) True if it is

dep_getkey(mydep)

source code 

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
Returns: String
The package category/package-name

match_to_list(mypkg, mylist)

source code 

Searches list for entries that matches the package.

Parameters:
  • mypkg (String) - The package atom to match
  • mylist - The list of package atoms to compare against
  • mylist - List
Returns: List
A unique list of package atoms that match the given package atom

best_match_to_list(mypkg, mylist)

source code 

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
Returns: String
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

match_from_list(mydep, candidate_list)

source code 

Searches list for entries that matches the package.

Parameters:
  • mydep (String) - The package atom to match
  • candidate_list - The list of package atoms to compare against
  • candidate_list - List
Returns: List
A list of package atoms that match the given package atom

get_required_use_flags(required_use, eapi=None)

source code 

Returns a set of use flags that are used in the given REQUIRED_USE string

Parameters:
  • required_use (String) - REQUIRED_USE string
Returns: Set
Set of use flags that are used in the given REQUIRED_USE string

check_required_use(required_use, use, iuse_match, eapi=None)

source code 

Checks if the use flags listed in 'use' satisfy all constraints specified in 'constraints'.

Parameters:
  • required_use (String) - REQUIRED_USE string
  • use - Enabled use flags
  • use - List
  • iuse_match - Callable that takes a single flag argument and returns True if the flag is matched, false otherwise,
  • iuse_match - Callable
Returns: Bool
Indicates if REQUIRED_USE constraints are satisfied

extract_affecting_use(mystr, atom, eapi=None)

source code 

Take a dep string and an atom and return the use flags that decide if the given atom is in effect.

Example usage:

>>> extract_affecting_use('sasl? ( dev-libs/cyrus-sasl )                        !minimal? ( cxx? ( dev-libs/cyrus-sasl ) )', 'dev-libs/cyrus-sasl')
{'cxx', 'minimal', 'sasl'}
Parameters:
  • mystr (String) - The dependency string
  • atom (String) - The atom to get into effect
Returns: Set of strings
Set of use flags affecting given atom

extract_unpack_dependencies(src_uri, unpackers)

source code 

Return unpack dependencies string for given SRC_URI string.

Parameters:
  • src_uri (String) - SRC_URI string
  • unpackers (Dictionary) - Dictionary mapping archive suffixes to dependency strings
Returns: String
Dependency string specifying packages required to unpack archives.

Variables Details [hide private]

_slot_dep_re_cache

Value:
{False: re.compile(r'(?ux)^([\w\+][\w\+\.-]*)$'),
 True: re.compile(r'(?ux)^([\w\+][\w\+\.-]*)?(\*|=|/([\w\+][\w\+\.-]*)\
=?)?$')}

_atom_re_cache

Value:
{False: re.compile(r'(?ux)^(?P<without_use>(?:(?P<op>([=~]|[><]=?)(([\\
w\+][\w\+\.-]*/[\w\+][\w\+-]*?(-(cvs\.)?(\d+)((\.\d+)*)([a-z]?)((_(pre\
|p|beta|alpha|rc)\d*)*)(-r(\d+))?)?)-(cvs\.)?(\d+)((\.\d+)*)([a-z]?)((\
_(pre|p|beta|alpha|rc)\d*)*)(-r(\d+))?))|(?P<star>=(([\w\+][\w\+\.-]*/\
[\w\+][\w\+-]*?(-(cvs\.)?(\d+)((\.\d+)*)([a-z]?)((_(pre|p|beta|alpha|r\
c)\d*)*)(-r(\d+))?)?)-(cvs\.)?(\d+)((\.\d+)*)([a-z]?)((_(pre|p|beta|al\
pha|rc)\d*)*)(-r(\d+))?)\*)|(?P<simple>([\w\+][\w\+\.-]*/[\w\+][\w\+-]\
*?(-(cvs\.)?(\d+)((\.\d+)*)([a-z]?)((_(pre|p|beta|alpha|rc)\d*)*)(-r(\\
...

_atom_wildcard_re_cache

Value:
{True: re.compile(r'(?u)((?P<simple>([\w\+\*][\w\+\.\*-]*)/([\w\+\*][\\
w\+\.\*-]*?(-(cvs\.)?(\d+)((\.\d+)*)([a-z]?)((_(pre|p|beta|alpha|rc)\d\
*)*)(-r(\d+))?)?))|(?P<star>=(([\w\+\*][\w\+\.\*-]*)/([\w\+\*][\w\+\.\\
*-]*?))-(?P<version>\*\w+\*)))(:(?P<slot>([\w\+\./\*=-]+)))?(::(?P<rep\
o>\w[\w-]*))?$')}

_useflag_re_cache

Value:
{False: re.compile(r'^[A-Za-z0-9][A-Za-z0-9\+_@-]*$'),
 True: re.compile(r'^[A-Za-z0-9][A-Za-z0-9\+_@\.-]*$')}