nxt.nxt_path module
Common nxt pathing operations. Both for file and node paths.
- clear_file_expand_cache()[source]
Forget cached path expansions.
Called when a graph starts executing, so each run resolves against the filesystem as it is at that moment.
- full_file_expand(path, start=None)[source]
A combination of commonly used os.path functions called to completely expand given path. If start is given, os.cwd is temporarily changed in order to influence the start of relative path expansion. Return value will always use forward slashes as seperator.
- Parameters
path (str) – path to expand
start (str, optional) – base directory to expand from, defaults to os cwd
- Returns
given path expanded. Relative paths, environment variables, and user character “~” are expanded.
- Return type
[type]
- unify_env_vars(path, target_platform='win32')[source]
Replace foreign platform environment variables with platform native ones Environment variable patterns must be defined in PLATFORM_VAR_PATTERN_MAP and PLATFORM_VAR_PATTERN_MAP to be able to find and replace.
In short, if you’re on windows, convert linux style environment vars to windows style. If you’re on linux, the reverse.
Supports mixed type environment variables.
- Parameters
path – string to replace variables in
target_platform (str, optional) – platform to unify as, defaults to sys.platform
- Returns
given path as unified as possible
- Return type
str
- expand_relative_node_path(rel_path, start_node_path)[source]
Expands given node rel_path using start_node_path as root of relative path. This function does not validate the path, it is only a string machine.
- Parameters
rel_path (str) – relative path to expand.
start_node_path (str) – node to treat as root of relative path.
- Returns
expanded node path
- Return type
str
- path_attr_partition(str_path)[source]
Returns a tuple of the node path and attribute name from the given path.
>>> nxt_path.node_path_partition('somewhere/else.attr') ('somewhere/else', 'attr') >>> nxt_path.node_path_partition('...attr') ('..', 'attr') >>> nxt_path.node_path_partition('..attr') ('.', 'attr')
- Parameters
str_path (str) – node or attribute path
- Returns
tuple of node path and attr name (‘node/path’, ‘attr_name’)
- Return type
tuple
- str_path_to_node_namespace(str_path)[source]
Given an absolute node or attr str_path, split it into the list-“namespace” format used by stage. NOTE that if given an attribute path, that attribute name will not be present in the returned path.
- node_namespace_to_str_path(namespace)[source]
Given a node namespace, return it rejoined into a full string path.
- node_path_from_attr_path(attr_path)[source]
Given an attribute path, return the node path contained within.
- Parameters
attr_path (str) – path to attribute
- Returns
node path
- Return type
str
- attr_name_from_attr_path(attr_path)[source]
Given an attribute path, return the attribute name.
- Parameters
attr_path (str) – path to attribute
- Returns
attr name contained within input
- Return type
str
- node_name_from_node_path(node_path)[source]
Given a node path, return the node name of specified node.
- Parameters
node_path (node path to get node name from) – str
- Returns
node name
- Return type
str
- get_parent_path(node_path)[source]
Returns the parent path implied by given node_path
- Parameters
node_path (node path to get parent path from) – str
- Returns
parent path
- Return type
str
- get_root_path(node_path)[source]
Returns the implied “root” node of the given path. A root is a node with no parent.
- Parameters
node_path (node path to get root path from) – str
- Returns
root path
- Return type
str
- is_attr_path(path)[source]
Whether the given path appears to be a path to an attribute.
- Parameters
node_path (path to check) – str
- Returns
True/False whether path appears to be an attribute path.
- Return type
bool
- make_attr_path(node_path, attr_name)[source]
Given a node path and attr name, join them into an attribute path.
- Parameters
node_path (str) – node path to join
attr_name (str) – attr name to join
- Returns
constructed attribute path
- Return type
str
- join_node_paths(node_path1, node_path2)[source]
Given 2 node paths, treat node_path1 as ancestor, and combine their paths together
- Parameters
node_path1 (str) – intended ancestor of given paths
node_path2 (str) – intended descendant of given paths
- Returns
path to descendant of node_path1
- Return type
str
- replace_ancestor(path, old_ancestor, new_ancestor)[source]
Given a node path, replace given old ancestor path with new ancestor path.
- Parameters
path (str) – Original path which will have its ancestor replaced
old_ancestor (str) – Path to ancestor of path that will be replaced
new_ancestor (str) – New ancestor to replace old_ancestor
- Returns
New path with old_ancestor replaced with new_ancestor
- Return type
str
- is_ancestor(path_to_check, ancestor_path)[source]
Returns if given ancestor_path is an ancestor path to path_to_check
- Parameters
path_to_check (str) – potential descendant path
ancestor_path (str) – potential ancestor path
- Returns
Whether ancestor_path is ancestor of path_to_check
- Return type
bool
- all_ancestor_paths(path)[source]
Returns the ancestor paths implied by given path
- Parameters
path (str) – node path
- Returns
list of implied ancestor paths
- Return type
list
- get_path_depth(path)[source]
Get depth of given path. Depth is number of nodes deep from world. World is depth 0.
- Parameters
path (str) – path to check depth of.
- Returns
depth of given path.
- Return type
int
- trim_to_depth(path, trim_depth)[source]
Trim a path to given depth. Removes nodes from the end of the path to trim to an ancestor path of given path. If trim depth is 0, world path is returned. If trim depth is greater than or equal to the depth of given path, path is returned unchanged.
- Parameters
path (str) – path to trim
trim_depth (int) – depth to trim to
- Returns
path, trimmed to trim depth if possible
- Return type
str