setuptools“至少其中之一”依赖规范
在某些情况下,有各种模块,每个模块都实现通用 API(在我的例子中,是旧的纯 python elementtree
、cElementTree
、lxml.etree 和内置
xml.etree
)。我可以使用 ElementTree
编写模块来尝试每个选项,并根据我自己的偏好顺序采用第一个存在的选项 - 但我找不到任何有关指定仅其中一个选项的信息这些必须安装在 setup.py 中。我想写一些看起来像这样的东西:
setup(
...,
install_requires="""
elementtree | cElementTree | lxml
""",
...
)
这个或类似的东西可能吗?
In some cases, there are various modules which each implement a common API (in my case, the old pure-python elementtree
, cElementTree
, lxml.etree
, and the built-in xml.etree
). I can write the module using ElementTree
to try each of these options, and take the first one that exists according to my own preference order -- but I can't find any information on specifying that only one of these must be installed in setup.py
. I want to write something that looks like this:
setup(
...,
install_requires="""
elementtree | cElementTree | lxml
""",
...
)
Is this, or something like it, possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不这么认为,但是,如果您使用的是相当新的 Python,
elementtree
是标准 Python 库的一部分,为什么您担心它可能不存在呢? (我确实知道这对于 API 的几种可能实现的其他情况来说是一个问题,我只是想知道您是否真的需要它来满足您的特定用例)。I don't think so, but, if you're using a reasonably recent Python,
elementtree
being part of the standard Python libraries, why do you worry it might be absent? (I do understand this would be a problem for other cases of several possible implementations of an API, I just wonder if you really need it for your specific use case).您可能想尝试在 setup.py 中执行类似的操作:
如果未安装等效项,这基本上会将 elementree 包安装为依赖项。
You might want to try doing something like this in setup.py:
This will basically install elementree package as dependency if none of the equivalent are installed.