[英]Description of dependencies in requirements.txt
I've been given a large requirements.txt
file with ~130 dependencies, half of which I don't recognise.我收到了一个包含约 130 个依赖项的大型
requirements.txt
文件,其中一半我不认识。
Is there an easy way to get a short desciption of each dependency without having to look each one up myself in the CheeseShop ?有没有一种简单的方法可以简单地了解每个依赖项,而不必自己在CheeseShop中查找每个依赖项?
It turns out that you can get info
(including a summary
and the latest version
) directly from pypi.org as JSON:事实证明,您可以直接从 pypi.org 获取
info
(包括summary
和最新version
),如 JSON:
http://pypi.org/pypi/<package_name>/json
This is working for me:这对我有用:
#!/usr/bin/env python3
import json
import sys
from urllib import request
from urllib.error import HTTPError
filename = 'requirements.txt' if len(sys.argv) == 1 else sys.argv[1]
with open(filename, 'r') as f:
for line in f:
package = line.split('=', 1)[0].rstrip()
# remove any version info given after '>' or '<'
package = package.split('<')[0].split('>')[0]
if not package: continue
url = 'https://pypi.org/pypi/{}/json'.format(package)
try:
with request.urlopen(url.format(package)) as url:
data = json.loads(url.read().decode())
summary = data['info']['summary']
version = data['info']['version']
except: # e.g. HTTPError:
summary = 'error'
version = ''
print('{} ({}): {}'.format(line.rstrip(), version, summary))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.