prequ——python需求处理
prequ的Python项目详细描述
用于处理python需求的工具。有助于保持 需求文件完整且最新。
注意:prequ当前设计为使用虚拟环境,因此 不保证与非虚拟python环境的兼容性 现在就工作。
背景
每个非库python项目都应该有一个requirements.txt文件 其中列出了项目所需的python包,即 依赖关系。很容易列出依赖项 最小和最大版本在那里,但这不是一个好的做法。 如果依赖项的版本没有固定到确切的版本,则 不确定安装了哪个版本的软件包。甚至钉住 直接依赖性是不够的,因为项目依赖性可能有 它们自己的依赖关系(项目的间接依赖关系)和 也应该别针。这就是prequ的用武之地:它使得 从中生成这些固定的直接和间接依赖项的列表 非固定要求。
还有a good article by Vincent Driessen这个词更能说明问题 为什么你要把你的包裹钉上。
普雷库是文森特·德里森的一个叉子。PIP工具很好 项目,但我想添加一些新功能并做一些更改 对现有工作流。我还需要几个虫子 早晚会修好的。大部分的虫子已经被修复了 Github请求,但未合并到PIP工具。所以我 决定创造我自己的叉子。
安装
$ pip install prequ
prequ update
的示例用法假设您有一个烧瓶项目,并希望将其固定以供生产。 您需要为prequ指定一个配置文件。配置 文件最低限度地定义了所谓的源需求,即 python包(带有可选的版本说明符)。这可以通过 将以下部分写入setup.cfg:
[prequ]requirements=Flask
现在,运行prequ update:
$ prequ update *** Compiling requirements.txt
它会产生你的requirements.txt,和所有的烧瓶 依赖项和所有基础依赖项已固定。把这个文件 也在版本控制下。生成的文件如下:
# This file is autogenerated by Prequ. To update, run: # # prequ update # flask==0.10.1 itsdangerous==0.24 jinja2==2.7.3 markupsafe==0.23 werkzeug==0.10.4
若要添加/删除包,请将其添加/删除到setup.cfg或从setup.cfg和 重新运行prequ update。若要升级所有包,请删除生成的 requirements.txt并再次运行prequ update。
prequ sync
的示例用法既然有了requirements.txt,就可以使用prequ sync 更新虚拟环境以准确反映其中的内容。注: 这将安装/升级/卸载与 requirements.txt内容。
$ prequ sync Uninstalling flake8-2.4.1: Successfully uninstalled flake8-2.4.1 Collecting click==4.1 Downloading click-4.1-py2.py3-none-any.whl (62kB) ... Found existing installation: click 4.0 Uninstalling click-4.0: Successfully uninstalled click-4.0 Successfully installed click-4.1
要同步多个*.txt依赖项列表,只需通过 命令行参数,例如:
$ prequ sync requirements.txt requirements-dev.txt
传入空参数将导致它默认为 requirements.txt。
prequ配置的更详细示例
prequ支持为需求编译和 从pip url自动生成轮子。这里有一个更详细的 演示这些功能的prequ配置示例:
[prequ]annotate=yesgenerate_hashes=noheader=yesextra_index_urls= https://shuup.github.io/pypi/simple/wheel_dir=wheelswheel_sources= github_shuup = git+ssh://git@github.com/shuup/{pkg}@v{ver}requirements= django~=1.9.5 shuup~=0.5.0 shuup-stripe==0.4.2 (wheel from github_shuup)requirements-dev= flake8 pep8-naming
现在运行prequ update将首先为 shup stripe然后它将生成两个文件,requirements.txt 以及requirements-dev.txt:
$ prequ update *** Building wheel for shuup-stripe 0.4.2 from git+ssh://git@github.com/shuup/shuup-stripe@v0.4.2 Collecting git+ssh://git@github.com/shuup/shuup-stripe@v0.4.2 ... Successfully built shuup-stripe Cleaning up... Removing source in /tmp/pip-b5rf3ioq-build *** Built: wheels/shuup_stripe-0.4.2-py2.py3-none-any.whl *** Compiling requirements.txt *** Compiling requirements-dev.txt
生成的文件将具有指定的额外索引url选项,并且 并查找wheels目录的链接:
$ cat requirements.txt # This file is autogenerated by Prequ. To update, run: # # prequ update # --extra-index-url https://shuup.github.io/pypi/simple/ --find-links wheels Babel==2.3.4 # via shuup django-bootstrap3==6.2.2 # via shuup ... $ cat requirements-dev.txt # This file is autogenerated by Prequ. To update, run: # # prequ update # --extra-index-url https://shuup.github.io/pypi/simple/ --find-links wheels flake8==3.3.0 mccabe==0.6.1 # via flake8 pep8-naming==0.4.1 pycodestyle==2.3.1 # via flake8 pyflakes==1.5.0 # via flake8