Pkg Utils

walk_files(top, max_depth=-1, exclude_dirs=None, include_ext=None)[source]

Walk through the files recursively.

Parameters:
  • top (str | Path) – Path to start from

  • max_depth (int) – Max recursion depth. If -1, there is no limit for recursion

  • exclude_dirs (set[str] | None) – Dirs to exclude. No dirs are excluded by default, but it is recommended to exlude dirs such as __pycache__, .tox etc

  • include_ext (set[str] | None) – Extensions to include. If None or empty, all extensions are included

Returns:

Generator that produces files satisfying all given values

Return type:

Iterator[Path]

is_python_package(path)[source]

Determine whether a given directory is a package or not.

Parameters:

path (Path) – Path to the inspected dir

Returns:

True if dir is a Python package, False otherwise

Return type:

bool

module_name_from_path(file_path, pkg_root, pkg)[source]

Compute importable module path.

Parameters:
  • file_path (Path) – Path to the .py file

  • pkg_root (Path) – Root of the package

  • pkg (str) – Package to import

Returns:

Importable path to module

Return type:

str