Skip to content

Instantly share code, notes, and snippets.

@sevko
Last active November 3, 2021 04:59
Show Gist options
  • Save sevko/919e28588e455a6d5024 to your computer and use it in GitHub Desktop.
Save sevko/919e28588e455a6d5024 to your computer and use it in GitHub Desktop.
Parallel versions of pylint for Python 2 and 3.

pylint+

Developers commonly work on both Python 2 and 3 codebases, so it's desirable to configure the pylint utility to execute against a specific version of the language. Problematically, it relies on the system-wide Python interpreter (for abstract syntax trees, etc.), so simply passing in a flag, like --use-version 3, wouldn't suffice; the solution is to write a thin wrapper script around pylint which executes it with the proper interpreter.

requirements

You must have:

  • python2 in your $PATH
  • python3 in your $PATH
  • pylint installed (via pip, and not from your package manager) for Python 2
  • pylint installed (via pip3, and not from your package manager) for Python 3

use

Just plop the pylint+ shell-script somewhere in your $PATH, and give it executable permissions. CLI usage:

pylint+ 2|3 PYLINT_ARGS

For instance:

$ pylint+ 2 --version
No config file found, using default configuration
-c 1.4.0,
astroid 1.3.2, common 0.61.0
Python 2.7.6 (default, Mar 22 2014, 22:59:56)
[GCC 4.8.2]

$ pylint+ 3 --version
No config file found, using default configuration
-c 1.4.0,
astroid 1.3.2, common 0.63.0
Python 3.4.0 (default, Apr 11 2014, 13:05:11)
[GCC 4.8.2]
#! /usr/bin/env bash
# Description:
# A wrapper around pylint that allows the user to specify whether it should
# be executed with version 2 or 3 of the Python interpreter.
#
# Use:
# pylint+ [PYTHON_VERSION] PYLINT_ARGS
#
# PYTHON_VERSION: Either 2 or 3, for version 2/3 of the Python interpreter.
# PYLINT_ARGS: Argument to pass on to pylint: flags, module paths, etc.
python_interpreter="python${1}"
pylint_args="-f colorized ${@:2}"
pylint_import=$(cat << PYTHON
import sys
import pkg_resources
__requires__ = "pylint"
sys.exit(
pkg_resources.load_entry_point("pylint", "console_scripts", "pylint")()
)
PYTHON
)
$python_interpreter -c "$pylint_import" $pylint_args
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment