确定所需的最低Python版本的工具? [英] Tool to determine what lowest version of Python required?

查看:71
本文介绍了确定所需的最低Python版本的工具?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否存在类似于Pylint的东西,它们将查看(或运行)Python脚本,并确定每行(或函数)所需的Python版本?

Is there something similar to Pylint, that will look at a Python script (or run it), and determine which version of Python each line (or function) requires?

例如,理论用法:

$ magic_tool <EOF
with something:
    pass
EOF
1: 'with' statement requires Python 2.6 or greater

$ magic_tool <EOF
class Something:
    @classmethod
    def blah(cls):
        pass
EOF
2: classmethod requires Python 2.2 or greater
$ magic_tool <EOF
print """Test
"""
EOF
1: Triple-quote requires Python 1.5 of later

这样的事情可能吗?我想最简单的方法是将所有Python版本都放到光盘上,运行每个版本的脚本,然后看看会发生什么错误。。

Is such a thing possible? I suppose the simplest way would be to have all Python versions on disc, run the script with each one and see what errors occur..

推荐答案

Greg Hewgill的工具pyqver已有一段时间没有更新。

The tool pyqver from Greg Hewgill wasn't updated since a while.

vermin 是一个类似的实用程序,它以详细模式( -vvv )显示决定中考虑的行。

vermin is a similar utility which shows in the verbose mode (-vvv) what lines are considered in the decision.

% pip install vermin
% vermin -vvv somescript.py
Detecting python files..
Analyzing using 8 processes..
!2, 3.6      /path/to/somescript.py
  L13: f-strings require 3.6+
  L14: f-strings require 3.6+
  L15: f-strings require 3.6+
  L16: f-strings require 3.6+
  print(expr) requires 2+ or 3+

Minimum required versions: 3.6
Incompatible versions:     2

奖金:带参数 -t = V ,您可以定义要与之兼容的目标版本 V 。如果不满足此版本要求,脚本将以退出代码 1 退出,从而易于集成到测试套件中。

Bonus: With the parameter -t=V you can define a target version V you want to be compatible with. If this version requirement is not met, the script will exit with an exit code 1, making it easy integratable into a test suite.

这篇关于确定所需的最低Python版本的工具?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆