通过分析包导入为任何项目生成pip requirements.txt文件
rqmts的Python项目详细描述
要求
rqmts-通过分析包导入为任何项目生成requirements.txt文件
单击here查看演示。
单击here获取文档。
关于项目
rqmts是一个很棒的独立工具,它通过分析包导入为任何项目生成requirements.txt
文件。
为什么选择这个项目
问题
- 为什么不直接使用pip的freeze命令为我的项目生成一个
requirements.txt
文件? - 既然已经存在pipreqs、pigar、poetry等模块,为什么要re invent the wheel?
- 为什么不手动?
答案
- 为什么不直接冻结pip?
pip freeze
只保存环境中与pip install
一起安装的包。pip freeze
保存环境中的所有包,包括当前项目中不使用的包。(如果您没有virtualenv)
- 为什么要重新发明轮子?
- pipreqs多次失败(请参阅-pipreqs/issues)
- 我找到了这个仓库,想,“嗯。我想在尝试匹配pipreqs结果“
- pigar查询pypi服务器,大的no-no。理想情况下,它应该是本地的。(回退时?那么也许……)
- 除此之外,pigar建议使用pipenv(pipenv has serious issues)
- poetry引号“但是,请注意,它还将安装poetry的依赖项,这可能会导致冲突。”
- 纯粹的好奇。“我能创建一个有潜力收集成百上千个贡献者的项目吗?”
- 手动?
- 你现在是认真的吗?
安装
rqmts提供一个自定义脚本,该脚本将通过使用无文件/基于内存的执行来运行与系统其他部分隔离的rqmts实例。这是运行需求的推荐方式。
curl -sSL https://raw.githubusercontent.com/0x48piraj/rqmts/master/Rqmts.py | python
或者,可以从根目录下载Rqmts.py
,然后单独执行。
也可以使用pip安装rqmts。
pip install --user rqmts (windows)
pip3 install rqmts (linux)
用法
命令行界面
C:\rqmts>py -m rqmts -h
usage: __main__.py [-h] [-p FILE]
.===================================================================.
|| rqmts - Generate pip requirements.txt for any project ||
|| ||
|| ||
|| ___ ||
|| .' '. requirements.txt ||
|| / rqmts \ oOoOo. ||
|| | | | ,==|||||o. ||
|| \ pip / _|| |||||o. pip ||
|| '.___.' _.-'^|| ||||| ||
|| __/_______.-' '==rqmts ||
|| _.-'` / """"" ||
|| .-' / oOoOo. ||
|| `-._ / ,==|||||o. ||
|| '-/._|| |||||o. python ||
|| / ^|| ||||| ||
|| / '==rqmts ||
|| /________""""" ||
|| `\ `\ ||
|| \ `\ ||
|| \ `\ ||
|| / / ||
|| / / ||
|| @0x48piraj /_____ /_____ ||
|| ||
'==================================================================='
Options:
-p FILE, --path FILE Path of the Python script (inside quotation marks)
--REDACTED--
C:\rqmts>py -m rqmts -p "C:\test_proj\run.py"
--REDATED--
[!] System package found : string
[!] System package found : time
[!] System package found : random
[!] System package found : os
[!] System package found : re
[+] Success: Parsed the dependencies correctly
[*] Saving generated requirements.txt
[+] Success: requirements.txt saved
[+] Path where it can be found: C:\test_proj\requirements.txt
交互模式
C:\rqmts>py -m rqmts
.===================================================================.
|| rqmts - Generate pip requirements.txt for any project ||
|| ||
|| ||
|| ___ ||
|| .' '. requirements.txt ||
|| / rqmts \ oOoOo. ||
|| | | | ,==|||||o. ||
|| \ pip / _|| |||||o. pip ||
|| '.___.' _.-'^|| ||||| ||
|| __/_______.-' '==rqmts ||
|| _.-'` / """"" ||
|| .-' / oOoOo. ||
|| `-._ / ,==|||||o. ||
|| '-/._|| |||||o. python ||
|| / ^|| ||||| ||
|| / '==rqmts ||
|| /________""""" ||
|| `\ `\ ||
|| \ `\ ||
|| \ `\ ||
|| / / ||
|| / / ||
|| @0x48piraj /_____ /_____ ||
|| ||
'==================================================================='
[*] Path not provided, invoking interactive mode ...
[*] Enter the path of Python script
----> C:\test_proj\run.py
[!] System package found : random
[!] System package found : os
[!] System package found : re
[!] System package found : time
[!] System package found : string
[+] Success: Parsed the dependencies correctly
[*] Saving generated requirements.txt
[+] Success: requirements.txt saved
[+] Path where it can be found: C:\test_proj\requirements.txt
贡献
C:\rqmts>py -m rqmts -h
usage: __main__.py [-h] [-p FILE]
.===================================================================.
|| rqmts - Generate pip requirements.txt for any project ||
|| ||
|| ||
|| ___ ||
|| .' '. requirements.txt ||
|| / rqmts \ oOoOo. ||
|| | | | ,==|||||o. ||
|| \ pip / _|| |||||o. pip ||
|| '.___.' _.-'^|| ||||| ||
|| __/_______.-' '==rqmts ||
|| _.-'` / """"" ||
|| .-' / oOoOo. ||
|| `-._ / ,==|||||o. ||
|| '-/._|| |||||o. python ||
|| / ^|| ||||| ||
|| / '==rqmts ||
|| /________""""" ||
|| `\ `\ ||
|| \ `\ ||
|| \ `\ ||
|| / / ||
|| / / ||
|| @0x48piraj /_____ /_____ ||
|| ||
'==================================================================='
Options:
-p FILE, --path FILE Path of the Python script (inside quotation marks)
--REDACTED--
C:\rqmts>py -m rqmts -p "C:\test_proj\run.py"
--REDATED--
[!] System package found : string
[!] System package found : time
[!] System package found : random
[!] System package found : os
[!] System package found : re
[+] Success: Parsed the dependencies correctly
[*] Saving generated requirements.txt
[+] Success: requirements.txt saved
[+] Path where it can be found: C:\test_proj\requirements.txt
C:\rqmts>py -m rqmts
.===================================================================.
|| rqmts - Generate pip requirements.txt for any project ||
|| ||
|| ||
|| ___ ||
|| .' '. requirements.txt ||
|| / rqmts \ oOoOo. ||
|| | | | ,==|||||o. ||
|| \ pip / _|| |||||o. pip ||
|| '.___.' _.-'^|| ||||| ||
|| __/_______.-' '==rqmts ||
|| _.-'` / """"" ||
|| .-' / oOoOo. ||
|| `-._ / ,==|||||o. ||
|| '-/._|| |||||o. python ||
|| / ^|| ||||| ||
|| / '==rqmts ||
|| /________""""" ||
|| `\ `\ ||
|| \ `\ ||
|| \ `\ ||
|| / / ||
|| / / ||
|| @0x48piraj /_____ /_____ ||
|| ||
'==================================================================='
[*] Path not provided, invoking interactive mode ...
[*] Enter the path of Python script
----> C:\test_proj\run.py
[!] System package found : random
[!] System package found : os
[!] System package found : re
[!] System package found : time
[!] System package found : string
[+] Success: Parsed the dependencies correctly
[*] Saving generated requirements.txt
[+] Success: requirements.txt saved
[+] Path where it can be found: C:\test_proj\requirements.txt
该项目的主要挑战是从首先从输入脚本提取的模块中提取所需的元数据。
挑战
- python中的版本号可以放在非常不同的位置,具体取决于大小写
- 包索引中的包名与我们导入的模块名无关
这些怪癖让这个项目很有趣。源代码中有一个有趣的注释,它反映了我们之间的差异,如下所示:
# module_name.__version__ sucks, because we suck (PEP 0396)
此项目旨在结合现有的最佳策略覆盖最广泛的情况集{EM1}$(如果不是全部)
如果您有任何问题或建议,请随时open an issue或pull request!
许可证
此软件是根据bsd 3子句“new”或“revisited”许可证授权的。要查看此许可证的副本,请访问BSD 3-Clause。