[推荐] vermin: 检测运行代码所需的 Python 版本

昨天更新 lsp-bridge 之后发现报错无法启动(现在已经修复了 72bb4a3),经过一番搜索,发现是因为 Python 版本落后了,random.randbytes 需要 Python 3.9+。我就想有没有工具像 package-lint.el 一样,可以探测当前代码所需的最小运行时呢。结果还真有:

用法:


$ vermin lsp_bridge.py
Tips:
- You're using potentially backported modules: typing
  If so, try using the following for better results: --backport typing
- Since '# novm' or '# novermin' weren't used, a speedup can be achieved using: --no-parse-comments
(disable using: --no-tips)

Minimum required versions: 3.9
Incompatible versions:     2

如果想知道更具体的信息:


$ vermin -vv lsp_bridge.py
Detecting python files..
Analyzing using 4 processes..
!2, 3.9      ~/repos/emacs-lsp-bridge/lsp_bridge.py
  'dict.fromkeys' member requires 2.3, 3.0
  'enumerate' member requires 2.3, 3.0
  'json' module requires 2.6, 3.0
  'open(encoding)' requires !2, 3.0
  'open(errors)' requires !2, 3.0
  'pathlib' module requires !2, 3.4
  'queue' module requires !2, 3.0
  'random.randbytes' member requires !2, 3.9
  'shutil.which' member requires !2, 3.3
  'str.format' member requires 2.6, 3.0
  'traceback.format_exc' member requires 2.4, 3.0
  'type' member requires 2.2, 3.0
  'typing' module requires !2, 3.5
  `"..{}..".format(..)` requires 2.7, 3.0
  `with` requires 2.5, 3.0

Tips:
- You're using potentially backported modules: typing
  If so, try using the following for better results: --backport typing
- Since '# novm' or '# novermin' weren't used, a speedup can be achieved using: --no-parse-comments
(disable using: --no-tips)

Minimum required versions: 3.9
Incompatible versions:     2

6 个赞