[英]Python Packaging multiple subpackages with different data directories
I have a structure of the directory as such with foobar
and alphabet
data directories together with the code something.py
: 我有一个目录结构,例如
foobar
和alphabet
数据目录以及代码something.py
:
\mylibrary
\packages
\foobar
foo.zip
bar.zip
\alphabet
abc.zip
xyz.zip
something.py
setup.py
And the goal is such that users can pip install the module as such: 目标是使用户可以通过以下方式pip安装模块:
pip install mylibrary[alphabet]
And that'll only include the data from the packages/alphabet/*
data and the python code. 而且这将仅包括来自
packages/alphabet/*
数据和python代码的数据。 Similar behavior should be available for pip install mylibrary[foobar]
. pip install mylibrary[foobar]
应该具有类似的行为。
If the user installs without the specification: 如果用户未按照规范进行安装:
pip install mylibrary
Then it'll include all the data directories under packages/
. 然后它将在
packages/
下包含所有数据目录。
Currently, I've tried writing the setup.py
with Python3.5 as such: 目前,我尝试使用Python3.5编写
setup.py
,如下所示:
import glob
from setuptools import setup, find_packages
setup(
name = 'mylibrary',
packages = ['packages'],
package_data={'packages':glob.glob('packages' + '/**/*.txt', recursive=True)},
)
That will create a distribution with all the data directories when users do pip install mylibrary
. 当用户执行
pip install mylibrary
时,这将创建一个包含所有数据目录的pip install mylibrary
。
How should I change the setup.py
such that specific pip installs like pip install mylibrary[alphabet]
is possible? 我应该如何更改
setup.py
,以便可以进行像pip install mylibrary[alphabet]
这样的特定pip安装?
Firs you have to package and publish alphabet
and foobar
as a separate packages as pip install mylibrary[alphabet]
means 首先,您必须将
pip install mylibrary[alphabet]
含义打包并发布alphabet
和foobar
作为单独的软件包
pip install mylibrary
pip install alphabet
After that add alphabet
and foobar
as extras
: 之后,添加
alphabet
和foobar
作为extras
:
setup(
…,
extras = {
'alphabet': ['alphabet'],
'foobar': ['foobar'],
}
)
The keys in the dictionary are the names used in pip install mylibrary[EXTRA_NAME]
, the values are a list of package names that will be installed from PyPI. 字典中的键是
pip install mylibrary[EXTRA_NAME]
使用的名称,这些值是将从PyPI安装的软件包名称的列表。
PS. PS。 And no, you cannot use extras to install some data files that are not available as packages from PyPI.
不,您不能使用Extras安装一些数据文件,这些数据文件不能从PyPI包中获得。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.