README
liblaf.cherries.utils
¶
Classes:
-
GitUrlParsed–Subset of attributes returned by
giturlparse.parse.
Functions:
-
flatten_dict–Flatten nested mappings into slash-delimited keys.
-
giturlparse–Parse a Git remote URL with the attributes Cherries needs.
-
pretty_yaml–Serialize
dataas YAML, converting path-like objects to strings. -
relative_or_absolute–Return
pathrelative toprefix, or as an absolute path. -
relative_or_name–Return
pathrelative toprefix, or just its file name. -
unflatten_dict–Expand slash-delimited keys into nested dictionaries.
GitUrlParsed
¶
Bases: Protocol
flowchart TD
liblaf.cherries.utils.GitUrlParsed[GitUrlParsed]
click liblaf.cherries.utils.GitUrlParsed href "" "liblaf.cherries.utils.GitUrlParsed"
Subset of attributes returned by giturlparse.parse.
Attributes:
flatten_dict
¶
Flatten nested mappings into slash-delimited keys.
Parameters:
-
mapping(Mapping[str, Any]) –Mapping to flatten.
-
prefix(str, default:'') –Prefix already accumulated by a recursive call.
-
sep(str, default:'/') –Separator inserted between nested key segments.
Returns:
Examples:
Source code in src/liblaf/cherries/utils/_dict.py
giturlparse
¶
giturlparse(url: str) -> GitUrlParsed
Parse a Git remote URL with the attributes Cherries needs.
Examples:
>>> info = giturlparse("https://github.com/liblaf/cherries.git")
>>> (info.platform, info.owner, info.repo)
('github', 'liblaf', 'cherries')
Source code in src/liblaf/cherries/utils/_git.py
pretty_yaml
¶
Serialize data as YAML, converting path-like objects to strings.
relative_or_absolute
¶
Return path relative to prefix, or as an absolute path.
Parameters:
-
path(Path) –Path to display or serialize.
-
prefix(Path) –Directory that should be stripped when
pathis inside it.
Returns:
-
Path–path.relative_to(prefix)when possible; otherwisepath.resolve().
Examples:
>>> relative_or_absolute(
... Path("/tmp/cherries/data/out.txt"), Path("/tmp/cherries")
... )
PosixPath('data/out.txt')
>>> relative_or_absolute(Path("/var/tmp/out.txt"), Path("/tmp/cherries"))
PosixPath('/var/tmp/out.txt')
Source code in src/liblaf/cherries/utils/_path.py
relative_or_name
¶
Return path relative to prefix, or just its file name.
This keeps copied artifact names short even when a user logs a file outside the experiment working directory.
Parameters:
-
path(Path) –Path to display or copy.
-
prefix(Path) –Directory that should be stripped when
pathis inside it.
Returns:
-
Path–path.relative_to(prefix)when possible; otherwisePath(path.name).
Examples:
>>> relative_or_name(Path("/tmp/cherries/data/out.txt"), Path("/tmp/cherries"))
PosixPath('data/out.txt')
>>> relative_or_name(Path("/var/tmp/out.txt"), Path("/tmp/cherries"))
PosixPath('out.txt')
Source code in src/liblaf/cherries/utils/_path.py
unflatten_dict
¶
Expand slash-delimited keys into nested dictionaries.
Parameters:
-
mapping(Mapping[str, Any]) –Flat mapping to expand.
-
sep(str, default:'/') –Separator used between nested key segments.
Returns:
Examples: