带有多个模块和打包名称空间的Python 2.7软件包安装 [英] Python 2.7 package install with multiple modules and packaged namespaces
问题描述
我想将多个python模块保留在同一回购中,以便更轻松地管理它们并同时处理它们.
I want to keep multiple python modules in the same repo so it's easier to manage them, and work on them simultaneously.
这些模块是打包的名称空间包,因此我无法在同一级别拥有根,其中有4个根,并且以后可能还会更多.
The modules are packaged namespace packages, so I can't have the roots at the same level, and there are 4 of them, and might be more later.
这是我的结构:
repo/
modules/
foo_a/
setup.py
VERSION
foo/
__init__.py
a/
foo_b/
setup.py
VERSION
foo/
__init__.py
b/
VERSION文件是分开的,并且跟踪不同的版本.上面的__init__.py
文件是特殊类型在这里描述.
The VERSION files are separate and track different versions. And the __init__.py
files above are the special type described here.
当前,当其中的VERSION文件更改时,我会自动构建相应的模块.
Currently I automatically build the respective module when the VERSION file in it changes.
我想要的是能够从回购目录的根目录安装带有所有名称空间包的整个包.所以我可以做pip install .
.要么将所有内容都安装为单个软件包(foo_all
),要么单独安装每个模块.
What I want is to be able to install the entire package with all namespace packages from the root of the repo. So I can just do pip install .
. Either this would install everything as a single package (foo_all
) or individually install each module.
一个用例是,大多数人都使用所有模块,并且他们想要易于安装的东西,但是有时候我只想能够安装其中一个模块.
The usecase for this, is that most people use all modules and they want something easy to install, but sometimes I just want to be able to install one of the modules.
关键是您可以运行:
pip install repo
然后这些Python命令成功.
and then these Python commands succeed.
from foo import a
from foo import b
关于如何执行此操作的任何想法?
Any ideas on how to do this?
我看过 setuptools.find_namespace_packages()
函数,但是看起来好像只有Python3,而且我也不完全确定这是我所需要的.我无法升级到Python3,因为它是针对客户端的,并且依赖于令人难以置信的Python2 API.
I've seen the setuptools.find_namespace_packages()
function, but that looks like it's only Python3, and I'm not entirely sure it's what I need anyway. I can't upgrade to Python3 because it's for a client and it's dependent on a Python2 API, which is incredibly frustrating.
还看到了setuptools.setup()
的package_dir
选项,但是这是因为所有软件包都位于不同的文件夹中.我不能将所有软件包都放在不同的文件夹中,因为单个文件会重叠(setup.py
,VERSION
,foo/
)
Also seen the package_dir
option for setuptools.setup()
, but that's for if all the packages are just in a different folder. I can't put all the package in a different folder because the individual files would overlap (setup.py
, VERSION
, foo/
)
推荐答案
可能将foo.a
和foo.b
作为独立项目分发,同时将空的foo
项目分发给其他两个为install_requires
的项目.
Probably distribute foo.a
and foo.b
as independent projects alongside a empty foo
project that has the other two as install_requires
.
关于打包命名空间包"的《 Python打包用户指南》中描述了整个设置".
这篇关于带有多个模块和打包名称空间的Python 2.7软件包安装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!