假设我有一个像一堆要求文件:解决Python的依赖关系基础上的翻译版本
requirements.txt # common for both 2.x and 3.x
requirements-2.txt # 2.x
requirements-3.txt # 3.x
,我想根据当前填充install_requires
论点setup.py
文件Python解释器版本。当然假设点处理安装过程。
解决方案1:当然,我可以编写一个简单的函数来读取并返回正确的需求。在有多个项目的情况下,这显然是不可接受的,因为我将不得不复制到任何地方的功能。
解决方案2:这里接下来的想法是写一个简单的包,它会为我,但问题是,它应该是不仅可在分配的时间(如python setup.py sdist
),但更重要的是,在安装时在一台机器上。
我被设法编写一个简单的模块来完成这件事,我们称它为depmodule
。我也有以下setup.py
:
# -*- coding: utf-8 -*-
from setuptools import setup, find_packages
try:
from depmodule import find_requirements
except ImportError:
# this line is executed when reading setup.py for the first time
# since depmodule is not installed yet
find_requirements = lambda: []
setup(
name='some-package',
packages=find_packages(),
# snip...
platforms='any',
# note that depmodule is listed here as a requirement, so it will be
# installed before some-package, thus will be available when it comes
# to running setup.py of some-package
install_requires=['depmodule'] + find_requirements(),
)
当谈到pip install some-package
它实际上正确的解决依赖,但它们不是由PIP回升,所以它只能安装:depmodule some-package
(按顺序),而不是depmodule dep1 dep2 ... some-package
。
我试图用setup_requires
的说法,但没有运气。下载依赖项,但我无法访问它,因为它是一个蛋包(未提取)。
有什么办法可以解决这个问题吗?有没有其他方法可以帮助解决这个问题?
谢谢!