V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
ferstar
V2EX  ›  Python

分享自己写的一个可以自动检测项目 requirements.txt 的 package

  •  
  •   ferstar ·
    ferstar · 2020-09-10 13:09:06 +08:00 · 1517 次点击
    这是一个创建于 1317 天前的主题,其中的信息可能已经有所发展或是发生改变。

    偶尔会碰到自己本地环境加了某package, 但忘了往requirements.txt里加导致代码提交后CIimport error的问题, 找了一圈没有合适的轮子, 所以就自己造一个

    工具也可以用来指导简化requirements.txtpackage内容, 比如numpy这个包, 实际上'tensorflow', 'pandas'是有包含的, 所以requirements.txt里只需要写'tensorflow', 'pandas'就可以了, 完全没必要再去补numpy

    具体运行效果:

    Bad import detected: "bs4"  # bad import 的依据是你在代码中 import 但又没把这个包写在 requirements.txt 里
    /Users/ferstar/PycharmProjects/xxx_demo/xxx_spider.py:12
    Bad import detected: "requests"
    /Users/ferstar/PycharmProjects/xxx_demo/xxx_handler.py:17
    "numpy" required by: {'numpy', 'scikit-learn', 'tensorflow', 'pandas'}  # numpy 在这里相当于重复了, 可以删掉
    

    附上项目地址: check-requirements-txt

    PS: 可以配合pre-commit使用, 也可以单独作为CLI工具写在单元测试样例里

    2 条回复    2020-09-10 16:45:00 +08:00
    no1xsyzy
        1
    no1xsyzy  
       2020-09-10 14:57:15 +08:00
    pip-tools
    ferstar
        2
    ferstar  
    OP
       2020-09-10 16:45:00 +08:00
    @no1xsyzy 感谢回复, 也考察过这个工具, 但是并不是很符合我的需求, 而且相对太重了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5474 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 06:36 · PVG 14:36 · LAX 23:36 · JFK 02:36
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.