Python Easy_Install 更新报告

发布于 2024-10-20 11:36:07 字数 155 浏览 7 评论 0原文

有没有一种简单的方法来获取通过 easy_install 安装的所有具有更新版本的 Python 库的报告?我不想简单地在已知已安装库的列表上重新运行 easy_install,因为较新的库可能具有非向后兼容的更改。我想获得一个列表,以便快速查看更改的内容,并检查新版本以审查任何潜在冲突的更改。

Is there an easy way to get a report of all Python libraries installed via easy_install that have a more recent version available? I don't want to simply re-run easy_install on a list of known installed libraries, because the newer library might have a non-backwards compatible change. I'd like to get a list so I quickly see what's changed, and inspect new releases to vet-out any potentially conflicting changes.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

偷得浮生 2024-10-27 11:36:07

这是一个快速脚本,用于扫描 easy-install.pth 文件并打印已安装软件包的较新版本列表。您可以将其自定义为仅显示可用的最新版本(采用 parsed_version 的最大值),调整输出格式等:

#!/usr/bin/env python
import os, sys
from distutils import sysconfig
from pkg_resources import Requirement
from setuptools.package_index import PackageIndex

index = PackageIndex()
root = sysconfig.get_python_lib()
path = os.path.join(root, 'easy-install.pth')
if not os.path.exists(path):
    sys.exit(1)
for line in open(path, 'rb'):
    if line.startswith('import sys'):
        continue
    path = os.path.join(root, line.strip(), 'EGG-INFO', 'PKG-INFO')
    if not os.path.exists(path):
        continue
    lines = [r.split(':', 1) for r in open(path, 'rb').readlines() if ':' in r]
    info = dict((k.strip(), v.strip()) for k, v in lines)
    print '%s %s updates..' % (info['Name'], info['Version'])
    spec = Requirement.parse(info['Name'] + '>' + info['Version'])
    index.find_packages(spec)
    versions = set([
        (d.parsed_version, d.version) for d in index[spec.key] if d in spec
        ])
    if versions:
        for _, version in sorted(versions):
            print '\t', version
    else:
        print '\tnone'

用法:

% easy_install networkx==1.3
% easy_install gdata==2.0.5
% ./pkgreport
networkx 1.3 updates..
        1.4rc1
        1.4
gdata 2.0.5 updates..
        2.0.6
        2.0.7
        2.0.8
        2.0.9
        2.0.14

Here is a quick script to scan the easy-install.pth file and print a list of newer versions of installed packages. You could customize it to only show the newest version available (take max of parsed_version), tweak the output format, etc:

#!/usr/bin/env python
import os, sys
from distutils import sysconfig
from pkg_resources import Requirement
from setuptools.package_index import PackageIndex

index = PackageIndex()
root = sysconfig.get_python_lib()
path = os.path.join(root, 'easy-install.pth')
if not os.path.exists(path):
    sys.exit(1)
for line in open(path, 'rb'):
    if line.startswith('import sys'):
        continue
    path = os.path.join(root, line.strip(), 'EGG-INFO', 'PKG-INFO')
    if not os.path.exists(path):
        continue
    lines = [r.split(':', 1) for r in open(path, 'rb').readlines() if ':' in r]
    info = dict((k.strip(), v.strip()) for k, v in lines)
    print '%s %s updates..' % (info['Name'], info['Version'])
    spec = Requirement.parse(info['Name'] + '>' + info['Version'])
    index.find_packages(spec)
    versions = set([
        (d.parsed_version, d.version) for d in index[spec.key] if d in spec
        ])
    if versions:
        for _, version in sorted(versions):
            print '\t', version
    else:
        print '\tnone'

Usage:

% easy_install networkx==1.3
% easy_install gdata==2.0.5
% ./pkgreport
networkx 1.3 updates..
        1.4rc1
        1.4
gdata 2.0.5 updates..
        2.0.6
        2.0.7
        2.0.8
        2.0.9
        2.0.14
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文