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

Update linter and add auto-formatter config #1314

Merged
merged 7 commits into from
Mar 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ tests/htmlcov/*
.python-version
*~
*.tmp
.pre-commit-config.yaml

# Debian generated files
debian/.debhelper/*
Expand Down
24 changes: 22 additions & 2 deletions docs/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ Note: Development of TUF occurs on the "develop" branch of this repository.

Contributions can be made by submitting GitHub pull requests. Submitted code
should follow our `code style guidelines
<https://github.com/secure-systems-lab/code-style-guidelines>`_, which provide
examples of what to do (or not to do) when writing Python code.
<https://github.com/secure-systems-lab/code-style-guidelines>`_, which are
enforced with linters and auto-formatters (details below).

Contributors must also indicate acceptance of the `Developer Certificate of
Origin <https://developercertificate.org/>`_ (DCO) when making a contribution
Expand Down Expand Up @@ -105,6 +105,26 @@ To work on the TUF project, it's best to perform a development install.
$ pip install -r requirements-dev.txt


Auto-formatting
===============

CI/CD will check that new TUF code is formatted with `black
<https://black.readthedocs.io/>`__ and `isort <https://pycqa.github.io/isort>`__.
Auto-formatting can be done on the command line:
::

$ # TODO: configure black and isort args in pyproject.toml (see #1161)
$ black --line-length 80 tuf/api
$ isort --line-length 80 --profile black -p tuf tuf/api

or via source code editor plugin
[`black <https://black.readthedocs.io/en/stable/editor_integration.html>`__,
`isort <https://github.com/pycqa/isort/wiki/isort-Plugins>`__] or
`pre-commit <https://pre-commit.com/>`__-powered git hooks
[`black <https://black.readthedocs.io/en/stable/version_control_integration.html>`__,
`isort <https://pycqa.github.io/isort/docs/configuration/pre-commit/>`__].


Testing
=======

Expand Down
2 changes: 2 additions & 0 deletions docs/GOVERNANCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ undergo review and automated testing, including, but not limited to:
[Tox](https://tox.readthedocs.io/en/latest/).
* Static code analysis via [Pylint](https://www.pylint.org/) and
[Bandit](https://wiki.openstack.org/wiki/Security/Projects/Bandit).
- Auto-formatting with [black](https://black.readthedocs.io/) and
[isort](https://pycqa.github.io/isort/).
* Checks for Signed-off-by commits via [Probot: DCO](https://github.com/probot/dco).
* Review by one or more
[maintainers](MAINTAINERS.txt).
Expand Down
2 changes: 2 additions & 0 deletions requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ python-dateutil

# additional test tools for linting and coverage measurement
coverage
black
isort
pylint
bandit
9 changes: 7 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,14 @@ commands =

[testenv:lint]
commands =
# Use different pylint configs for legacy and new (tuf/api) code
# Use different configs for new (tuf/api/*) and legacy code
# TODO: configure black and isort args in pyproject.toml (see #1161)
black --check --diff --line-length 80 {toxinidir}/tuf/api
isort --check --diff --line-length 80 --profile black -p tuf {toxinidir}/tuf/api
pylint {toxinidir}/tuf/api --rcfile={toxinidir}/tuf/api/pylintrc

# NOTE: Contrary to what the pylint docs suggest, ignoring full paths does
# work, unfortunately each subdirectory has to be ignored explicitly.
pylint {toxinidir}/tuf --ignore={toxinidir}/tuf/api,{toxinidir}/tuf/api/serialization
pylint {toxinidir}/tuf/api --rcfile={toxinidir}/tuf/api/pylintrc

bandit -r {toxinidir}/tuf
Loading