检查requirements.txt文件与环境之间的差异。

pip-lock的Python项目详细描述


https://img.shields.io/pypi/v/pip-lock.svghttps://img.shields.io/travis/adamchainz/pip-lock/master.svg

检查requirements.txt文件与环境之间的差异。

在yplan,我们在开发和测试期间自动调用check_requirements(),以便为开发人员提供即时的 如果他们的环境与当前的requirements.txt不同步,则提供反馈。这确保了开发人员 不会遇到与不同步要求相关的意外行为或错误。

安装

使用pip安装

pipinstallpip-lock

支持Python3.4+。

示例用法

frompip_lockimportcheck_requirements# Check requirements and if there are any mismatches, print a message and die with exit code 1check_requirements('requirements.txt')
frompip_lockimportget_mismatches# Get mismatches as a dictionary of package names to tuples (expected_version, actual_version)# e.g. {'django': ('1.10.2', None), 'requests': ('2.11.1', '2.9.2')}mismatches=get_mismatches('requirements.txt')

在yplan,我们在django中调用check_requirements(),它每次都检查需求 django启动或运行测试。我们建议检查环境以确保它不在生产环境中运行 环境,以避免减慢应用程序启动速度。

API

check_requirements(requirements_file_path, post_text='')

退出代码1,如果环境和需求文件不匹配,输出到STDRR。

requirements_file_pathrequirements.txt文件的路径-建议使用绝对文件路径。

post_text是可选文本,显示在stderr消息之后。这可以用来显示指令 如何更新需求。

示例:

check_requirements('requirements.txt',post_text='\nRun the following on your host machine: \n\n    vagrant provision\n')
There are requirement mismatches with requirements.txt:
    * Package Django has version 1.9.10 but you have version 1.9.0 installed.
    * Package requests has version 2.11.1 but you have version 2.11.0 installed.
    * Package requests-oauthlib is in requirements.txt but not in virtualenv

Run the following on your host machine:

    vagrant provision

get_mismatches(requirements_file_path, post_text='')

对于不匹配的包,将包名称字典返回到(expected_version, actual_version)的元组。

requirements_file_pathrequirements.txt文件的路径-建议使用绝对文件路径。

示例:

>>>get_mismatches('requirements.txt'){'django':('1.10.2','1.9.0'),'requests':('2.11.1','2.9.2'),'request-oauthlib':('0.7.0',None)}

历史记录

2.0.0(2019-02-28)

  • 放弃Python2支持,现在只支持Python3.4+。

1.2.0(2018-07-25)

  • 忽略已安装的外部(-e)包。

1.1.1(2018-04-15)

  • 修复pip 10将导入移动到pip._internal

1.1.0(2016-08-18)

  • 删除使相对文件路径相对于 调用代码文件。它现在是相对于 当前工作目录。建议通过绝对路径。
  • 比较包名称不区分大小写 requirements.txt对canoncial包使用不同大小写的文件 名字。这可能发生在始终输出小写字母的pip-compile上 名字。
  • 修复“不匹配”输入错误
  • 在错误消息中,仅将不匹配列表缩进4个空格

1.0.2(2016-10-28)

  • 修复所有环境的相对路径

1.0.1(2016-10-28)

  • 支持relative requirements.txt路径

1.0.0(2016-10-27)

  • pypi上的第一个版本。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java log4j找不到log4jtest。房产?   我在java线程“awteventque1”中获得异常。lang.NullPointerException   java为什么在使用完整路径从文件系统读取文件时出错?   java如何迭代所有注册表项?   java中的安卓 Opencv SVM未正确训练   多线程Java ThreadPoolExecutor关闭特定线程?   如何使用Java NIO CreateDirectory方法设置目录所有者组?   java NatTable混合了固定宽度的列和可调整大小的填充剩余空间   java如何删除特定网络,即使该网络是由安卓上的其他设备创建的?   java Guava toJavaUtil()不存在   java对许多常量使用枚举是有效的memorywise?   java是否可以使用坐标定位JButton?   从WSDL生成java代码导致异常   java如何在安卓中导出javadoc   爬行JAX中的java NoClassDefFoundError错误   java为片段中的文本视图设置区域设置   发送最后一条消息后发生Java RMI RemoteException