working on a python project, I tried to separate source code and unit tests; here is the project structure:
MyProject/
MANIFEST.in
README.md
setup.py
source/
__init.py__
my_project/
__init.py__
some_module.py
test/
__init.py__
my_project/
__init.py__
test_some_module.py
And here is the setup.py file:
from setuptools import setup, find_packages
setup(
name='my_project',
packages=find_packages(where='./source'),
description='My project to be packaged',
version='1.0.0',
author='me'
install_requires=[
'fastnumbers~=2.0.1',
'numpy~=1.14.1',
'pandas~=0.22.0'
],
extras_require={
'dev': ['check-manifest'],
'test': [
'mock',
'PyHamcrest',
'pytest',
'pytest-cov'
],
}
)
Then, when I run command python3 setup.py sdist, it fails with the following output:
running sdist
running egg_info
writing my_project.egg-info/PKG-INFO
writing requirements to my_project.egg-info/requires.txt
writing dependency_links to my_project.egg-info/dependency_links.txt
writing top-level names to my_project.egg-info/top_level.txt
error: package directory 'my_project' does not exist
The resulting top_level.txt file looks fine:
my_project
but it looks like the setuptools is not starting from source folder to find modules to be packaged.
setup.py and MANIFEST.in files into source folder?where argument for in setuptools.find_packages function?Function defined in setuptools find_packages(where='.', exclude=()) Return a list all Python packages found within directory 'where' 'where' should be supplied as a “cross-platform” (i.e. URL-style) path; it will be converted to the appropriate local path syntax.
Setuptools is a package development process library designed to facilitate packaging Python projects by enhancing the Python standard library distutils (distribution utilities). It includes: Python package and module definitions. Distribution package metadata.
setup. cfg is a file which might be used to specify such options in addition to reading the command line when calling python setup.py <somecommand> . The documentation for setup.
To install a package that includes a setup.py file, open a command or terminal window and: cd into the root directory where setup.py is located. Enter: python setup.py install.
You are one step away from a working solution. Add
package_dir={
'': 'source',
},
to the setup() arguments:
setup(
...,
packages=find_packages(where='source'),
package_dir={
'': 'source',
},
...
)
More info on packages remapping can be found in Listing whole packages section.
However, it looks like you made the source dir to a python package by placing an __init__.py in it. Was that intentional? Do you have import statements like
import source.my_project
from source.my_project.my_module import stuff
or similar, using source as package name? Then beware that the imports will fail once you install your built package because source is omitted when including sources on build. I see two ways:
source/__init__.py, use package_dir like described above to make my_project to the top level package, omit source in imports (should you get any errors, just remove myproject-1.0.0.egg_info dir and recreate it with python setup.py egg_info), orsource as top level package: don't use package_dir, look for packages in the project root dir (packages=find_packages() without explicitly stating where).If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With