pythondistutils

Python distutils setup relative paths for package_dir


I've looked here:
How can I get my setup.py to use a relative path to my files?
and here:
python distutils does not include data_files

and here:
Confused about the package_dir and packages settings in setup.py but found no love.

I suspect that distutils doesn't support the directory structure I'm trying to use but would love confirmation and/or suggestion for how to improve.

I have the following directory structure:

/src  
├── user 
├── admin  
│   ├── admin.py  
│   ├── LICENSE.txt  
│   ├── MANIFEST  
│   ├── MANIFEST.in  
│   ├── README.txt  
│   └── setup.py  
└── lib  
    ├── __init__.py  
    ├── __init__.pyc  
    ├── rcodes.py  
    ├── rcodes.pyc  
    ├── validation.py  
    └── validation.pyc  

Where several projects in src depend on the lib package. However, when trying to run the setup.py in /src/admin I can not include the lib dir in the final package (using setup.py sdist).

Setup.py is as follows: from distutils.core import setup

setup(
name='admin_server',
version='0.0.0',
author='Instamrkt',
author_email='info@instamrkt.com',
url='http://instamrkt.com',
description='Instamrkt Admin Server',
packages=['lib'],
package_dir = {'lib': '../lib'},
py_modules = [
'admin',
'lib.rcodes',
'lib.validation'
],)

Which yields:

[foozle@ip-172-31-36-251 admin]$ python setup.py sdist
running sdist
running check
reading manifest template 'MANIFEST.in'
writing manifest file 'MANIFEST'
creating admin_server-0.0.0
making hard links in admin_server-0.0.0...
hard linking README.txt -> admin_server-0.0.0
hard linking admin.py -> admin_server-0.0.0
hard linking setup.py -> admin_server-0.0.0
Creating tar archive
removing 'admin_server-0.0.0' (and everything under it)
[foozle@ip-172-31-36-251 admin]$ tar tzf ./dist/admin_server-0.0.0.tar.gz
admin_server-0.0.0/
admin_server-0.0.0/PKG-INFO
admin_server-0.0.0/admin.py
admin_server-0.0.0/setup.py
admin_server-0.0.0/README.txt

The package lib is missing.

And just to be explicit I would like the same directory structure preserved in the package so that I can use lib in multiple distributions for different apps.

Thanks!


Solution

  • You cannot create a source distribution when using the package_dir option to point to an upstream directory ('../lib'), because sdist will copy the whole source tree as is, and '../lib' ends up outside of the build tree.

    You can however create a binary distribution:

    python setup.py bdist
    

    or, if using setuptools:

    python setup.py bdist_wheel
    

    The later has the advantage of creating a system-agnostic distribution if your module is pure Python.