pythonfinder.utils module

pythonfinder.utils.dedup(iterable)[source]

Deduplicate an iterable object like iter(set(iterable)) but order-reserved.

Return type

Iterable

pythonfinder.utils.ensure_path(path)[source]

Given a path (either a string or a Path object), expand variables and return a Path object.

Parameters

path (str or Path) – A string or a Path object.

Return type

Path

Returns

A fully expanded Path object.

pythonfinder.utils.expand_paths(path, only_python=True)[source]

Recursively expand a list or PathEntry instance

Parameters
  • path (Union[Sequence, PathEntry]) – The path or list of paths to expand

  • only_python (bool) – Whether to filter to include only python paths, default True

Return type

Iterator

Returns

An iterator over the expanded set of path entries

pythonfinder.utils.filter_pythons(path)[source]

Return all valid pythons in a given path

Return type

Iterable | Path

pythonfinder.utils.get_python_version(path)[source]

Get python version string using subprocess from a given path.

Return type

str

pythonfinder.utils.guess_company(path)[source]

Given a path to python, guess the company who created it

Parameters

path (str) – The path to guess about

Return type

str | None

Returns

The guessed company

pythonfinder.utils.is_in_path(path, parent)[source]
pythonfinder.utils.looks_like_python(name)[source]

Determine whether the supplied filename looks like a possible name of python.

Parameters

name (str) – The name of the provided file.

Return type

bool

Returns

Whether the provided name looks like python.

pythonfinder.utils.normalize_path(path)[source]
Return type

str

pythonfinder.utils.parse_asdf_version_order(filename='.tool-versions')[source]
pythonfinder.utils.parse_pyenv_version_order(filename='version')[source]
pythonfinder.utils.parse_python_version(version_str)[source]
Return type

dict[str, str | int | Version]

pythonfinder.utils.path_is_executable(path)[source]

Determine whether the supplied path is executable.

Return type

bool

Returns

Whether the provided path is executable.

pythonfinder.utils.path_is_known_executable(path)[source]

Returns whether a given path is a known executable from known executable extensions or has the executable bit toggled.

Parameters

path (Path) – The path to the target executable.

Return type

bool

Returns

True if the path has chmod +x, or is a readable, known executable extension.

pythonfinder.utils.path_is_python(path)[source]

Determine whether the supplied path is executable and looks like a possible path to python.

Parameters

path (Path) – The path to an executable.

Return type

bool

Returns

Whether the provided path is an executable path to python.

pythonfinder.utils.path_is_pythoncore(path)[source]

Given a path, determine whether it appears to be pythoncore.

Does not verify whether the path is in fact a path to python, but simply does an exclusionary check on the possible known python implementations to see if their names are present in the path (fairly dumb check).

Parameters

path (str) – The path to check

Return type

bool

Returns

Whether that path is a PythonCore path or not

pythonfinder.utils.split_version_and_name(major=None, minor=None, patch=None, name=None)[source]
Return type

tuple[str | int | None, str | int | None, str | int | None, str | None]

pythonfinder.utils.unnest(item)[source]