pythonfinder.models.python module

class pythonfinder.models.python.PythonFinder(**data)[source]

Bases: PathEntry

class Config[source]

Bases: object

allow_mutation = True
arbitrary_types_allowed = True
include_private_attributes = True
validate_assignment = True
classmethod create(root, sort_function, version_glob_path=None, ignore_unsupported=True)[source]

Helper method for creating new pythonfinder.models.PathEntry instances.

Parameters
  • path (str) – Path to the specified location.

  • is_root (bool) – Whether this is a root from the environment PATH variable, defaults to False

  • only_python (bool) – Whether to search only for python executables, defaults to False

  • pythons (dict) – A dictionary of existing python objects (usually from a finder), defaults to None

  • name (str) – Name of the python version, e.g. anaconda3-5.3.0

Return type

PythonFinder

Returns

A new instance of the class.

find_all_python_versions(major=None, minor=None, patch=None, pre=None, dev=None, arch=None, name=None)[source]

Search for a specific python version on the path. Return all copies

Parameters
  • major (int) – Major python version to search for.

  • minor (int) – Minor python version to search for, defaults to None

  • patch (int) – Patch python version to search for, defaults to None

  • pre (bool) – Search for prereleases (default None) - prioritize releases if None

  • dev (bool) – Search for devreleases (default None) - prioritize releases if None

  • arch (str) – Architecture to include, e.g. ‘64bit’, defaults to None

  • name (str) – The name of a python version, e.g. anaconda3-5.3.0

Return type

list[PathEntry]

Returns

A list of PathEntry instances matching the version requested.

find_python_version(major=None, minor=None, patch=None, pre=None, dev=None, arch=None, name=None)[source]

Search or self for the specified Python version and return the first match.

Parameters
  • major (int) – Major version number.

  • minor (int) – Minor python version to search for, defaults to None

  • patch (int) – Patch python version to search for, defaults to None

  • pre (bool) – Search for prereleases (default None) - prioritize releases if None

  • dev (bool) – Search for devreleases (default None) - prioritize releases if None

  • arch (str) – Architecture to include, e.g. ‘64bit’, defaults to None

  • name (str) – The name of a python version, e.g. anaconda3-5.3.0

Return type

PathEntry | None

Returns

A PathEntry instance matching the version requested.

get_bin_dir(base)[source]
Return type

Path

classmethod get_paths(v)[source]
get_pythons()[source]
Return type

DefaultDict[str, PathEntry]

get_version_order()[source]
ignore_unsupported: bool

Whether to ignore any paths which raise exceptions and are not actually python

property is_asdf: bool
property is_pyenv: bool
paths: List

List of paths discovered during search

property pythons: dict
pythons_ref: Dict
root: Path
roots: Dict

The root locations used for discovery

sort_function: Optional[Callable]

The function to use to sort version order when returning an ordered version set

classmethod version_from_bin_dir(entry)[source]
Return type

PathEntry | None

version_glob_path: str

Glob path for python versions off of the root directory

property version_paths: Any
property versions: DefaultDict[tuple, PathEntry]
which(name)[source]

Search in this path for an executable.

Parameters

executable (str) – The name of an executable to search for.

Return type

PathEntry | None

Returns

PathEntry instance.

class pythonfinder.models.python.PythonVersion(**data)[source]

Bases: FinderBaseModel

class Config[source]

Bases: object

allow_mutation = True
arbitrary_types_allowed = True
include_private_attributes = True
validate_assignment = True
architecture: Optional[str]
as_dict()[source]
Return type

dict[str, int | bool | Version | None]

as_major()[source]
Return type

PythonVersion

as_minor()[source]
Return type

PythonVersion

comes_from: Optional['PathEntry']
company: Optional[str]
classmethod create(**kwargs)[source]
Return type

PythonVersion

executable: Optional[Union[str, WindowsPath, Path]]
classmethod from_path(path, name=None, ignore_unsupported=True, company=None)[source]

Parses a python version from a system path.

Raises:

ValueError – Not a valid python path

Parameters
  • path (str or PathEntry instance) – A string or PathEntry

  • name (str) – Name of the python distribution in question

  • ignore_unsupported (bool) – Whether to ignore or error on unsupported paths.

  • company (Optional[str]) – The company or vendor packaging the distribution.

Return type

PythonVersion

Returns

An instance of a PythonVersion.

classmethod from_windows_launcher(launcher_entry, name=None, company=None)[source]

Create a new PythonVersion instance from a Windows Launcher Entry

Parameters
  • launcher_entry – A python launcher environment object.

  • name (Optional[str]) – The name of the distribution.

  • company (Optional[str]) – The name of the distributing company.

Return type

PythonVersion

Returns

An instance of a PythonVersion.

get_architecture()[source]
Return type

str

is_debug: bool
is_devrelease: bool
is_postrelease: bool
is_prerelease: bool
major: int
matches(major=None, minor=None, patch=None, pre=False, dev=False, arch=None, debug=False, python_name=None)[source]
Return type

bool

minor: Optional[int]
name: Optional[str]
classmethod parse(version)[source]

Parse a valid version string into a dictionary

Raises:

ValueError – Unable to parse version string ValueError – Not a valid python version TypeError – NoneType or unparsable type passed in

Parameters

version (str) – A valid version string

Return type

dict[str, str | int | Version]

Returns

A dictionary with metadata about the specified python version.

classmethod parse_executable(path)[source]
Return type

dict[str, str | int | Version | None]

patch: Optional[int]
update_metadata(metadata)[source]

Update the metadata on the current pythonfinder.models.python.PythonVersion

Given a parsed version dictionary from pythonfinder.utils.parse_python_version(), update the instance variables of the current version instance to reflect the newly supplied values.

Return type

None

version: Optional[Version]
property version_sort: tuple[int, int, int | None, int, int]

A tuple for sorting against other instances of the same class.

Returns a tuple of the python version but includes points for core python, non-dev, and non-prerelease versions. So released versions will have 2 points for this value. E.g. (1, 3, 6, 6, 2) is a release, (1, 3, 6, 6, 1) is a prerelease, (1, 3, 6, 6, 0) is a dev release, and (1, 3, 6, 6, 3) is a postrelease. (0, 3, 7, 3, 2) represents a non-core python release, e.g. by a repackager of python like Continuum.

property version_tuple: tuple[int, int, int, bool, bool, bool]

Provides a version tuple for using as a dictionary key.

Returns

A tuple describing the python version meetadata contained.

class pythonfinder.models.python.VersionMap(**data)[source]

Bases: FinderBaseModel

class Config[source]

Bases: object

allow_mutation = True
arbitrary_types_allowed = True
include_private_attributes = True
validate_assignment = True
add_entry(entry)[source]
Return type

None

merge(target)[source]
Return type

None

versions: DefaultDict[Tuple[int, Optional[int], Optional[int], bool, bool, bool], List[PathEntry]]