Building a Wheel File with extra_requires using Tox

100 Views Asked by At

I have a Python multi-module project with a setup.py file that defines extra dependencies using extra_requires. I want to use Tox to build a wheel file that includes these extra dependencies. However, I'm not sure how to achieve this with Tox.

Here's my project structure:

my_project/
    ├── setup.py
    ├── core/
    │   ├── __init__.py
    │   └── core_code.py
    ├── api/
    │   ├── __init__.py
    │   └── api_code.py
    ├── tests/
    │   ├── __init__.py
    │   ├── test_core_code.py
    │   ├── test_api_code.py
    │   └── tox.ini

It can be installed via pip install . or pip install .[api]

Here's an example setup.py:

from setuptools import setup, find_packages

setup(
    name='my_project',
    version='0.1.0',
    packages=find_packages(),
    install_requires=[
        # core dependencies
        'requests',
    ],
    extras_require={
        'api': [
            # additional dependencies for the API
            'flask',
            'fastapi',
        ],
    },
)

Using tox, I'd like to build the wheel file for the core module only, which is working fine.

tox]
envlist = py39

[testenv]
description = 'Builds a core wheel file (from setup.py) and runs unit tests.'
package = wheel
deps = pytest
commands =
    pytest tests

However, I'd also like to create a wheel file for the full module. That is the core + extras. Is there some builtin way to tell tox to build the wheel file and include the extra_args so that the [api] profile is built?

[testenv:api-full]
description = 'Builds a wheel file with extra_requires and runs tests.'
package = wheel [api]   #<--- pseudocode
deps = pytest
commands =
0

There are 0 best solutions below