Skip to content

OpenAstronomy/minimum_dependencies

Repository files navigation

minimum_dependencies

https://codecov.io/gh/OpenAstronomy/minimum_dependencies/branch/main/graph/badge.svg?token=0nyyslY22s pre-commit https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336

Generate the minimum dependencies for a Python project based on the lower pins.

Installation

This package is available on PyPI. You can install it with pip:

$ pip install minimum-dependencies

Usage

minumum_dependencies can be used as a command line tool or as a library.

CLI

The manpage for the CLI tool is below:

$ minimum_dependencies --help
usage: minimum_deps [-h] [--filename FILENAME] [--extras [EXTRAS ...]] package

Generate the minimum requirements for a package based on the lower pins of its dependencies.

positional arguments:
package               Name of the package to generate requirements for

options:
-h, --help            show this help message and exit
--filename FILENAME, -f FILENAME
                        Name of the file to write out
--extras [EXTRAS ...], -e [EXTRAS ...]
                        List of optional dependency sets to include
--fail                Raise an error if pin is not present or not on PyPi.

For example, to generate the minimum dependencies for minimum_dependencies:

$ minimum_dependencies minimum_dependencies
importlib-metadata==4.11.4
packaging==23.0
requests==2.25.0

Similarly, to generate this with some of its optional dependencies (test and other):

$ minimum_dependencies minimum_dependencies --extras test other
importlib-metadata==4.11.4
packaging==23.0
requests==2.25.0
astropy[all]==5.0
pytest==6.0.0
pytest-doctestplus==0.12.0

Note

One can pass the --fail flag to raise an error if a pin is not present or not on PyPi. If this flag is not passed, a warning will be issued and the pin will be set at the lowest available on PyPi.

Library Usage

The library provides two public functions:
  • create: takes a package name and returns a list of requirement strings.
  • write: takes a package name and a filename and writes the requirements to the file.

For example, to generate the minimum dependencies for minimum_dependencies:

>>> import minimum_dependencies
>>> minimum_dependencies.create("minimum_dependencies")
['packaging==23.0\n', 'requests==2.25.0\n']
>>> minimum_dependencies.write(
...     "minimum_dependencies", "requirements.txt"
... )  # writes the requirements to requirements.txt

One can also pass these methods a list of extras (optional installs for the package) to include in the requirements. For example, to generate the minimum dependencies for minimum_dependencies with all its optional dependencies:

.. doctest-requires:: importlib_metadata
>>> import minimum_dependencies
>>> minimum_dependencies.create("minimum_dependencies", extras=["test", "testing_other"])
['importlib-metadata==4.11.4\n', 'packaging==23.0\n', 'requests==2.25.0\n',
'pytest==6.0.0\n', 'pytest-doctestplus==0.12.0\n', 'astropy[all]==5.0\n',
'numpy==1.20.0\n', 'scipy==1.6.0\n']
>>> minimum_dependencies.write(
...     "minimum_dependencies", "requirements.txt", extras=["test", "other"]
... )  # writes the requirements to requirements.txt

Note

One can pass the argument fail=True to raise an error if a pin is not present or not on PyPi. If if this is not passed, or False, a warning will be issued and the pin will be set at the lowest available version on PyPi.