pythonfinder.utils module

pythonfinder.utils.dedup(iterable)[source]

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

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.

Returns

A fully expanded Path object.

Return type

Path

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

Recursively expand a list or PathEntry instance

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

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

Returns

An iterator over the expanded set of path entries

Return type

Iterator[PathEntry]

pythonfinder.utils.filter_pythons(path)[source]

Return all valid pythons in a given path

pythonfinder.utils.get_python_version(path)[source]

Get python version string using subprocess from a given path.

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

Returns

The guessed company

Return type

Optional[str]

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.

Returns

Whether the provided name looks like python.

Return type

bool

pythonfinder.utils.normalize_path(path)[source]
pythonfinder.utils.optional_instance_of(cls)[source]

Return an validator to determine whether an input is an optional instance of a class.

Returns

A validator to determine optional instance membership.

Return type

_OptionalValidator

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]
pythonfinder.utils.path_is_executable(path)[source]

Determine whether the supplied path is executable.

Returns

Whether the provided path is executable.

Return type

bool

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.

Returns

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

Return type

bool

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.

Returns

Whether the provided path is an executable path to python.

Return type

bool

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

Returns

Whether that path is a PythonCore path or not

Return type

bool

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