4. pkg_utils package

4.1. Submodules

4.2. pkg_utils.core module

Utilities for linking setuptools with package version metadata, GitHub README.md files, requirements.txt files, and restoring overridden entry points during for editable installations.

Author:Jonathan Karr <jonrkarr@gmail.com>
Date:2017-12-03
Copyright:2017, Karr Lab
License:MIT
class pkg_utils.core.PackageMetadata[source]

Bases: object

Metadata about a package

name[source]
Type:str
description[source]

short description

Type:str
long_description[source]

long description, e.g. from README.rst

Type:str
version[source]

version, e.g. from package/VERSION

Type:str
install_requires[source]

dependencies, e.g. from requirements.txt

Type:list
extras_require[source]

optional dependencies, e.g. from requirements.optional.txt

Type:dict
tests_require[source]

test dependencies, e.g. from tests/requirements.txt

Type:list

documentation dependencies, e.g. from docs/requirements.txt

Type:list
pkg_utils.core.add_console_scripts(dirname, package_name, console_scripts)[source]

Add console scripts for a package

Parameters:
  • dirname (str) – path to the package
  • package_name (str) – package name
  • console_scripts (dict of dict) – console script names and functions
pkg_utils.core.convert_readme_md_to_rst(dirname)[source]

Convert the README.md to README.rst

Parameters:dirname (str) – path to the package
pkg_utils.core.expand_package_data_filename_patterns(dirname, package_data_filename_patterns=None)[source]

Expand the package data filenames

:param dict: package data

pkg_utils.core.get_console_scripts(dirname, package_name)[source]

Get the console scripts for a package

Parameters:
  • dirname (str) – path to the package
  • package_name (str) – package name
Returns:

console script names and functions

Return type:

dict of dict

pkg_utils.core.get_dependencies(dirname, include_extras=True, include_specs=True, include_markers=True)[source]

Parse required and optional dependencies from requirements.txt files

Parameters:
  • dirname (str) – path to the package
  • include_extras (bool, optional) – if True, include extras in the dependencies list
  • include_specs (bool, optional) – if True, include specifications in the dependencies list
  • include_markers (bool, optional) – if True, include markers in the dependencies list
Returns:

requirements list of str: dependency links

Return type:

list of str

pkg_utils.core.get_long_description(dirname)[source]

Get the long description of a package from its README.rst file

Parameters:dirname (str) – path to the package
Returns:long description
Return type:str
pkg_utils.core.get_package_metadata(dirname, package_name, package_data_filename_patterns=None)[source]

Get meta data about a package

Parameters:
  • dirname (str) – path to the package
  • package_name (str) – package name
  • package_data_filename_patterns (dict, optional) – package name, optionally with glob patterns in the filenames
Returns:

meta data

Return type:

PackageMetadata

Raises:

ValueError: if test or documentation dependencies are defined in requirements.optional.txt

pkg_utils.core.get_version(dirname, package_name)[source]

Get the version a package from its VERSION file (package/VERSION)

Parameters:
  • dirname (str) – path to the package
  • package_name (str) – package name
Returns:

version

Return type:

str

pkg_utils.core.install_dependencies(dependencies, upgrade=False, process_dependency_links=True)[source]

Install dependencies

Parameters:
  • dependencies (list) – list of dependencies
  • upgrade (bool, optional) – if True, upgrade package
  • process_dependency_links (bool, optional) – True, process dependency links
pkg_utils.core.parse_optional_requirements_file(filename, include_extras=True, include_specs=True, include_markers=True)[source]

Parse a requirements.optional.txt file into list of requirements and dependency links

Parameters:
  • filename (str) – path to requirements.txt file
  • include_extras (bool, optional) – if True, include extras in the dependencies list
  • include_specs (bool, optional) – if True, include specifications in the dependencies list
  • include_markers (bool, optional) – if True, include markers in the dependencies list
Returns:

requirements list of str: dependency links

Return type:

dict of list of str

Raises:

ValueError – if a line cannot be parsed

pkg_utils.core.parse_requirement_lines(lines, include_extras=True, include_specs=True, include_markers=True)[source]

Parse lines from a requirements.txt file into list of requirements and dependency links

Parameters:
  • lines (list of str) – lines from a requirements.txt file
  • include_extras (bool, optional) – if True, include extras in the dependencies list
  • include_specs (bool, optional) – if True, include specifications in the dependencies list
  • include_markers (bool, optional) – if True, include markers in the dependencies list
Returns:

requirements list of str of str: dependency links

Return type:

list of str

Raises:

ValueError – if a line cannot be parse

pkg_utils.core.parse_requirements_file(filename, include_extras=True, include_specs=True, include_markers=True)[source]

Parse a requirements.txt file into list of requirements and dependency links

Parameters:
  • filename (str) – path to requirements.txt file
  • include_extras (bool, optional) – if True, include extras in the dependencies list
  • include_specs (bool, optional) – if True, include specifications in the dependencies list
  • include_markers (bool, optional) – if True, include markers in the dependencies list
Returns:

requirements list of str: dependency links

Return type:

list of str

4.3. Module contents