Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I build multiple wheel files from a single setup.py?

In my project, I have a single setup.py file that builds multiple modules using the following namespace pattern:

from setuptools import setup

setup(name="testmoduleserver",
      packages=["testmodule.server","testmodule.shared"],
      namespace_packages=["testmodule"])

setup(name="testmoduleclient",
      packages=["testmodule.client","testmodule.shared"],
      namespace_packages=["testmodule"])

I am trying to build wheel files for both packages. However, when I do:

python -m pip wheel .

It only ever builds the package for one of the definitions.

Why does only one package get built?

like image 539
Greg Fuller Avatar asked Jul 12 '18 01:07

Greg Fuller


People also ask

What is Python setuptools used for?

Setuptools is a collection of enhancements to the Python distutils that allow developers to more easily build and distribute Python packages, especially ones that have dependencies on other packages. Packages built and distributed using setuptools look to the user like ordinary Python packages based on the distutils .

What is Package_dir in setup py?

package_dir = {'': 'lib'} in your setup script. The keys to this dictionary are package names, and an empty package name stands for the root package. The values are directory names relative to your distribution root.

Does Python come with setuptools?

Usually, Yes. the setuptools is not part of the python vanilla codebase, hence not a vanilla modules. python.org installers or mac homebrew will install it for you, but if someone compile the python by himself or install it on some linux distribution he may not get it and will need to install it by himself.


1 Answers

You cannot call setuptools.setup() more than once in your setup.py, even if you want to create several packages out of one codebase.

Instead you need to separate everything out into separate namespace packages, and have one setup.py for each (they all can reside in one Git repository!):

testmodule/
    testmodule-client/
        setup.py
        testmodule/
            client/
                __init__.py
    testmodule-server/
        setup.py
        testmodule/
            server/
                __init__.py
    testmodule-shared/
        setup.py
        testmodule/
            shared/
                __init__.py

And each setup.py contains something along the lines

from setuptools import setup

setup(
    name='testmodule-client',
    packages=['testmodule.client'],
    install_requires=['testmodule-shared'],
    ...
)

and

from setuptools import setup

setup(
    name='testmodule-server',
    packages=['testmodule.server'],
    install_requires=['testmodule-shared'],
    ...
)

and

from setuptools import setup

setup(
    name='testmodule-shared',
    packages=['testmodule.shared'],
    ...
)

To build all three wheels you then run

pip wheel testmodule-client
pip wheel testmodule-server
pip wheel testmodule-shared
like image 76
Nils Werner Avatar answered Oct 26 '22 23:10

Nils Werner