Skip to content

Commit

Permalink
document and run pre-commit with tox
Browse files Browse the repository at this point in the history
  • Loading branch information
graingert committed Oct 22, 2020
1 parent 55631fc commit 1120d9d
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Please note that the trac ticket, news fragment, and review submission portions
## Contributor Checklist:

* [ ] The associated ticket in Trac is here: https://twistedmatrix.com/trac/ticket/<!-- Create a new one at https://twistedmatrix.com/trac/newticket and replace this comment with the ticket number. -->
* [ ] I ran `tox -e black-reformat` to format my patch to meet the [Twisted Coding Standard](https://twistedmatrix.com/documents/current/core/development/policy/coding-standard.html)
* [ ] I ran `tox -e lint` to format my patch to meet the [Twisted Coding Standard](https://twistedmatrix.com/documents/current/core/development/policy/coding-standard.html)
* [ ] I ran additional checks listed at [Getting Your Patch Accepted](https://twistedmatrix.com/trac/wiki/TwistedDevelopment#GettingYourPatchAccepted)
* [ ] I have created a newsfragment in src/twisted/newsfragments/ (see: [News files](https://twistedmatrix.com/trac/wiki/ReviewProcess#Newsfiles))
* [ ] I have updated the automated tests.
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
lint:
runs-on: ubuntu-20.04
env:
TOXENV: "lint,black,twine"
TOXENV: "lint,twine"

steps:
- uses: actions/checkout@v2
Expand Down
11 changes: 3 additions & 8 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,12 @@ Static Code Checkers

You can ensure that code complies to Twisted `coding standards <https://twistedmatrix.com/documents/current/core/development/policy/coding-standard.html>`_::

$ tox -e lint # run pyflakes to check syntax
$ tox -e black # run Black to check against coding standard
$ tox -e lint # run pre-commit to check coding stanards
$ tox -e mypy # run MyPy static type checker to check for type errors

To automatically format code according to the coding standards::
Or, for speed, use pre-commit directly::

$ tox -e black-reformat

Or, for speed, specify exactly what to format::

$ tox -e black-reformat -- path/to/file.py
$ pipx run pre-commit run


Copyright
Expand Down
6 changes: 3 additions & 3 deletions docs/core/development/policy/coding-standard.rst
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ This entire source tree can be reformatted by running:

.. code-block:: console
tox -e black-reformat
tox -e lint
A single file can be reformatted by running:
Only changed files can be reformatted by running:

.. code-block:: console
tox -e black-reformat -- path/to/file.py
pipx run pre-commit run
Modules
Expand Down
18 changes: 3 additions & 15 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ requires=
virtualenv>=20.0.35
tox-wheel>=0.5.0
skip_missing_interpreters=True
envlist=lint, mypy, black,
envlist=lint, mypy,
apidocs, narrativedocs, newsfragment,
manifest-checker, twine,
py38-alldeps-nocov
Expand Down Expand Up @@ -81,9 +81,7 @@ deps =

twine: twine

lint: pyflakes

black: black==20.8b1
lint: pre-commit

wheels: cibuildwheel==1.6.1

Expand All @@ -98,8 +96,6 @@ setenv =
# Help tests know where the base directory is.
TOX_INI_DIR = {toxinidir}

black: BLACK_LINT_ARGS=--check

; Configure cibuildwheel to build wheels for:
; CPython 3.5, 3.6, 3.7 and 3.8.
; This includes variants of bit depth, unicode width, etc.
Expand All @@ -113,7 +109,6 @@ skip_install =
codecov: True
coveralls: True
lint: True
black: True
manifest-checker: True

commands =
Expand Down Expand Up @@ -146,9 +141,7 @@ commands =
; Build in a root folder so that buildbot can pick the result
wheel: python -m pip wheel {toxinidir} --no-deps --use-pep517 --wheel-dir {toxinidir}/dist

lint: /bin/sh -c "pyflakes $(find {[default]sources} -name '*.py')"

black: black {env:BLACK_LINT_ARGS} {posargs:{[default]sources}}
lint: pre-commit {posargs:run --all-files --show-diff-on-failure}

apidocs: {toxinidir}/bin/admin/build-apidocs {toxinidir}/src/ apidocs
narrativedocs: sphinx-build -aW -b html -d {toxinidir}/docs/_build {toxinidir}/docs {toxinidir}/docs/_build/
Expand All @@ -166,11 +159,6 @@ commands =
[testenv:apidocs]
deps=https://github.com/twisted/pydoctor/archive/3f9c64829dfa040b334c9ae27c332c7078356e79.zip

[testenv:black-reformat]
setenv =
; Clear the --check flag
BLACK_LINT_ARGS=

[testenv:mypy]

description = run Mypy (static type checker)
Expand Down

0 comments on commit 1120d9d

Please sign in to comment.