nitpick.generic module

Generic functions and classes.

nitpick.generic.filter_names(iterable: Iterable, *partial_names: str) list[str][source]

Filter names and keep only the desired partial names.

Exclude the project name automatically.

>>> file_list = ['requirements.txt', 'tox.ini', 'setup.py', 'nitpick']
>>> filter_names(file_list)
['requirements.txt', 'tox.ini', 'setup.py']
>>> filter_names(file_list, 'ini', '.py')
['tox.ini', 'setup.py']
>>> mapping = {'requirements.txt': None, 'tox.ini': 1, 'setup.py': 2, 'nitpick': 3}
>>> filter_names(mapping)
['requirements.txt', 'tox.ini', 'setup.py']
>>> filter_names(file_list, 'x')
['requirements.txt', 'tox.ini']
nitpick.generic.relative_to_current_dir(path_or_str: PathOrStr | None) str[source]

Return a relative path to the current dir or an absolute path.

nitpick.generic.url_to_python_path(url: furl) Path

Convert the segments of a file URL to a path.

nitpick.generic.version_to_tuple(version: str = None) tuple[int, ...][source]

Transform a version number into a tuple of integers, for comparison.

>>> version_to_tuple("")
()
>>> version_to_tuple("  ")
()
>>> version_to_tuple(None)
()
>>> version_to_tuple("1.0.1")
(1, 0, 1)
>>> version_to_tuple(" 0.2 ")
(0, 2)
>>> version_to_tuple(" 2 ")
(2,)
Parameters

version – String with the version number. It must be integers split by dots.

Returns

Tuple with the version number.