util
frequenz.repo.config.nox.util ¤
General purpose utilities.
This module contains general purpose utilities that are used by the other modules in this package.
Functions¤
frequenz.repo.config.nox.util.deduplicate ¤
Filter out duplicates from an iterable preserving the original iterable order.
PARAMETER | DESCRIPTION |
---|---|
iterable
|
The iterable to remove duplicates from.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Iterable[_T]
|
The elements of |
Source code in frequenz/repo/config/nox/util.py
frequenz.repo.config.nox.util.discover_paths ¤
Discover paths to check.
Discover the paths to check by looking into different sources, like the
pyproject.toml
file.
Currently the following paths are discovered:
- The
testpaths
option in thetools.pytest.ini_options
section ofpyproject.toml
.
RETURNS | DESCRIPTION |
---|---|
list[str]
|
The discovered paths to check. |
Source code in frequenz/repo/config/nox/util.py
frequenz.repo.config.nox.util.existing_paths ¤
Filter paths to only leave valid paths that exist and are unique.
PARAMETER | DESCRIPTION |
---|---|
paths
|
The paths to check and filter. |
RETURNS | DESCRIPTION |
---|---|
Iterable[Path]
|
An iterable with the valid paths as |
Example
assert list(existing_paths([".", "/fake"])) == [pathlib.Path(".")]
Source code in frequenz/repo/config/nox/util.py
frequenz.repo.config.nox.util.find_toplevel_package_dirs ¤
Find top-level packages directories in a path
.
Searches recursively for the top-level packages in path
, relative to
root
.
PARAMETER | DESCRIPTION |
---|---|
path
|
The path to look for python packages.
TYPE:
|
root
|
The part of the path that is considered the root and will be
removed from the resulting path. If
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Iterable[Path]
|
The top-level paths that contains a |
Iterable[Path]
|
removed. |
Examples:
If we have a directory like the following:
.
├── noxfile.py
└── src
└── frequenz
└── repo
└── config
├── __init__.py
├── nox
│ ├── config.py
│ ├── default.py
│ ├── __init__.py
│ ├── session.py
│ └── util.py
└── setuptools.py
Then calling find_toplevel_package_dirs(pathlib.Path("src"))
will
return an iterator producing: ["frequenz/repo/config"]
.
Source code in frequenz/repo/config/nox/util.py
frequenz.repo.config.nox.util.flatten ¤
Flatten an iterable of iterables into one iterable with all the elements.
PARAMETER | DESCRIPTION |
---|---|
iterables
|
The iterables to flatten. |
RETURNS | DESCRIPTION |
---|---|
Iterable[_T]
|
The flattened iterable. |
Example
assert list(flatten([(1, 2), (3, 4)]) == [1, 2, 3, 4]
Source code in frequenz/repo/config/nox/util.py
frequenz.repo.config.nox.util.is_python_file ¤
frequenz.repo.config.nox.util.min_dependencies ¤
Extract the minimum dependencies from pyproject.toml.
RETURNS | DESCRIPTION |
---|---|
list[str]
|
The minimun dependencies defined in pyproject.toml. |
RAISES | DESCRIPTION |
---|---|
RuntimeError
|
If minimun dependencies are not properly set in pyproject.toml. |
Source code in frequenz/repo/config/nox/util.py
frequenz.repo.config.nox.util.path_to_package ¤
Convert paths to Python package names.
Paths should exist and be either a directory or a file ending with .pyi?
(otherwise this function will assert). The root
and path
are
concatenated when performing the check.
Directory separators in path
are replaced with .
and the .pyi?
suffix
is removed (if present).
PARAMETER | DESCRIPTION |
---|---|
path
|
The path to convert.
TYPE:
|
root
|
The root where the path is located. If
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
The package name based on |
Examples:
src/frequenz/pkg
(root="src"
) will be converted tofrequenz.pkg
.noxfile.py
(withoutroot
) will be converted tonoxfile
.
Source code in frequenz/repo/config/nox/util.py
frequenz.repo.config.nox.util.replace ¤
Replace elements in an iterable.
PARAMETER | DESCRIPTION |
---|---|
iterable
|
The iterable to replace elements in.
TYPE:
|
replacements
|
A mapping of elements to replace with other elements.
TYPE:
|
YIELDS | DESCRIPTION |
---|---|
Iterable[_T]
|
The next element in the iterable, with the replacements applied. |
Example
assert list(replace([1, 2, 3], {1: 4, 2: 5})) == [4, 5, 3]