Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revamp linting processes #7078

Merged
merged 20 commits into from
Sep 25, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .github/workflows/python-linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ jobs:
env:
- TOXENV: docs
- TOXENV: lint
- TOXENV: lint-py2
PYTHON_VERSION: 2.7
- TOXENV: mypy
- TOXENV: packaging
steps:
- uses: actions/checkout@master
Expand Down
38 changes: 38 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
exclude: 'src/pip/_vendor/'

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
hooks:
# - id: check-builtin-literals # TODO: enable when fixed.
- id: check-added-large-files
pradyunsg marked this conversation as resolved.
Show resolved Hide resolved
- id: check-case-conflict
- id: check-toml
- id: check-yaml
- id: debug-statements
# - id: end-of-file-fixer # TODO: enable when fixed.
- id: flake8
exclude: tests/data
- id: forbid-new-submodules
# - id: trailing-whitespace # TODO: enable when fixed.
# exclude: .patch

# TODO: enable when fixed.
# - repo: https://github.com/timothycrosley/isort
# rev: 4.3.21
# hooks:
# - id: isort
# files: \.py$

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.720
hooks:
- id: mypy
exclude: docs|tests

- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.4.1
hooks:
- id: python-no-log-warn
- id: python-no-eval
# - id: rst-backticks # TODO: enable when fixed.
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ jobs:
- stage: primary
env: TOXENV=docs
- env: TOXENV=lint
- env: TOXENV=lint-py2
python: 2.7
- env: TOXENV=mypy
- env: TOXENV=packaging
# Latest CPython
- env: GROUP=1
Expand Down
20 changes: 0 additions & 20 deletions docs/html/development/getting-started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,26 +76,6 @@ To use linters locally, run:
.. code-block:: console

$ tox -e lint
$ tox -e lint-py2

The above commands run the linters on Python 3 followed by Python 2.

.. note::

Do not silence errors from flake8 with ``# noqa`` comments or otherwise.
pradyunsg marked this conversation as resolved.
Show resolved Hide resolved

Running mypy
------------

pip uses :pypi:`mypy` to run static type analysis, which helps catch certain
kinds of bugs. The codebase uses `PEP 484 type-comments`_ due to compatibility
requirements with Python 2.7.

To run the ``mypy`` type checker, run:

.. code-block:: console

$ tox -e mypy

Building Documentation
----------------------
Expand Down
7 changes: 3 additions & 4 deletions tools/travis/run.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#!/bin/bash
set -e

# Short circuit tests and linting jobs if there are no code changes involved.
if [[ $TOXENV != docs ]] && [[ $TOXENV != lint-py2 ]] && [[ $TOXENV != lint ]]; then
# Keep lint and lint-py2, for docs/conf.py
# Short circuit test runs if there are no code changes involved.
if ! [[ $TOXENV ~= ^(docs|lint|packaging)$ ]]; then
if [[ "$TRAVIS_PULL_REQUEST" == "false" ]]
then
echo "This is not a PR -- will do a complete build."
Expand All @@ -18,7 +17,7 @@ if [[ $TOXENV != docs ]] && [[ $TOXENV != lint-py2 ]] && [[ $TOXENV != lint ]];
echo "$changes"
if ! echo "$changes" | grep -qvE '(\.rst$)|(^docs)|(^news)|(^\.github)'
then
echo "Only Documentation was updated -- skipping build."
echo "Code was not changed -- skipping build."
exit
fi
fi
Expand Down
21 changes: 1 addition & 20 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tox]
minversion = 3.4.0
envlist =
docs, packaging, mypy, lint, lint-py2,
docs, packaging, lint,
py27, py35, py36, py37, py38, pypy, pypy3

[helpers]
Expand Down Expand Up @@ -61,22 +61,3 @@ commands_pre =
commands =
flake8
isort --check-only --diff

[testenv:lint-py2]
skip_install = True
basepython = python2
deps = {[lint]deps}
commands_pre =
# No need to flake8 docs, tools & tasks in py2
commands =
flake8 src tests
isort --check-only --diff

[testenv:mypy]
skip_install = True
basepython = python3
deps = -r{toxinidir}/tools/requirements/mypy.txt
commands_pre =
commands =
mypy src
mypy src -2