Giter VIP home page Giter VIP logo

vermin's Introduction

PyPI version Build Status Coverage Commits since last

Vermin

Concurrently detect the minimum Python versions needed to run code. Additionally, since the code is vanilla Python, and it doesn't have any external dependencies, it works with v2.7+ and v3+.

It functions by parsing Python code into an abstract syntax tree (AST), which it traverses and matches against internal dictionaries with 648 rules divided into 104 modules, 441 classes/functions/constants members of modules, 99 kwargs of functions, and 4 strftime directives. Including looking for v2/v3 print expr and print(expr), long, f-strings, "..".format(..), imports (import X, from X import Y, from X import *), function calls wrt. name and kwargs, and strftime + strptime directives used. It tries to detect and ignore user-defined functions, classes, arguments, and variables with names that clash with library-defined symbols.

Usage

It is fairly straightforward to use Vermin:

./vermin.py /path/to/your/project

Or via PyPi:

% pip install vermin
% vermin /path/to/your/project

When using continuous integration (CI) tools, like Travis CI, Vermin can be used to check that the minimum required versions didn't change. The following is an exerpt:

install:
- ./setup_virtual_env.sh
- pip install vermin
script:
- vermin -t=2.7 -t=3 project_package otherfile.py

Examples

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

Options:
  -q      Quite mode. It only prints the final versions verdict.
  -v..    Verbosity level 1 to 3. -v shows less than -vv but more than no verbosity.
  -t=V    Target version that files must abide by. Can be specified once or twice.
          If not met Vermin will exit with code 1.
  -p=N    Use N concurrent processes to analyze files (defaults to all cores = 8).
  -i      Ignore incompatible version warnings.
  -d      Dump AST node visits.

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

% ./vermin.py -q -t=3.3 vermin
Minimum required versions: 2.7, 3.0
Target versions not met:   3.3
% echo $?
1

% ./vermin.py -v examples
Detecting python files..
Analyzing 6 files using 8 processes..
             /path/to/examples/formatv2.py
2.7, 3.2     /path/to/examples/argparse.py
2.7, 3.0     /path/to/examples/formatv3.py
2.0, 3.0     /path/to/examples/printv3.py
!2, 3.4      /path/to/examples/abc.py
             /path/to/examples/unknown.py
Minimum required versions:   3.4
Incompatible versions:         2

Contributing

Contributions are very welcome, especially adding and updating detection rules of modules, functions, classes etc. to cover as many Python versions as possible. For PRs, make sure to keep the code vanilla Python and run make test first. Note that code must be remain valid and working on Python v2.7+ and v3+.

vermin's People

Contributors

moreati avatar netromdk avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.