A static-analysis bot for Github

Overview

Imhotep

Imhotep, the peaceful builder.

Build Status codecov.io Requirements Status

What is it?

Imhotep is a tool which will comment on commits coming into your repository and check for syntactic errors and general lint warnings.

Installation

Currently, installation is done from source through Python packaging system. We first need to download it from GitHub. We then setup a virtualenv which will keep our python packages separate from other things on your system, lest we have version conflicts. Finally, we install the required packages.

virtualenv env
. env/bin/activate
pip install imhotep

If you want to hack on imhotep, that looks more like this:

git clone git://github.com/justinabrahms/imhotep.git
cd imhotep
virtualenv env
. env/bin/activate
pip install -r requirements.txt
pip install -e .

You'll also need to install the plugins you'd like to run. Examples include jshint, flake8, pep8, pylint, rubocop, foodcritic, and jsl. You can install those with pip. Example: pip install imhotep_jshint.

Usage

To use imhotep, we must tell it which repository to look at, who to authenticate as and what to comment on. Imhotep is able to comment in two ways: either on a single commit or on a pull request.

Commenting on a pull request

    imhotep \
       --repo_name="justinabrahms/imhotep" \
       --github-username="your_username" \
       --github-password="a_sha_generated_by_github" \
       --pr-number=1

Commenting on a single commit

    imhotep \
       --repo_name="justinabrahms/imhotep" \
       --github-username="your_username" \
       --github-password="a_sha_generated_by_github" \
       --commit="a123445714cfa89d1e843d9950ea8f249cd6e4df"

Where do I get that SHA?

The SHA generated by github is done through your user's settings page. Generate a personal access token and use that for the --github-password above.

Full Usage Info

usage: imhotep [-h] [--config-file CONFIG_FILE] --repo_name REPO_NAME
               [--commit COMMIT] [--origin-commit ORIGIN_COMMIT]
               [--filenames FILENAMES [FILENAMES ...]] [--debug]
               [--github-username GITHUB_USERNAME]
               [--github-password GITHUB_PASSWORD] [--no-post]
               [--authenticated] [--pr-number PR_NUMBER]
               [--cache-directory CACHE_DIRECTORY] [--report-file-violations]

Posts static analysis results to github.

optional arguments:
  -h, --help            show this help message and exit
  --config-file CONFIG_FILE
                        Configuration file in json.
  --repo_name REPO_NAME
                        Github repository name in owner/repo format
  --commit COMMIT       The sha of the commit to run static analysis on.
  --origin-commit ORIGIN_COMMIT
                        Commit to use as the comparison point.
  --filenames FILENAMES [FILENAMES ...]
                        filenames you want static analysis to be limited to.
  --debug               Will dump debugging output and won't clean up after
                        itself.
  --github-username GITHUB_USERNAME
                        Github user to post comments as.
  --github-password GITHUB_PASSWORD
                        Github password for the above user.
  --no-post             [DEBUG] will print out comments rather than posting to
                        github.
  --authenticated       Indicates the repository requires authentication
  --pr-number PR_NUMBER
                        Number of the pull request to comment on
  --cache-directory CACHE_DIRECTORY
                        Path to directory to cache the repository
  --report-file-violations
                        Report file-level violations, i.e. those not on
                        individual lines

Note: if you get a error where the plugin cannot find imhotep.tools, make sure you installed imhotep into your virtualenv with pip install -e .. See the Installation instructions above.

Linter Support

There is currently support for 2 linters: PyLint and JSHint. If it finds violations, it will post those violations to GitHub. New linting tools are encouraged!

By default, imhotep runs all plugins it can find on your source code. If you'd like to only run a subset of linters, you should specify the --linter directive with a dotted path to the module. An example of this is imhotep.tools:PyLint or imhotep_pep8.plugin:Pep8Linter. If you want to specify multiple tools, just pass multiple things to the --linter flag.

Writing Plugins

Imhotep supports adding linters through a plugin API based around Python's setuptools entrypoints. This means that plugins can live as separate Python packages which are installable alongside imhotep.

To write your own tool, subclass the Tool class and override the process_line, get_file_extensions, and get_command methods. If you need greater control over how the tool is run, you can override the invoke method which gives you maximal control over how the tools are run.

To make your plugin discoverable, you need to add an entry_points stanza to your setup.py. It looks like this.

setup(
  # ...
  entry_points={
    'imhotep_linter': [
      '.py = path.to.module:ToolClassName'
    ]
  }
  # ...
)

The key pieces of this are the name of the entrypoint which must be imhotep_linter. This is how we know where to find the plugins. The list that follows it is a list of strings that map file extensions to a tool that knows how to lint them. So for the entry above, we'll do something like from path.to.module import ToolClassName and run that on all .py files in the repository.

You can find a working example of a setup.py file in the imhotep_pep8 repository.

What's with the name?

Imhotep, the first Egyptian architect, is known as "the one who comes in peace". In keeping with that name, the goal of this tool is to keep code reviews peaceful and productive by having robots point out the nitpicky details, leaving people to critique bigger picture things, not spacing and misspelling issues.

Release Notes

1.1.1

Bugfixes:

  • Improved discovery of build tools

1.1.0

This is the first release where I'm tracking release notes. This release is majoritively the work of danpalmer. Thanks, Dan!

Features:

  • Support for file level violations

Backwards incompatible change:

  • The printer reporter was broken, not using the correct interface for reporting individual lines. I've chosen to not bump the major version, because this change was to get something to work. Any work built on top of this class would have not be operational code, so I'm not worried about breaking someone.

Bugfixes:

  • Different reporters that report errors on the same line don't clobber each other.
  • File extensions are properly filtered before reporting.
Owner
Justin Abrahms
Justin Abrahms
Flake8 extension for enforcing trailing commas in python

Flake8 Extension to enforce better comma placement. Usage If you are using flake8 it's as easy as: pip install flake8-commas Now you can avoid those a

Python Code Quality Authority 127 Sep 03, 2022
:sparkles: Surface lint errors during code review

✨ Linty Fresh ✨ Keep your codebase sparkly clean with the power of LINT! Linty Fresh parses lint errors and report them back to GitHub as comments on

Lyft 183 Dec 18, 2022
Reference implementation of sentinels for the Python stdlib

Sentinels This is a reference implementation of a utility for the definition of sentinel values in Python. This also includes a draft PEP for the incl

Tal Einat 22 Aug 27, 2022
flake8 plugin that integrates isort

Flake8 meet isort Use isort to check if the imports on your python files are sorted the way you expect. Add an .isort.cfg to define how you want your

Gil Forcada Codinachs 139 Nov 08, 2022
Enforce the same configuration across multiple projects

Nitpick Flake8 plugin to enforce the same tool configuration (flake8, isort, mypy, Pylint...) across multiple Python projects. Useful if you maintain

Augusto W. Andreoli 315 Dec 25, 2022
Plugin for mypy to support zope.interface

Plugin for mypy to support zope.interface The goal is to be able to make zope interfaces to be treated as types in mypy sense. Usage Install both mypy

Shoobx 36 Oct 29, 2022
Tool to check the completeness of MANIFEST.in for Python packages

check-manifest Are you a Python developer? Have you uploaded packages to the Python Package Index? Have you accidentally uploaded broken packages with

Marius Gedminas 270 Dec 26, 2022
Optional static typing for Python 3 and 2 (PEP 484)

Mypy: Optional Static Typing for Python Got a question? Join us on Gitter! We don't have a mailing list; but we are always happy to answer questions o

Python 14.4k Jan 08, 2023
A simple plugin that allows running mypy from PyCharm and navigate between errors

mypy-PyCharm-plugin The plugin provides a simple terminal to run fast mypy daemon from PyCharm with a single click or hotkey and easily navigate throu

Dropbox 301 Dec 09, 2022
Flake8 wrapper to make it nice, legacy-friendly, configurable.

THE PROJECT IS ARCHIVED Forks: https://github.com/orsinium/forks It's a Flake8 wrapper to make it cool. Lint md, rst, ipynb, and more. Shareable and r

Life4 232 Dec 16, 2022
Tool for automatically reordering python imports. Similar to isort but uses static analysis more.

reorder_python_imports Tool for automatically reordering python imports. Similar to isort but uses static analysis more. Installation pip install reor

Anthony Sottile 589 Dec 26, 2022
The official GitHub mirror of https://gitlab.com/pycqa/flake8

Flake8 Flake8 is a wrapper around these tools: PyFlakes pycodestyle Ned Batchelder's McCabe script Flake8 runs all the tools by launching the single f

Python Code Quality Authority 2.6k Jan 03, 2023
flake8 plugin which checks that typing imports are properly guarded

flake8-typing-imports flake8 plugin which checks that typing imports are properly guarded installation pip install flake8-typing-imports flake8 codes

Anthony Sottile 50 Nov 01, 2022
Pymxs, the 3DsMax bindings of Maxscript to Python doesn't come with any stubs

PyMXS Stubs generator What Pymxs, the 3DsMax bindings of Maxscript to Python doe

Frieder Erdmann 19 Dec 27, 2022
An extension for flake8 that forbids some imports statements in some modules.

flake8-obey-import-goat An extension for flake8 that forbids some imports statements in some modules. Important: this project is developed using DDD,

Ilya Lebedev 10 Nov 09, 2022
Flake8 plugin for managing type-checking imports & forward references

flake8-type-checking Lets you know which imports to put in type-checking blocks. For the imports you've already defined inside type-checking blocks, i

snok 67 Dec 16, 2022
Collection of awesome Python types, stubs, plugins, and tools to work with them.

Awesome Python Typing Collection of awesome Python types, stubs, plugins, and tools to work with them. Contents Static type checkers Dynamic type chec

TypedDjango 1.2k Jan 04, 2023
Easy saving and switching between multiple KDE configurations.

Konfsave Konfsave is a config manager. That is, it allows you to save, back up, and easily switch between different (per-user) system configurations.

42 Sep 25, 2022
Flake8 plugin that checks import order against various Python Style Guides

flake8-import-order A flake8 and Pylama plugin that checks the ordering of your imports. It does not check anything else about the imports. Merely tha

Python Code Quality Authority 270 Nov 24, 2022
Tool for pinpointing circular imports in Python. Find cyclic imports in any project

Pycycle: Find and fix circular imports in python projects Pycycle is an experimental project that aims to help python developers fix their circular de

Vadim Kravcenko 311 Dec 15, 2022