Reputation: 599
I'm trying to setup some Python packages that will share a common set of "utilities" but need to be able to distribute them as separate "packages." Assume the following structure:
/packages
|-setup.py
|-__init__.py
|-MANIFEST.in
|-com
| |-__init__.py
| |-company
| | |-__init__.py
| | |-subdir1
| | | |-__init__.py
...
|-utilities
| |-__init__.py
| |-utils1.py
| |-utils2.py
| |-...
|-package1
| |-__init__.py
| |-package1_1.py
| |-package1_2.py
| |-...
|-package2
| |-__init__.py
| |-package2_1.py
| |-package2_2.py
| |-...
I would like to be able to use setup.py for building either package1 or package2 both of which should include the same utilities.
All of the tutorials I've found use a simple single project which makes using a single setup.py fairly straightforward. But how do I create multiple different packages from the same directory (it's a git repository) structure? At the moment I'm using package1_setup.py to build package1 that looks similar to:
from setuptools import setup,find_packages
import sys, os
version = '0.1'
setup(name = 'package1',
version = version,
description = 'Package 1',
author = 'Rob Marshall',
author_email = '[email protected]',
url = None,
packages = ["package1","utils","com"],
include_package_data = True,
zip_safe = False,
entry_points = {
'console_scripts':[
'tool1 = package1.package1_1:main',
'tool2 = package1.package1_2:main',
],
},
install_requires = [
'boto >= 2.40',
'python-swiftclient >= 3.2.0',
'fabric >= 1.13.0',
],
)
So when I want to build package1 I do:
% python package1_setup.py sdist
Which creates an installable source package but is somewhat "awkward" because the setup.py is called package1_setup.py. Not that that is tragic, but I was wondering if there's a better way to do this.
Thanks,
Rob
Upvotes: 32
Views: 23813
Reputation: 599
I may have answered my own question: If I modify the setup.py to use:
packages = find_packages(),
and change the directory structure to:
...
|-package1
| |-setup.py
| |-MANIFEST.in
| |-com (symlink to ../com)
| |-utilities (symlink to ../utilities)
| |-package1
| | |-__init__.py
| | |-package1_1.py
| | |-package1_2.py
| | |-...
If I then cd into package1 and do:
% python setup.py sdist
It seems to create the distribution correctly.
Rob
Upvotes: 10