8
votes

I have a package with a structure that would (simplified) look like:

mypackage/
    __init__.py
    setup.py
    module1.py
    module2.py
    mysubpackage/
        __init__.py
        mysubmodule1.py
        mysubmodule2.py

I'm using a configuration for setup.py like this:

from setuptools import setup, find_packages

setup(
    name = "mypackage",
    version = "0.1",
    author = "Foo",
    author_email = "[email protected]",
    description = ("My description"),
    packages=find_packages(),
)

The default where argument for find_packages() is '.', but it doesn't include my top-level modules (module1.py nor module2.py). However, all child submodules and subpackages are added when running python setup.py build.

How could I get top-level Python modules added too, without moving setup.py one level higher?

1
Why don't you want to move setup.py? It should be outside the package. - jonrsharpe
To be fair, setup.py should be moved up one level higher and all other scripts / packages / modules need to be installed by configuring setup.py correctly. That should be it. - Simeon Visser
The mypackage in fact is a django app, and I'd like to have setup.py inside the app to commit it with the app's source and to avoid having it inside a django project of mine. - Caumons
setup.py should always be at a higher directory level than your Python package. Your app's "source" should be the Python package itself, plus any support files like setup.py or a README that would exist outside the Python package. Have a look at packaging.python.org/en/latest/distributing.html - Iguananaut
I've posted an answer with the working solution used based on your comments. Thank you guys! :) - Caumons

1 Answers

5
votes

Thank you all for your responses.

Finally, I added a directory (not Python package) containing mypackage and the setup.py module. The structure now looks as follows:

myapp/
    setup.py
    mypackage/
        __init__.py
        module1.py
        module2.py
        mysubpackage/
            __init__.py
            mysubmodule1.py
            mysubmodule2.py

Now using find_packages() works as expected. Thanks!