pythonfinder.models.python module

class pythonfinder.models.python.PythonFinder(path=None, children=NOTHING, only_python=False, name=NOTHING, py_version=None, is_dir=None, is_executable=None, is_python=None, root=None, ignore_unsupported=True, version_glob_path='versions/*', sort_function=None, roots=NOTHING, paths=NOTHING, shim_dir='shims', versions=NOTHING, pythons=NOTHING)[source]

Bases: pythonfinder.models.mixins.BaseFinder, pythonfinder.models.mixins.BasePath

classmethod create(root, sort_function, version_glob_path=None, ignore_unsupported=True)[source]
property expanded_paths
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

Returns

A list of PathEntry instances matching the version requested.

Return type

List[PathEntry]

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

Returns

A PathEntry instance matching the version requested.

get_bin_dir(base)[source]
get_paths()[source]
get_pythons()[source]
get_version_order()[source]
ignore_unsupported

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

property is_asdf
property is_pyenv
paths

List of paths discovered during search

property pythons
root
roots

The root locations used for discovery

shim_dir

shim directory

sort_function

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

classmethod version_from_bin_dir(entry)[source]
version_glob_path

Glob path for python versions off of the root directory

property versions
which(name)[source]

Search in this path for an executable.

Parameters

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

Returns

PathEntry instance.

class pythonfinder.models.python.PythonVersion(major=0, minor=None, patch=None, is_prerelease=False, is_postrelease=False, is_devrelease=False, is_debug=False, version=None, architecture=None, comes_from=None, executable=None, company=None, name=None)[source]

Bases: object

architecture
as_dict()[source]
as_major()[source]
as_minor()[source]
comes_from
company
classmethod create(**kwargs)[source]
executable
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.

Returns

An instance of a PythonVersion.

Return type

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.

Returns

An instance of a PythonVersion.

Return type

PythonVersion

get_architecture()[source]
is_debug
is_devrelease
is_postrelease
is_prerelease
major
matches(major=None, minor=None, patch=None, pre=False, dev=False, arch=None, debug=False, python_name=None)[source]
minor
name
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 unparseable type passed in

Parameters

version (str) – A valid version string

Returns

A dictionary with metadata about the specified python version.

Return type

dict

classmethod parse_executable(path)[source]
patch
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.

version
property version_sort

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

Provides a version tuple for using as a dictionary key.

Returns

A tuple describing the python version meetadata contained.

Return type

tuple

class pythonfinder.models.python.VersionMap(versions=NOTHING)[source]

Bases: object

add_entry(entry)[source]
merge(target)[source]
pythonfinder.models.python.overload(f)[source]