A requirements file parser that provides a method for setuptools to use requirements specified in external requirements files.
A base requirements file is supported, and additional suffixed files can be used to specify requirements for tests and extras. Dependency links are automatically combined from all requirements files found.
Basic example usage for requirements*.txt in the same directory:
from requirements import RequirementsParser
requirements = RequirementsParser()
- setup(
- ... install_requires=requirements.install_requires, setup_requires=requirements.setup_requires, tests_require=requirements.tests_require, extras_require=requirements.extras_require, dependency_links=requirements.dependency_links, ...
)
The RequirementsParser class can be instantiated with a custom path, filename prefix and file extension if required:
requirements = RequirementsParser(path=’/’, name=’depends’, extn=’conf’)
A globbing approach is used to locate additional requirements files which contain packages for use when testing or to specify optional extra packages.
For example, a file with the name requirements-cython.txt would be added to the extra packages dictionary with the name cython.
In addition, requirements-tests.txt will also be added as the packages required for testing as well as being added as an extra with the name tests.
If a file named dependency_links.txt is found in the same path as the requirements files, dependencies listed in the file will also be added to the dependency links generated by the requirements parser.
Support has also been added for operating system specific packages such packages listed in requirements+linux.txt will only be installed on Linux. The names that can be used are anything that matches strings generated by __import__('platform').system().lower().
See more information about requirements files and integration with setup.py:
Bases: object
Parser for requirements files providing helpful properties for populating the setuptools setup() function with requirements based on requirements files.
Extracts dependency links from parsed requirements files.
Returns: | The dependency links from the requirements files. |
---|---|
Return type: | list |
Extracts requirements for extras from parsed requirements files.
Returns: | The requirements for extras from the requirements files. |
---|---|
Return type: | dict |
Extracts requirements for installation from parsed requirements files.
Returns: | The requirements for installation from the requirements files. |
---|---|
Return type: | list |