How can I make setup.py to include a class into packaging

457 Views Asked by At

I'm using setup.py to package my project. the structure is like:

foo -
    |
    |--foo/
    |    |
    |    |--first.py
    |    |--second.py
    |    |--...
    |--README
    |--requirements.txt
    |--scripts/
    |        |
    |        |-script1.sh
    |        |-script2.py
    |--service.py
    |--setup.py

If I run the current setup.py, which is in accordance with the suggestions here: What is setup.py? then in the venv/lib/python3.6/site-packages/foo and venv/lib/python3.6/site-packages/scripts I can see all python classes there. But service.py is absent. My question is how to modify the setup.py to include service.py into packaging such that I can find service.py at venv/lib/python3.6/site-packages/? Thanks in advance!

1

There are 1 best solutions below

2
On

For top level modules, such as service.py, to be included in the distributions, setuptools offers the py_modules parameter.

The setuptools documentation does not show it clearly, but it is the same as in (now deprecated) distutils:

setuptools.setup(
    # ...
    py_modules=['service'],  # no '.py'
)