stepup.core.path¶
Specialized path operations
apply_affixes(path, leading, trailing)
¶
Apply leading ./ and trailing / slashes to a path.
Parameters:
-
path(StrPath) –The path to which the affixes will be applied.
-
leading(str) –The leading slash to apply or
"". -
trailing(str) –The trailing slash to apply or
"".
Raises:
-
ValueError–If the path already has leading or trailing slashes and the corresponding affix is not None.
-
ValueError–If the leading is given and not one of
""or"./". -
ValueError–If the trailing is given and not
""or"/".
Source code in stepup/core/path.py
coerce_path(arg)
¶
coerce_paths(args)
¶
Convert a path-like argument or flat collection to path.Path instances.
coerce_paths2(args)
¶
Convert a collection of paths or path sub-collections, flattening one level of nesting.
Source code in stepup/core/path.py
coerce_str(arg)
¶
get_affixes(path)
¶
Get the leading ./ and trailing / of a path.
Parameters:
-
path(StrPath) –The path from which the affixes will be extracted.
Returns:
-
leading–The leading slash of the path, or
""if there is none. -
trailing–The trailing slash of the path, or
""if there is none.
Notes
For the special case of the path "./", the leading is "" and the trailing is "/".
Source code in stepup/core/path.py
make_path_out(path_in, dest, ext, other_exts=())
¶
Construct an output path given the input path, an out argument and the expected extension.
Parameters:
-
path_in(StrPath) –The input path from which the output path can be derived.
-
dest(StrPath | None) –An output destination. Either None (only change extension), a destination directory (requires trailing slash) or a file. In either case, the extension of the output is equal to ext.
-
ext(str | None) –The (new) extension of the output, e.g. .pdf. When None, the extension of the input is preserved.
-
other_exts(Collection[str], default:()) –Other extensions that are allowed for the output.
Returns:
-
path_out–A properly formatted output path.
Source code in stepup/core/path.py
translate(path, workdir='.')
¶
Normalize the path and, if relative, make it relative to self.root.
Parameters:
-
path(StrPath) –The path to translate. If relative, it assumed to be relative to the working directory.
-
workdir(StrPath, default:'.') –The work directory. If relative, it is assumed to be relative to
self.here
Returns:
-
translated_path–A path that can be interpreted in the working directory of the StepUp director.
Source code in stepup/core/path.py
translate_back(path, workdir='.')
¶
If relative, make it relative to work directory, assuming it is relative to self.root.
Parameters:
-
path(StrPath) –The path to translate. If relative, it is assumed to be relative to
ROOT. -
workdir(StrPath, default:'.') –The working directory. If relative, it is assumed to be relative to
HERE.
Returns:
-
back_translated_path–A path that can be interpreted in the working directory.