4. pkg_utils package

4.1. Submodules

4.2. pkg_utils._version module

4.3. 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.py

Type

str

install_requires[source]

dependencies, e.g. from requirements.txt

Type

list of str

extras_require[source]

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

Type

dict of list of str

tests_require[source]

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

Type

list of str

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

Type

list of str

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_uri=False, 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_uri (bool, optional) – if True, include URI in the dependencies list

  • 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: extra/optional requirements list of str: test 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.py)

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)[source]

Install dependencies

Parameters
  • dependencies (list) – list of dependencies

  • upgrade (bool, optional) – if True, upgrade package

pkg_utils.core.parse_optional_requirements_file(filename, include_uri=False, 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_uri (bool, optional) – if True, include URI in the dependencies list

  • 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_line(line, include_uri=False, 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
  • line (str) – line from a requirements.txt file

  • include_uri (bool, optional) – if True, include URI in the dependencies list

  • 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

requirement str: dependency link

Return type

str

pkg_utils.core.parse_requirement_lines(lines, include_uri=False, 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_uri (bool, optional) – if True, include URI in the dependencies list

  • 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.parse_requirements_file(filename, include_uri=False, 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_uri (bool, optional) – if True, include URI in the dependencies list

  • 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.4. Module contents