Safe path

Portions of a Path take into account platform must be dealt withpSafely deal with paths.

wreck._safe_path.__all__: tuple[str, str, str, str, str, str, str, str] = ("fix_relpath", "is_linux", "is_macos", "is_win",    "replace_suffixes", "resolve_path", "resolve_joinpath",    "get_venv_python_abspath")

Module exports

wreck._safe_path.fix_relpath(relpath_b)

Paths are normally expressed as posix paths. On Windows, relpath must be converted.

src/complete_awesome_perfect/_version.py

becomes

src\complete_awesome_perfect\_version.py

Parameters:

relpath_b (pathlib.PurePath | pathlib.Path | str) – A posix style path. Requiring fixing before joinpath

Returns:

Platform specific pure path

Return type:

pathlib.PureWindowsPath | pathlib.PurePosixPath

wreck._safe_path.get_venv_python_abspath(path_cwd, venv_relpath)

Within the package base folder, venv(s) should have been created within subfolder(s).

Given the package base folder and the venv relative path, get the platform specific python executable absolute path

Parameters:
Returns:

venv’s python executable absolute path

Return type:

str

Raises:
  • TypeError – 1st arg Unsupported type. Expecting Path or PurePath

  • NotADirectoryError – Missing venv folder. May indicate run under gh workflow or tox

wreck._safe_path.is_linux()

Check platform is Linux.

When messages are intended for Windows, but would like to see on Linux as well.

Returns:

True if platform is Linux

Return type:

bool

wreck._safe_path.is_macos()

Check platform is MacOS

Returns:

True if platform is MacOS

Return type:

bool

wreck._safe_path.is_win()

Check platform is Windows

Returns:

True if platform is Windows

Return type:

bool

wreck._safe_path.replace_suffixes(abspath_a, suffixes)

Replace suffixes.

Parameters:
Returns:

abspath with replaced suffixes

Return type:

pathlib.PurePath | pathlib.Path

wreck._safe_path.resolve_joinpath(abspath_a, relpath_b)

Windows safe joinpath. Fixes relative path

Parameters:
Returns:

Platform specific pure path

Return type:

pathlib.PureWindowsPath | pathlib.PurePosixPath | type[pathlib.Path]

wreck._safe_path.resolve_path(str_cmd)

Windows safe resolve executable path

Parameters:

str_cmd (str) – Relative path to executable

Returns:

Windows safe absolute path to executable

Return type:

str | None