在与 __init__.py 相同的根文件夹中创建可编辑的包 setup.py [英] Create editable package setup.py in the same root folder as __init__.py
问题描述
现有项目的设置方式是存储库在根文件夹中有一个 __init__.py
.我想在存储库中创建一个 setup.py
所以这将是生成的项目结构:
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
并且您应该能够:
git clone project.url
cd project-master
pip install -e .
from project.submodule1 import ...
我尝试了临时复制子文件夹中的内容的 hacky 解决方案,以便 setup.py
是包文件夹的上一级并从那里安装.如果我 pip install .
这很有效,但不幸的是,这个解决方案在可编辑模式下不起作用,因为我在安装后删除了临时文件夹.
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.
问题:创建正确的 setup.py
的正确方法是什么,该 setup.py
可在可编辑模式下运行并与包的 __init__ 位于同一根文件夹中.py
?
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
?
推荐答案
这对于 可编辑 安装似乎是不可能的.据我所知,最接近的如下:
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',
},
)
<小时>
更新
有关如何在可编辑或开发模式下使用此类项目的想法,请参阅以下内容:https://stackoverflow.com/a/58429242/11138259
See the following for an idea how to use such a project in editable or develop mode: https://stackoverflow.com/a/58429242/11138259
这篇关于在与 __init__.py 相同的根文件夹中创建可编辑的包 setup.py的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!