Detect the minimum Python version to run code

In case we want to check if our code is compatible with a specific version of Python, we can get help from the library vermin.

Vermin is a library that detects the minimum Python version to run code.

As the documentation says:

“It functions by parsing Python code into an abstract syntax tree (AST), which it traverses and matches against internal dictionaries with 184 rules divided into 40 modules, 123 classes/functions/constants members of modules, and 21 kwargs of functions. Including looking for v2/v3 print expr and print(expr), "..".format(..), imports (import X, from X import Y, from X import *), and function calls wrt. name and kwargs.”

Here you can find some usage examples, which come from the github repo:

% ./vermin
Vermin 0.2.2
Usage: ./vermin [options] <python source files and folders..>

  -q      Quite mode. It only prints the final versions verdict.
  -v..    Verbosity level 1 to 2. -v shows less than -vv but more than no verbosity.
  -i      Ignore incompatible version warnings.
  -p=X    Use X concurrent processes to analyze files (defaults to all cores = 8).
  -d      Dump AST node visits.

% ./vermin -q
Minimum required versions: 2.7, 3.0

% ./ -v examples
Detecting python files..
Analyzing 6 files using 8 processes..
2.7, 3.2     /path/to/examples/
2.7, 3.0     /path/to/examples/
2.0, 3.0     /path/to/examples/
!2, 3.4      /path/to/examples/
Minimum required versions: !2, 3.4

When it yields !2 or !3 it means that it explicitly cannot run on that version

4 thoughts on “Detect the minimum Python version to run code

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s