Search code examples
pythonpipsetuptoolspip-tools

How to create `dev_requirements.txt` from `extras_require` section of `setup.cfg` file using `pip-compile` from `pip-tools`?


I use pip-tools to manage my dependencies and environments which perfectly generates a requirements.txt file for my package that consists of a setup.py that looks like this:

#! /usr/bin/env python
import os
from setuptools import setup


if "CI_COMMIT_TAG" in os.environ:
    VERSION = os.environ["CI_COMMIT_TAG"]
else:
    VERSION = "0.0.0"

setup(version=VERSION)

and a setup.cfg like this:

...
[options]
python_requires = >=3.7
zip_safe = False
packages = find:
include_package_data = True
install_requires =
    PyYAML
    Cython
    numpy==1.17.5
    pandas==0.25.3
    ...
package_dir=
    foo=bar

[options.extras_require]
testing =
    tox>=3.1.2
    pytest>=3.4.0
coverage =
    coverage
    pytest-cov>=2.5.1
other =
    anybadge
...

Running $ pip-compile --index-url https://foo@bar@gitlab.my.host/api/v4/projects/236/packages/pypi/simple --no-header --allow-unsafe yields my package requirements:

...
async-timeout==3.0.1
    # via aiohttp
attrs==21.2.0
    # via aiohttp
bcrypt==3.2.0
...

But this only includes all the packages from the install_requires section of my setup.cfg file and not the requirements from extras_require. It should work with a dev_requirements.in file as described here but I would rather only use one configuration file.

How can I create a separate dev_requirements.txt from this extras_require section of my setup.cfg file using pip-compile without having to create a dev_requirements.in file?

Thanks in advance!


Solution

  • After digging for a while, I found my answer in another issue:

    $ pip-compile --extra testing --extra other