API Reference

This is the place where the functions and classes in distlib's public API are described.

The distlib.database package

Classes

class DistributionPath

This class represents a set of distributions which are installed on a Python path (like PYTHONPATH / sys.path). Both new-style (distlib) and legacy (egg) distributions are catered for.

Methods:

__init__(path=None, include_egg=False)

Initialise the instance using a particular path.

Parameters:
  • path (list of str) – The path to use when looking for distributions. If None is specified, sys.path is used.
  • include_egg – If True, legacy distributions (eggs) are included in the search; otherwise, they aren’t.
enable_cache()

Enables a cache, so that metadata information doesn’t have to be fetched from disk. The cache is per instance of the DistributionPath instance and is enabled by default. It can be disabled using disable_cache() and cleared using clear_cache() (disabling won’t automatically clear it).

disable_cache()

Disables the cache, but doesn’t clear it.

clear_cache()

Clears the cache, but doesn’t change its enabled/disabled status. If enabled, the cache will be re-populated when querying for distributions.

get_distributions()

The main querying method if you want to look at all the distributions. It returns an iterator which returns Distribution and, if include_egg was specified as True for the instance, also instances of any EggInfoDistribution for any legacy distributions found.

get_distribution(name)

Looks for a distribution by name. It returns the first one found with that name (there should only be one distribution with a given name on a given search path). Returns None if no distribution was found, or else an instance of Distribution (or, if include_egg was specified as True for the instance, an instance of EggInfoDistribution if a legacy distribution was found with that name).

Parameters:name (str) – The name of the distribution to search for.
get_exported_entries(category, name=None)

Returns an iterator for entries exported by distributions on the path.

Parameters:
  • category (str) – The export category to look in.
  • name (str) – A specific name to search for. If not specified, all entries in the category are returned.
Returns:

An iterator which iterates over exported entries (instances of ExportEntry).

class Distribution

A class representing a distribution, typically one which hasn’t been installed (most likely, one which has been obtained from an index like PyPI).

Properties:

name

The name of the distribution.

version

The version of the distribution.

metadata

The metadata for the distribution. This is a distlib.metadata.Metadata instance.

source_url

The download URL for the source distribution.

digest

The digest for the source distribution. This is either None or a 2-tuple consisting of the hashing algorithm and the digest using that algorithm, e.g. ('sha256', '01234...').

locator

The locator for an instance which has been retrieved through a locator. This is None for an installed distribution.

class InstalledDistribution(Distribution)

A class representing an installed distribution. This class is not instantiated directly, except by packaging tools. Instances of it are returned from querying a DistributionPath.

Properties:

requested

Whether the distribution was installed by user request (if not, it may have been installed as a dependency of some other distribution).

exports

The distribution’s exports, as described in Exporting things from Distributions. This is a cached property.

Methods:

list_installed_files(local=False)

Returns an iterator over all of the individual files installed as part of the distribution, including metadata files. The iterator returns tuples of the form (path, hash, size). The list of files is written by the installer to the RECORD metadata file.

Parameters:local – If True, the paths returned are local absolute paths (i.e. with platform-specific directory separators as indicated by os.sep); otherwise, they are the values stored in the RECORD metadata file.
list_distinfo_files(local=False)

Similar to list_installed_files(), but only returns metadata files.

Parameters:local – As for list_installed_files().
check_installed_files()

Runs over all the installed files to check that the size and checksum are unchanged from the values in the RECORD file, written when the distribution was installed. It returns a list of mismatches. If the files in the distribution haven’t been corrupted , an empty list will be returned; otherwise, a list of mismatches will be returned.

Returns:A list which, if non-empty, will contain tuples with the following elements:
  • The path in RECORD which failed to match.
  • One of the strings ‘exists’, ‘size’ or ‘hash’ according to what didn’t match (existence is checked first, then size, then hash).
  • The expected value of what didn’t match (as obtained from RECORD).
  • The actual value of what didn’t match (as obtained from the file system).
read_exports(filename=None)

Read exports information from a file.

Normal access to a distribution’s exports should be through its exports attribute. This method is called from there as needed. If no filename is specified, the EXPORTS file in the .dist-info directory is read (it is expected to be present).

Parameters:filename (str) – The filename to read from, or None to read from the default location.
Returns:The exports read from the file.
Return type:dict
write_exports(exports, filename=None)

Write exports information to a file.

If no filename is specified, the EXPORTS file in the .dist-info directory is written.

Parameters:
  • exports (dict) – A dictionary whose keys are categories and whose values are dictionaries which contain ExportEntry instances keyed on their name.
  • filename (str) – The filename to read from, or None to read from the default location.
class EggInfoDistribution

Analogous to Distribution, but covering legacy distributions. This class is not instantiated directly. Instances of it are returned from querying a DistributionPath.

Properties:

name

The name of the distribution.

version

The version of the distribution.

metadata

The metadata for the distribution. This is a distlib.metadata.Metadata instance.

Methods:

list_installed_files(local=False)

Returns a list all of the individual files installed as part of the distribution.

Parameters:local – If True, the paths returned are local absolute paths (i.e. with platform-specific directory separators as indicated by os.sep).
class DependencyGraph

This class represents a dependency graph between releases. The nodes are distribution instances; the edges model dependencies. An edge from a to b means that a depends on b.

add_distribution(distribution)

Add distribution to the graph.

add_edge(x, y, label=None)

Add an edge from distribution x to distribution y with the given label (string).

add_missing(distribution, requirement)

Add a missing requirement (string) for the given distribution.

repr_node(dist, level=1)

Print a subgraph starting from dist. level gives the depth of the subgraph.

Direct access to the graph nodes and edges is provided through these attributes:

adjacency_list

Dictionary mapping distributions to a list of (other, label) tuples where other is a distribution and the edge is labelled with label (i.e. the version specifier, if such was provided).

reverse_list

Dictionary mapping distributions to a list of predecessors. This allows efficient traversal.

missing

Dictionary mapping distributions to a list of requirements that were not provided by any distribution.

The distlib.resources package

Attributes

cache

An instance of Cache, which uses the default base location for the cache (as described in the documentation for Cache.__init__()).

Functions

finder(package)[source]

Get a finder for the specified package.

If the package hasn’t been imported yet, an attempt will be made to import it. If importing fails, an ImportError will be raised.

Parameters:package (str) – The name of the package for which a finder is desired.
Returns:A finder for the package.
register_finder(loader, finder_maker)[source]

Register a callable which makes finders for a particular type of PEP 302 loader.

Parameters:
  • loader – The loader for which a finder is to be returned.
  • finder_maker – A callable to be registered, which is called when a loader of the specified type is used to load a package. The callable is called with a single argument – the Python module object corresponding to the package – and must return a finder for that package.

Classes

class Resource[source]

A class representing resources. It is never instantiated directly, but always through calling a finder’s find method.

Properties:

is_container

Whether this instance is a container of other resources.

bytes[source]

All of the resource data as a byte string. Raises an exception if accessed on a container resource.

size[source]

The size of the resource data in bytes. Raises an exception if accessed on a container resource.

resources

The relative names of all the contents of this resource. Raises an exception if accessed on a resource which is not a container.

path

This attribute is set by the resource’s finder. It is a textual representation of the path, such that if a PEP 302 loader’s get_data() method is called with the path, the resource’s bytes are returned by the loader. This attribute is analogous to the resource_filename API in setuptools. Note that for resources in zip files, the path will be a pointer to the resource in the zip file, and not directly usable as a filename. While setuptools deals with this by extracting zip entries to cache and returning filenames from the cache, this does not seem an appropriate thing to do in this package, as a resource is already made available to callers either as a stream or a string of bytes.

file_path[source]

This attribute is the same as the path for file-based resource. For resources in a .zip file, the relevant resource is extracted to a file in a cache in the file system, and the name of the cached file is returned. This is for use with APIs that need file names or to be able to access data through OS-level file handles.

Methods:

as_stream()[source]

A binary stream of the resource’s data. This must be closed by the caller when it’s finished with.

Raises an exception if called on a container resource.

class ResourceFinder[source]

A base class for resource finders, which finds resources for packages stored in the file system.

__init__(module)[source]

Initialise the finder for the package specified by module.

Parameters:module – The Python module object representing a package.
find(resource_name)[source]

Find a resource with the name specified by resource_name and return a Resource instance which represents it.

Parameters:resource_name – A fully qualified resource name, with hierarchical components separated by ‘/’.
Returns:A Resource instance, or None if a resource with that name wasn’t found.
is_container(resource)[source]

Return whether a resource is a container of other resources.

Parameters:resource (a Resource instance) – The resource whose status as container is wanted.
Returns:True or False.
get_stream(resource)[source]

Return a binary stream for the specified resource.

Parameters:resource (a Resource instance) – The resource for which a stream is wanted.
Returns:A binary stream for the resource.
get_bytes(resource)[source]

Return the contents of the specified resource as a byte string.

Parameters:resource (a Resource instance) – The resource for which the bytes are wanted.
Returns:The data in the resource as a byte string.
get_size(resource)[source]

Return the size of the specified resource in bytes.

Parameters:resource (a Resource instance) – The resource for which the size is wanted.
Returns:The size of the resource in bytes.
class ZipResourceFinder[source]

This has the same interface as ResourceFinder.

class Cache[source]

This class implements a cache for resources which must be accessible as files in the file system.

__init__(base=None)[source]

Initialise a cache instance with a specific directory which holds the cache. If base is specified but does not exist, it is created. If base is not specified, it defaults to os.expanduser('~/.distlib/resource-cache') on POSIX platforms (``os.name == 'posix'). On Windows, if the environment contains LOCALAPPDATA, the cache will be placed in

os.path.expandvars(r'$localappdata\.distlib\resource-cache')

Otherwise, the location will be

os.path.expanduser(r'~\.distlib\resource-cache')
get(resource)[source]

Ensures that the resource is available as a file in the file system, and returns the name of that file. This method calls the resource’s finder’s get_cache_info() method.

is_stale(resource, path)[source]

Returns whether the data in the resource which is cached in the file system is stale compared to the resource’s current data. The default implementation returns True, causing the resource’s data to be re-written to the file every time.

prefix_to_dir(prefix)[source]

Converts a prefix for a resource (e.g. the name of its containing .zip) into a directory name in the cache. This implementation delegates the work to path_to_cache_dir().

The distlib.scripts package

Classes

class ScriptMaker[source]

A class used to install scripts based on specifications.

source_dir

The directory where script sources are to be found.

target_dir

The directory where scripts are to be created.

add_launchers

Whether to create native executable launchers on Windows.

force

Whether to overwrite scripts even when timestamps show they’re up to date.

set_mode

Whether, on Posix, the scripts should have their execute mode set.

script_template

The text of a template which should contain %(shebang)s, %(module)s and %(func)s in the appropriate places.

The attribute is defined at class level. You can override it at the instance level to customise your scripts.

__init__(source_directory, target_directory, add_launchers=True, dry_run=False)[source]

Initialise the instance with options that control its behaviour.

Parameters:
  • source_directory (str) – Where to find scripts to install.
  • target_directory (str) – Where to install scripts to.
  • add_launchers (bool) –

    If true, create executable launchers on Windows. The executables are currently generated from the following project:

    https://bitbucket.org/vinay.sajip/simple_launcher/

  • dry_run – If true, don’t actually install scripts - just pretend to.
make(specification, options=None)[source]

Make a script in the target directory.

Parameters:
  • specification (str) –

    A specification, which can take one of the following forms:

    • A filename, relative to source_directory, such as foo.py or subdir/bar.py.
    • A reference to a callable, given in the form:
      name = some_package.some_module:some_callable [flags]

      where the flags part is optional.

      When this form is passed, a Python stub script is created with the appropriate shebang line and with code to load and call the specified callable with no arguments, returning its value as the return code from the script.

      For more information about flags, see Flag formats.

  • options – If specified, a dictionary of options used to control script creation. Currently, only the key gui is checked: this should be a bool which, if True, indicates that the script is a windowed application. This distinction is only drawn on Windows if add_launchers is True, and results in a windowed native launcher application if options['gui'] is True (otherwise, the native executable launcher is a console application).
Returns:

A list of absolute pathnames of files installed (or which would have been installed, but for dry_run being true).

make_multiple(specifications, options)[source]

Make multiple scripts from an iterable.

This method just calls make() once for each value returned by the iterable, but it might be convenient to override this method in some scenarios to do post-processing of the installed files (for example, running 2to3 on them).

Parameters:
  • specifications – an iterable giving the specifications to follow.
  • options – As for the make() method.
Returns:

A list of absolute pathnames of files installed (or which would have been installed, but for dry_run being true).

The distlib.locators package

Classes

class Locator[source]

The base class for locators. Implements logic common to multiple locators.

__init__(scheme='default')[source]

Initialise an instance of the locator. :param scheme: The version scheme to use. :type scheme: str

get_project(name)[source]

This method should be implemented in subclasses. It returns a (potentially empty) dictionary whose keys are the versions located for the project named by name, and whose values are instances of distlib.util.Distribution.

convert_url_to_download_info(url, project_name)[source]

Extract information from a URL about the name and version of a distribution.

Parameters:
  • url (str) – The URL potentially of an archive (though it needn’t be).
  • project_name (str) – This must match the project name determined from the archive (case-insensitive matching is used).
Returns:

None if the URL does not appear to be that of a distribution archive for the named project. Otherwise, a dictionary is returned with the following keys at a minimum:

  • url – the URL passed in, minus any fragment portion.
  • filename – a suitable filename to use for the archive locally.

Optional keys returned are:

  • md5_digest – the MD5 hash of the archive, for verification after downloading. This is extracted from the fragment portion, if any, of the passed-in URL.
  • sha256_digest – the SHA256 hash of the archive, for verification after downloading. This is extracted from the fragment portion, if any, of the passed-in URL.

Return type:

dict

get_distribution_names()[source]

Get the names of all distributions known to this locator.

The base class raises NotImplementedError; this method should be implemented in a subclass.

Returns:All distributions known to this locator.
Return type:set
locate(requirement, prereleases=False)[source]

This tries to locate the latest version of a potentially downloadable distribution which matches a requirement (name and version constraints). If a potentially downloadable distribution (i.e. one with a download URL) is not found, None is returned – otherwise, an instance of Distribution is returned. The returned instance will have, at a minimum, name, version and source_url populated.

Parameters:
  • requirement (str) – The name and optional version constraints of the distribution to locate, e.g. 'Flask' or 'Flask (>= 0.7, < 0.9)'.
  • prereleases (bool) – If True, prereleases are treated like normal releases. The default behaviour is to not return any prereleases unless they are the only ones which match the requirement.
Returns:

A matching instance of Distribution, or None.

class DirectoryLocator(Locator)[source]

This locator scans the file system under a base directory, looking for distribution archives. The locator scans all subdirectories recursively, unless the recursive flag is set to False.

__init__(base_dir, **kwargs)[source]
Parameters:
  • base_dir (str) – The base directory to scan for distribution archives.
  • kwargs

    Passed to base class constructor, apart from the following keyword arguments:

    • recursive (defaults to True) – if False, no recursion into subdirectories occurs.
class PyPIRPCLocator(Locator)[source]

This locator uses the PyPI XML-RPC interface to locate distribution archives and other data about downloads.

__init__(url, **kwargs)[source]
param url:The base URL to use for the XML-RPC service.
type url:str
param kwargs:Passed to base class constructor.
get_project(name)

See Locator.get_project().

class PyPIJSONLocator(Locator)[source]

This locator uses the PyPI JSON interface to locate distribution archives and other data about downloads. It gets the metadata and URL information in a single call, so it should perform better than the XML-RPC locator.

__init__(url, **kwargs)[source]
param url:The base URL to use for the JSON service.
type url:str
param kwargs:Passed to base class constructor.
get_project(name)

See Locator.get_project().

class SimpleScrapingLocator[source]

This locator uses the PyPI ‘simple’ interface – a Web scraping interface – to locate distribution archives.

__init__(url, timeout=None, num_workers=10, **kwargs)[source]
Parameters:
  • url (str) – The base URL to use for the simple service HTML pages.
  • timeout (float) – How long (in seconds) to wait before giving up on a remote resource.
  • num_workers (int) – The number of worker threads created to perform scraping activities.
  • kwargs – Passed to base class constructor.
class DistPathLocator[source]

This locator uses a DistributionPath instance to locate installed distributions.

__init__(url, distpath, **kwargs)[source]
Parameters:
  • distpath (DistributionPath) – The distribution path to use.
  • kwargs – Passed to base class constructor.
class AggregatingLocator(Locator)[source]

This locator uses a list of other aggregators and delegates finding projects to them. It can either return the first result found (i.e. from the first aggregator in the list provided which returns a non-empty result), or a merged result from all the aggregators in the list.

__init__(*locators, **kwargs)[source]
Parameters:
  • locators (sequence of locators) – A list of aggregators to delegate finding projects to.
  • merge (bool) – If this kwarg is True, each aggregator in the list is asked to provide results, which are aggregated into a results dictionary. If False, the first non-empty return value from the list of aggregators is returned. The locators are consulted in the order in which they’re passed in.
class DependencyFinder[source]

This class allows you to recursively find all the distributions which a particular distribution depends on.

__init__(locator)[source]

Initialise an instance with the locator to be used for locating distributions.

find(requirement, metas_extras=None, prereleases=False)[source]

Find all the distributions needed to fulfill requirement.

Parameters:
  • requirement – A string of the from name (version) where version can include an inequality constraint, or an instance of Distribution (e.g. representing a distribution on the local hard disk).
  • meta_extras – A list of meta extras such as :test:, :build: and so on, to be included in the dependencies.
  • prereleases – If True, allow pre-release versions to be returned - otherwise, don’t return prereleases unless they’re all that’s available.
Returns:

A 2-tuple. The first element is a set of Distribution instances. The second element is a set of problems encountered during dependency resolution. Currently, if this set is non- empty, it will contain 2-tuples whose first element is the string ‘unsatisfied’ and whose second element is a requirement which couldn’t be satisfied.

In the set of Distribution instances returned, some attributes will be set:

  • The instance representing the passed-in requirement will have the requested attribute set to True.
  • All requirements which are not installation requirements (in other words, are needed only for build and test) will have the build_time_dependency attribute set to True.

Functions

get_all_distribution_names(url=None)[source]

Retrieve the names of all distributions registered on an index.

Parameters:url (str) – The XML-RPC service URL of the node to query. If not specified, The main PyPI index is queried.
Returns:A list of the names of distributions registered on the index. Note that some of the names may be Unicode.
Return type:list
locate(requirement, prereleases=False)

This convenience function returns the latest version of a potentially downloadable distribution which matches a requirement (name and version constraints). If a potentially downloadable distribution (i.e. one with a download URL) is not found, None is returned – otherwise, an instance of Distribution is returned. The returned instance will have, at a minimum, name, version and download_url.

Parameters:
  • requirement (str) – The name and optional version constraints of the distribution to locate, e.g. 'Flask' or 'Flask (>= 0.7, < 0.9)'.
  • prereleases (bool) – If True, prereleases are treated like normal releases. The default behaviour is to not return any prereleases unless they are the only ones which match the requirement.
Returns:

A matching instance of Distribution, or None.

Variables

default_locator

This attribute holds a locator which is used by locate() to locate distributions.

The distlib.index package

Classes

class PackageIndex[source]

This class represents a package index which is compatible with PyPI, the Python Package Index. It allows you to register projects, upload source and binary distributions (with support for digital signatures), upload documentation, verify signatures and get a list of hosts which are mirrors for the index.

Methods:

__init__(url=None, mirror_host=None)[source]

Initialise an instance, setting instance attributes named from the keyword arguments.

Parameters:
  • url – The root URL for the index. If not specified, the URL for PyPI is used (‘http://pypi.python.org/pypi‘).
  • mirror_host – The DNS name for a host which can be used to determine available mirror hosts for the index. If not specified, the value ‘last.pypi.python.org’ is used.
register(metadata)[source]

Register a project with the index.

Parameters:metadata – A Metadata instance. This should have at least the Name and Version fields set, and ideally as much metadata as possible about this distribution. Though it might seem odd to have to specify a version when you are initially registering a project, this is required by PyPI. You can see this in PyPI’s Web UI when you click the “Package submission” link in the left-hand side menu.
Returns:An urllib HTTP response returned by the index. If an error occurs, an HTTPError exception will be raised.
upload_file(metadata, filename, signer=None, sign_password=None, filetype='sdist', pyversion='source')[source]

Upload a distribution to the index.

Parameters:
  • metadata – A Metadata instance. This should have at least the Name and Version fields set, and ideally as much metadata as possible about this distribution.
  • file_name – The path to the file which is to be uploaded.
  • signer – If specified, this needs to be a string identifying the GnuPG private key which is to be used for signing the distribution.
  • sign_password – The passphrase which allows access to the private key used for the signature.
  • filetype – The type of the file being uploaded. This would have values such as sdist (for a source distribution), bdist_wininst for a Windows installer, and so on. Consult the distutils documentation for the full set of possible values.
  • pyversion – The Python version this distribution is compatible with. If it’s a pure-Python distribution, the value to use would be source - for distributions which are for specific Python versions, you would use the Python version in the form X.Y.
Returns:

An urllib HTTP response returned by the index. If an error occurs, an HTTPError exception will be raised.

upload_documentation(metadata, doc_dir)[source]

Upload HTML documentation to the index. The contents of the specified directory tree will be packed into a .zip file which is then uploaded to the index.

Parameters:
  • metadata – A Metadata instance. This should have at least the Name and Version fields set.
  • doc_dir – The path to the root directory for the HTML documentation. This directory should be the one that contains index.html.
Returns:

An urllib HTTP response returned by the index. If an error occurs, an HTTPError exception will be raised.

verify_signature(self, signature_filename, data_filename)[source]

Verify a digital signature against a downloaded distribution.

Parameters:
  • signature_filename – The path to the file which contains the digital signature.
  • data_filename – The path to the file which was supposedly signed to obtain the signature in signature_filename.
Returns:

True if the signature can be verified, else False. If an error occurs (e.g. unable to locate the public key used to verify the signature), a ValueError is raised.

Additional attributes:

username

The username to use when authenticating with the index.

password

The password to use when authenticating with the index.

gpg

The path to the signing and verification program.

gpg_home

The location of the key database for the signing and verification program.

mirrors[source]

The list of hosts which are mirrors for this index.

boundary

The boundary value to use when MIME-encoding requests to be sent to the index. This should be a byte-string.

The distlib.util package

Classes

class ExportEntry[source]

Attributes:

A class holding information about a exports entry.

name

The name of the entry.

prefix

The prefix part of the entry. For a callable or data item in a module, this is the name of the package or module containing the item.

suffix

The suffix part of the entry. For a callable or data item in a module, this is a dotted path which points to the item in the module.

flags

A list of flags. See Flag formats for more information.

value[source]

The actual value of the entry (a callable or data item in a module, or perhaps just a module). This is a cached property of the instance, and is determined by calling resolve() with the prefix and suffix properties.

dist

The distribution which exports this entry. This is normally an instance of InstalledDistribution.

Functions

get_cache_base()[source]

Return the base directory which will hold distlib caches. If the directory does not exist, it is created.

On Windows, if LOCALAPPDATA is defined in the environment, then it is assumed to be a directory, and will be the parent directory of the result. On POSIX, and on Windows if LOCALAPPDATA is not defined, the user’s home directory – as determined using os.expanduser('~') – will be the parent directory of the result.

The result is just the directory '.distlib' in the parent directory as determined above.

path_to_cache_dir(path)[source]

Converts a path (e.g. the name of an archive) into a directory name suitable for use in a cache. The following algorithm is used:

  1. On Windows, any ':' in the drive is replaced with '---'.
  2. Any occurrence of os.sep is replaced with '--'.
  3. '.cache' is appended.
get_export_entry(specification)[source]

Return a export entry from a specification, if it matches the expected format, or else None.

Parameters:specification (str) – A specification, as documented for the distlib.scripts.ScriptMaker.make() method.
Returns:None if the specification didn’t match the expected form for an entry, or else an instance of ExportEntry holding information about the entry.
resolve(module_name, dotted_path)[source]

Given a module name and a dotted_path representing an object in that module, resolve the passed parameters to an object and return that object.

If the module has not already been imported, this function attempts to import it, then access the object represented by dotted_path in the module’s namespace. If dotted_path is None, the module is returned. If import or attribute access fails, an ImportError or AttributeError will be raised.

Parameters:
  • module_name (str) – The name of a Python module or package, e.g. os or os.path.
  • dotted_path (str) – The path of an object expected to be in the module’s namespace, e.g. 'environ', 'sep' or 'path.supports_unicode_filenames'.

The distlib.wheel package

This package has functionality which allows you to work with wheels (see PEP 427).

Classes

class Wheel

This class represents wheels – either existing wheels, or wheels to be built.

__init__(spec)

Initialise an instance from a specification.

Parameters:spec (str) – This can either be a valid filename for a wheel (for when you want to work with an existing wheel), or just the name-version-buildver portion of a wheel’s filename (for when you’re going to build a wheel for a known version and build of a named project).
build(paths, tags=None, wheel_version=None)

Build a wheel. The name, version and buildver should already have been set correctly.

Parameters:
  • paths – This should be a dictionary with keys 'prefix', 'scripts', 'headers', 'data' and one of 'purelib' or 'platlib'. These must point to valid paths if they are to be included in the wheel.
  • tags – If specified, this should be a dictionary with optional keys 'pyver', 'abi' and 'arch' indicating lists of tags which indicate environments with which the wheel is compatible.
  • wheel_version – If specified, this is written to the wheel’s “Wheel-Version” metadata. If not specified, the implementation’s latest supported wheel version is used.
install(self, paths, maker, **kwargs)

Install from a wheel.

Parameters:
  • paths – This should be a dictionary with keys 'prefix', 'scripts', 'headers', 'data', 'purelib' and 'platlib'. These must point to valid paths to which files may be written if they are in the wheel. Only one of the 'purelib' and 'platlib' paths will be used (in the case where they are different), depending on whether the wheel is for a pure-Python distribution.
  • maker – This should be set to a suitably configured instance of ScriptMaker. The source_dir and target_dir arguments can be set to None when creating the instance - these will be set to appropriate values inside this method.
  • warner – If specified, should be a callable that will be called with (software_wheel_ver, file_wheel_ver) if they differ. They will both be in the form of tuples (major_ver, minor_ver).
  • lib_only – It’s conceivable that one might want to install only the library portion of a package – not installing scripts, headers, data and so on. If lib_only is specified as True, only the site-packages contents will be installed.
mount(append=False)

Mount the wheel so that its contents can be imported directly, without the need to install the wheel. If the wheel contains C extensions and has metadata about these extensions, the extensions are also available for import.

If the wheels tags indicate it is not compatible with the running Python, a DistlibException is raised.

param append:If True, the wheel’s pathname is added to the end of sys.path. By default, it is added to the beginning.
unmount()

Unmount the wheel so that its contents can no longer be imported directly. If the wheel contains C extensions and has metadata about these extensions, the extensions are also made unavailable for import.

name

The name of the distribution.

version

The version of the distribution

buildver

The build tag for the distribution.

pyver

A list of Python versions with which the wheel is compatible. See PEP 427 and PEP 425 for details.

abi

A list of application binary interfaces (ABIs) with which the wheel is compatible. See PEP 427 and PEP 425 for details.

arch

A list of architectures with which the wheel is compatible. See PEP 427 and PEP 425 for details.

dirname

The directory in which a wheel file is found/to be created.

filename

The filename of the wheel (computed from the other attributes)

metadata

The metadata for the distribution in the wheel, as a Metadata instance.

info

The wheel metadata (contents of the WHEEL metadata file) as a dictionary.

Functions

is_compatible(wheel, tags=None)

Indicate if a wheel is compatible with a set of tags. If any combination of the tags of wheel is found in tags, then the wheel is considered to be compatible.

Parameters:
  • wheel – A Wheel instance or the filename of a wheel.
  • tags – A set of tags to check for compatibility. If not specified, it defaults to the set of tags which are compatible with this Python implementation.
Returns:

True if compatible, else False.

Attributes

COMPATIBLE_TAGS

A list of (pyver, abi, arch) tags which are compatible with this Python implementation.

Next steps

You might find it helpful to look at the mailing list.

Comments powered by Disqus
Read the Docs v: 0.1.5
Versions
latest
0.1.5
0.1.4
0.1.3
0.1.2
0.1.1
0.1.0
Downloads
PDF
HTML
Epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.