pathsjson package

Submodules

pathsjson.automagic module

pathsjson.cli module

pathsjson.cli.extract_command(args)[source]
pathsjson.cli.main(args=None)[source]

pathsjson.helpers module

pathsjson.helpers.create_user_globals_file(overwrite=False)[source]

Create the OS-dependent global paths.json file.

Parameters:overwrite – overwrites the global file if True, otherwise raises a RuntimeError (default)
Returns:the filepath to the created file
pathsjson.helpers.expand(data)[source]

Expand the paths.json data structure into intermediary format.

Parameters:data – The paths.json data structure
Returns:a mapping of path_name => [path_element, …]. Each element is either a string (for path literal) or a pair of environmental variable name to default value.
pathsjson.helpers.find_file_asc(src_dir=None, target_name='.paths.json', limit=None)[source]

Walk file system towards root in search of the first target.

Parameters:
  • src_dir – the directory to start from or the cwd by default.
  • target_name – the file name to find
  • limit – the maximum number of parent directory visits
Returns:

the file path to the target or None if not found

pathsjson.helpers.get_user_globals_path()[source]
Returns:the OS-dependent path to the user’s global paths.json file.
pathsjson.helpers.inject_special_variables(data, file_path)[source]

Patch the paths.json data structure with special variables in place.

Parameters:file_path – the file path of the loaded paths.json.
Returns:the paths.json data structure
pathsjson.helpers.is_env_var(s)[source]

Environmental variables have a ‘$$’ prefix.

pathsjson.helpers.is_path_var(s)[source]

Path variables start with one and only one ‘$’.

pathsjson.helpers.load_user_globals()[source]
Returns:the data in the user’s global paths.json file or None if it doesn’t exist
pathsjson.helpers.patch_with_env(data)[source]

Patch the paths.json data structure with environmental variables in place.

Note this only patches defined paths or environmental variables.

Parameters:data – the paths.json data structure.
Returns:the data structure
pathsjson.helpers.patch_with_user_globals(data, skip_noexist=True)[source]

Patch the paths.json data structure with the user’s globals in place.

Parameters:
  • data – the paths.json data structure
  • skip_noexist – skip applying global data if it doesn’t exist otherwise raise an error for a non-existant file
Returns:

the patched data

pathsjson.helpers.path_vars_in(d)[source]

Extract all (and only) the path vars in a dictionary.

Parameters:d – a .paths.json data structure
Returns:all path var definitions without any special entries like ‘__ENV’
pathsjson.helpers.to_dependencies_of(g)[source]

Compute the dependencies of each path var.

Parameters:d – an adjacency list of dependency => [depends on, …]
Returns:an adjacency list of the given data structure such that the k => [depends on, …]. The vertices in the values are presorted to ensure reproducible results
pathsjson.helpers.to_paths(expansion)[source]

Converts an exanded paths.json data structure into a mapping of paths.

Parameters:expansion – the expansion of a paths.json data structure
Returns:a dict of path_name => Path
pathsjson.helpers.to_requirements_of(d)[source]

Compute the requirements of each path var.

Parameters:d – a .paths.json data structure
Returns:an adjacency list of the given data structure such that the dependency => [depends on, …]
pathsjson.helpers.topo_sort(requirements, ns=None)[source]

Topographical sort over the requirements graph.

Parameters:
  • requirements – the requirements graph of a paths.json file.
  • ns – an (optional) map of path variable to path that allows external bindings, e.g. a global file.
Returns:

a topographical ordering suitable for processing the dependency graph

pathsjson.impl module

class pathsjson.impl.PathsJSON(file_path=None, src_dir=None, target_name='.paths.json', enable_env_overrides=True, enable_user_global_overrides=True, validate=True)[source]

Bases: object

all_resolvable_paths
reload()[source]

Reload the path definitions.

resolve(k, *args, **kwargs)[source]
resolve_path(k, *args, **kwargs)[source]

pathsjson.path module

class pathsjson.path.Path(path, arg_names=None, defaults=None)[source]

Bases: object

arg_names
defaults
path
resolve(*args, **kwargs)[source]

Resolve the path for use including variable interpolation.

If there are too many parameter, resolution raises a TypeError (just like a function with too many parameters would raise.) Otherwise, it scans over the path arguments from left to right. During the scan, if the argument name exists in the kwargs, it’s popped off from the kwargs. If there are more required arguments than there are given arguments – both keyword and positional – it will try to use the defaults for all arguments prefixed with an underscore.

Parameters:
  • args – positional arguments for interpolation
  • kwargs – keyword-based arguments for interpolation
Returns:

a path string

pathsjson.resolution module

class pathsjson.resolution.Resolution(path_str)[source]

Bases: object

open(*args, **kwargs)[source]

Opens the file and automatically creates the directory if nessessary.

Yields:

the file pointer

Parameters:
  • args – passed to open
  • kwargs – passed to open
path_str