b3j0f.utils.path module

Tools for managing path resolution of python objects.

b3j0f.utils.path.clearcache(path=None)[source]

Clear cache memory for input path.

Parameters:path (str) – element path to remove from cache. If None clear all cache
Example:
>>> incache('b3j0f.utils')
False
>>> lookup('b3j0f.utils')
>>> incache('b3j0f.utils')
True
>>> clearcache('b3j0f.path')
>>> incache('b3j0f.utils')
False
>>> lookup('b3j0f.utils')
>>> incache('b3j0f.utils')
True
>>> clearcache()
>>> incache('b3j0f.utils')
False
b3j0f.utils.path.getpath(element)[source]

Get full path of a given element such as the opposite of the resolve_path behaviour.

Parameters:element – must be directly defined into a module or a package and has the attribute ‘__name__’.
Returns:element absolute path.
Return type:str
Raises AttributeError:
 if element has not the attribute __name__.
Example:
>>> getpath(getpath)
b3j0f.utils.path.getpath
b3j0f.utils.path.incache(path)[source]

Check if input path is in cache.

Returns:True if path is in cache
Return type:bool
Example:
>>> incache('b3j0f.utils')
False
>>> lookup('b3j0f.utils')
>>> incache('b3j0f.utils')
True
b3j0f.utils.path.lookup(path, cache=True)[source]

Get element reference from input element.

Limitations:

it does not resolve class methods or static values such as True, False, numbers, string and keywords.

Parameters:
  • path (str) – full path to a python element.
  • cache (bool) – if True (default), permits to reduce time complexity for lookup resolution in using cache memory to save resolved elements.
Returns:

python object which is accessible through input path or raise an exception if the path is wrong.

Return type:

object

Raises ImportError:
 

if path is wrong

b3j0f.utils.path.random() → x in the interval [0, 1).