我得到了一个很大的requirements.txt
文件,它具有约130个依赖项,其中有一半我不认识。
是否有一种简单的方法来简短地了解每个依赖项,而不必在CheeseShop中亲自检查每个依赖项?
答案 0 :(得分:0)
事实证明,您可以直接从pypi.org以JSON的形式获取info
(包括summary
和最新的version
)
http://pypi.org/pypi/<package_name>/json
这对我有用:
#!/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))