Skip to content

Commit

Permalink
Trac #34425: configure vscode pycodestyle linter
Browse files Browse the repository at this point in the history
The goal of this ticket is to configure the vscode pycodestyle linter to
check against Sage's minimal style conventions:
    * E111: indentation is not a multiple of four
    * E306: expected 1 blank line before a nested definition, found 0
    * E401: multiple imports on one line
    * E701: multiple statements on one line (colon)
    * E702: multiple statements on one line (semicolon)
    * E703: statement ends with a semicolon
    * E711: comparison to None should be ‘if cond is None:’
    * E712: comparison to True should be ‘if cond is True:’ or ‘if
cond:’
    * E713: test for membership should be 'not in'
    * E721: do not compare types, use isinstance()
    * E722: do not use bare except, specify exception instead
    * W605: invalid escape sequence ‘x’

See https://pycodestyle.pycqa.org/en/latest/intro.html#error-codes

URL: https://trac.sagemath.org/34425
Reported by: gh-DavidAyotte
Ticket author(s): David Ayotte
Reviewer(s): Matthias Koeppe
  • Loading branch information
Release Manager committed Aug 30, 2022
2 parents 523695c + 14b7780 commit 0a1d3ed
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
// This settings file is not ignored by git. It should be kept in sync with
// the trac repo.
"python.defaultInterpreterPath": "./venv/bin/python3",
"files.exclude": {
"**/__pycache__": true,
Expand All @@ -23,6 +25,9 @@
"python.testing.unittestEnabled": false,
"python.linting.pycodestyleEnabled": true,
"python.linting.enabled": true,
// The following pycodestyle arguments are the same as the pycodestyle-minimal
// tox environnment, see the file SAGE_ROOT/src/tox.ini
"python.linting.pycodestyleArgs": ["--select=E111,E306,E401,E701,E702,E703,W605,E711,E712,E713,E721,E722"],
"cSpell.words": [
"furo",
"Conda",
Expand Down
7 changes: 6 additions & 1 deletion src/doc/en/developer/tools.rst
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,12 @@ or a few related issues::

- Manual: Run ``pycodestyle path/to/the/file.py``.

- VS Code: Activate by adding the setting ``"python.linting.pycodestyleEnabled": true``, see `official VS Code documentation <https://code.visualstudio.com/docs/python/linting>`__ for details.
- VS Code: The minimal version of pycodestyle is activated by default in
``SAGE_ROOT/.vscode/settings.json`` (the corresponding setting is
``"python.linting.pycodestyleEnabled": true``). Note that the
``settings.json`` file is not ignored by git so be aware to keep it in sync
with the trac repo. For further details, see the
`official VS Code documentation <https://code.visualstudio.com/docs/python/linting>`__.

*Configuration:* ``[pycodestyle]`` block in ``SAGE_ROOT/src/tox.ini``

Expand Down
2 changes: 2 additions & 0 deletions src/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ deps = pycodestyle
commands = pycodestyle {posargs:{toxinidir}/sage/}

[testenv:pycodestyle-minimal]
## Note that the the pycodestyle linter provided by vscode checks against the
## same minimal conventions as defined below, see the file SAGE_ROOT/.vscode/settings.json.
description =
check against Sage's minimal style conventions
# Check for the following issues:
Expand Down

0 comments on commit 0a1d3ed

Please sign in to comment.