Reputation: 40973
I started working on a project with the following folder structure where each top folder lives in a separate repository:
project-api/
source/
module1.py
module2.py
project-core/
source/
module3.py
module4.py
I would like to pip install -e
and be able to do:
from api.module1 import function1
from core.module3 import function3
without changing the folder structure (fixed by the project).
Question: How can I create the corresponding(s) setup.py
?
Upvotes: 1
Views: 590
Reputation: 94483
You cannot do that with pip install -e
because option -e
"installs" packages in development/editable mode. It doesn't actually install anything but creates a link that allows Python to import modules directly from the development directory. Unfortunately in your case that impossible — directories project-core
and project-api
contain forbidden character in their name (-
) — these directories cannot be made importable in-place.
But pip install .
could be made to install top-level packages api
and core
from these directories. First you have to add __init__.py
:
touch project-api/source/__init__.py
touch project-core/source/__init__.py
And the following setup.py
do the rest:
#!/usr/bin/env python
from setuptools import setup
setup(
name='example',
version='0.0.1',
description='Example',
packages=['api', 'core'],
package_dir={
'api': 'project-api/source',
'core': 'project-core/source',
}
)
Run pip install .
and you're done. Execute import api, core
in Python.
PS. If you can create symlinks at the root:
ln -s project-api/source api
ln -s project-core/source core
you can use pip install -e .
Upvotes: 1