Show HN: Req Update Check
该文章介绍了一个名为 `req-update-check` 的 Python 工具,用于检查 `requirements.txt` 文件中 Python 包的更新。它能显示更新的严重程度、包主页和变更日志,并支持文件缓存以提高性能。该工具支持多种安装方式,包括从 PyPI、GitHub 或源代码安装。文章还提供了命令行选项和 Python API 的使用示例,以及对 `requirements.txt` 文件格式的支持说明。最后,文章说明了开发和贡献的流程,并声明了 MIT 许可证。
Show HN: Req Update Check 工具
ontherivt / req-update-check Public
License
req-update-check
一个 Python 工具,用于检查你的 requirements.txt
文件中是否有可用的包更新,并可选择文件缓存以获得更好的性能。
功能
- 检查你的
requirements.txt
文件中是否有可用的更新 - 显示更新的严重程度(major/minor/patch)
- 显示包的主页和变更日志(如果可用)
- 可选的文件缓存,用于更快的重复检查
- 支持
requirements.txt
中的注释和行内注释 - 忽略预发布版本(alpha、beta、release candidates)
安装
从 PyPI 安装:
pip install req-update-check
或者直接从仓库安装:
pip install git+https://github.com/ontherivt/req-update-check.git
或者从源代码安装:
git clone https://github.com/ontherivt/req-update-check.git
cd req-update-check
pip install -e .
使用方法
基本用法:
req-update-check requirements.txt
命令行选项
req-update-check [-h] [--no-cache] [--cache-dir CACHE_DIR] requirements_file
参数:
requirements_file
: 指向你的requirements.txt
文件的路径
选项:
--no-cache
: 禁用文件缓存--cache-dir
: 自定义缓存目录 (默认:~/.req-update-check-cache
)
示例输出
File caching enabled
The following packages need to be updated:
requests: 2.28.0 -> 2.31.0 [minor]
Pypi page: https://pypi.python.org/project/requests/
Homepage: https://requests.readthedocs.io
Changelog: https://requests.readthedocs.io/en/latest/community/updates/#release-history
redis: 4.5.0 -> 5.0.1 [major]
Pypi page: https://pypi.python.org/project/redis/
Homepage: https://github.com/redis/redis-py
Changelog: https://github.com/redis/redis-py/blob/master/CHANGES
使用文件缓存
该工具支持文件缓存,以提高多次检查时的性能。你可以配置缓存存储:
req-update-check --cache-dir ~/.your-cache-dir requirements.txt
Requirements.txt 格式
该工具支持以下格式的 requirements.txt
文件:
package==1.2.3
package == 1.2.3 # with spaces
package==1.2.3 # with inline comments
# Full line comments
注意:目前仅支持精确版本说明符 (==
)。计划在未来的版本中支持其他说明符(如 >=
, ~=
)。
Python API
你也可以使用 req-update-check
作为一个 Python 库:
from req_update_check import Requirements
# Without file cache
req = Requirements('requirements.txt', allow_cache=False)
req.check_packages()
req.report()
# With file cache defaults
req = Requirements('requirements.txt')
req.check_packages()
req.report()
开发
要进行开发设置:
- 克隆仓库
- 创建一个虚拟环境:
python -m venv venv
- 激活虚拟环境:
source venv/bin/activate
(Unix) 或venv\Scripts\activate
(Windows) - 安装开发依赖项:
pip install -e ".[dev]"
要运行测试:
python -m unittest
贡献
欢迎贡献!请随时提交 Pull Request。
License
此项目基于 MIT License 开源 - 参见 LICENSE 文件了解详情。