Create editable package setup.py in the same root folder as __init__.py

☆樱花仙子☆ 提交于 2019-12-11 17:18:57

问题


An existing project is setup in a way that the repository has an __init__.py in at the root folder. I would like to create a setup.py in the repository so this would be the resulting project structure:

project-master/
├── __init__.py
├── setup.py
└── submodule1
    ├── code.py
    └── __init__.py
└── submodule2
    ├── code.py
    └── __init__.py

and you should be able to:

git clone project.url
cd project-master
pip install -e .
from project.submodule1 import ...

I tried the hacky solution of temporarily copying the contents in a subfolder so that setup.py is one level up from the package folder and installing from there. This works well if I pip install . but unfortunately this solution doesn't work in editable mode because I delete the temporary folder after installing.

Question: What is the right way to create a proper setup.py that works in editable mode and lives in the same root folder as the package's __init__.py?


回答1:


This doesn't seem to be possible for an editable installation. As far as I know the closest one can get is as following:

project-master/
├── __init__.py
├── setup.py
└── submodule1
    └── __init__.py
#!/usr/bin/env python3
import setuptools
setuptools.setup(
    name='ProjectMaster',
    version='0.0.0.dev0',
    packages=['project', 'project.submodule'],
    package_dir={
        'project': '.',
        'project.submodule': './submodule1',
    },
)

Update

See the following for an idea how to use such a project in editable or develop mode: https://stackoverflow.com/a/58429242/11138259



来源:https://stackoverflow.com/questions/58375315/create-editable-package-setup-py-in-the-same-root-folder-as-init-py

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!