Show HN: Req Update Check 工具

ontherivt / req-update-check Public

License

MIT license 6 stars 1 fork

req-update-check

Tests Coverage Status Code style: ruff

一个 Python 工具,用于检查你的 requirements.txt 文件中是否有可用的包更新,并可选择文件缓存以获得更好的性能。

功能

安装

从 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

参数:

选项:

示例输出

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()

开发

要进行开发设置:

  1. 克隆仓库
  2. 创建一个虚拟环境: python -m venv venv
  3. 激活虚拟环境: source venv/bin/activate (Unix) 或 venv\Scripts\activate (Windows)
  4. 安装开发依赖项: pip install -e ".[dev]"

要运行测试:

  1. python -m unittest

贡献

欢迎贡献!请随时提交 Pull Request。

License

此项目基于 MIT License 开源 - 参见 LICENSE 文件了解详情。