检查requirements.txt文件与环境之间的差异。
pip-lock的Python项目详细描述
检查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_path是requirements.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_path是requirements.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上的第一个版本。