Skip to content

Commit

Permalink
style(lint): replace pylint with ruff (#675)
Browse files Browse the repository at this point in the history
* style(lint): autofix ruff 0.6 linting errors

* style(lint): autofix ruff 0.6 linting errors (unsafe)

This was done with `ruff check --fix --unsafe-fixes`

* style(lint): manually fix ruff 0.6 linting errors

* fix(lint): silence ruff in one case

* build(lint): replace pylint with ruff

* ci: replace pylint with ruff

* style(lint): bring some ruff config from starbase

* chore(lint): fixes for updated ruff config

* pr comments

* build(deps): update dev and doc dependencies
  • Loading branch information
lengau authored Aug 27, 2024
1 parent f1f82c4 commit b7d7059
Show file tree
Hide file tree
Showing 31 changed files with 193 additions and 170 deletions.
17 changes: 11 additions & 6 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ jobs:
submodules: true
- name: Install packages
run: |
sudo snap install --no-wait ruff
sudo snap install --no-wait shellcheck
sudo snap install --no-wait woke
sudo snap install --no-wait --classic node
sudo snap install --no-wait --classic pyright
sudo apt update
sudo apt install -y libapt-pkg-dev aspell aspell-en
- name: Set up Python 3.10
Expand Down Expand Up @@ -44,22 +49,22 @@ jobs:
make test-pydocstyle
- name: Run pyright
run: |
sudo snap install --classic node
sudo snap install --classic pyright
sudo snap watch --last=install
make test-pyright
- name: Run pylint
- name: Run ruff
run: |
make test-pylint
sudo snap watch --last=install
make test-ruff
- name: Run sphinx-lint
run: |
make test-sphinx-lint
- name: Run shellcheck
run: |
sudo snap install shellcheck
sudo snap watch --last=install
make test-shellcheck
- name: Run linkcheck,woke,spelling
run: |
sudo snap install woke
sudo snap watch --last=install
make test-docs
tests:
Expand Down
16 changes: 12 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
RUFF := $(shell ruff --version 2> /dev/null)

.PHONY: help
help: ## Show this help.
@printf "%-40s %s\n" "Target" "Description"
Expand All @@ -6,6 +8,9 @@ help: ## Show this help.

.PHONY: autoformat
autoformat: ## Run automatic code formatters.
ifndef RUFF
$(error "Ruff not installed. Install it with `sudo snap install ruff` or using the official installation instructions: https://docs.astral.sh/ruff/installation/")
endif
autoflake rockcraft/ tests/
black .
ruff check --fix-only rockcraft tests
Expand Down Expand Up @@ -69,7 +74,7 @@ install: clean ## Install python package.
python setup.py install

.PHONY: lint
lint: test-black test-codespell test-flake8 test-mypy test-pydocstyle test-pyright test-pylint test-sphinx-lint test-shellcheck ## Run all linting tests.
lint: test-black test-codespell test-flake8 test-mypy test-pydocstyle test-pyright test-ruff test-sphinx-lint test-shellcheck ## Run all linting tests.

.PHONY: release
release: dist ## Release with twine.
Expand All @@ -89,7 +94,10 @@ test-flake8:

.PHONY: test-ruff
test-ruff:
ruff rockcraft tests
ifndef RUFF
$(error "Ruff not installed. Install it with `sudo snap install ruff` or using the official installation instructions: https://docs.astral.sh/ruff/installation/")
endif
ruff check rockcraft tests

.PHONY: test-integrations
test-integrations: ## Run integration tests.
Expand All @@ -105,8 +113,8 @@ test-pydocstyle:

.PHONY: test-pylint
test-pylint:
pylint rockcraft
pylint tests --disable=invalid-name,missing-module-docstring,missing-function-docstring,redefined-outer-name,too-many-arguments,too-many-public-methods,no-member,import-outside-toplevel
echo "rockcraft has replaced pylint with ruff. Please use `make test-ruff` instead."
make test-ruff

.PHONY: test-pyright
test-pyright:
Expand Down
2 changes: 2 additions & 0 deletions extensions/django-framework/gunicorn.conf.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""gunicorn configuration."""

bind = ["0.0.0.0:8000"]
chdir = "/django/app"
statsd_host = "localhost:9125"
2 changes: 2 additions & 0 deletions extensions/flask-framework/gunicorn.conf.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""gunicorn configuration."""

bind = ["0.0.0.0:8000"]
chdir = "/flask/app"
statsd_host = "localhost:9125"
34 changes: 28 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ extend-exclude = [
"rockcraft/_version.py"
]
# Follow ST063 - Maintaining and updating linting specifications for updating these.
select = [ # Base linting rule selections.
lint.select = [ # Base linting rule selections.
# See the internal document for discussion:
# https://docs.google.com/document/d/1i1n8pDmFmWi4wTDpk-JfnWCVUThPJiggyPi2DYwBBu4/edit
# All sections here are stable in ruff and shouldn't randomly introduce
Expand All @@ -124,7 +124,7 @@ select = [ # Base linting rule selections.
"RET", # Simpler logic after return, raise, continue or break
"UP018", "C408", # Convert type calls to literals. The latest pylint enforces this, but ruff has auto-fixes.
]
extend-select = [
lint.extend-select = [
# These sets are still frequently getting new rules.
# Therefore, they're getting frozen with the current rules so we can
# upgrade ruff without breaking linting.
Expand All @@ -150,7 +150,7 @@ extend-select = [
"RUF005", # Encourages unpacking rather than concatenation
"RUF100", # #noqa directive that doesn't flag anything.
]
ignore = [
lint.ignore = [
#"E203", # Whitespace before ":" -- Commented because ruff doesn't currently check E203
"E501", # Line too long (reason: black will automatically fix this for us)
"D105", # Missing docstring in magic method (reason: magic methods already have definitions)
Expand All @@ -162,14 +162,36 @@ ignore = [

]

[tool.ruff.per-file-ignores]
[tool.ruff.lint.flake8-annotations]
allow-star-arg-any = true

[tool.ruff.lint.pydocstyle]
ignore-decorators = [ # Functions with these decorators don't have to have docstrings.
"typing.overload", # Default configuration
# The next four are all variations on override, so child classes don't have to repeat parent classes' docstrings.
"overrides.override",
"overrides.overrides",
"typing.override",
"typing_extensions.override",
]

[tool.ruff.lint.pylint]
max-args = 8

[tool.ruff.lint.pep8-naming]
# Allow Pydantic's `@validator` decorator to trigger class method treatment.
classmethod-decorators = ["pydantic.validator", "pydantic.root_validator"]

[tool.ruff.lint. per-file-ignores]
"tests/**.py" = [ # Some things we want for the moin project are unnecessary in tests.
"D", # Ignore docstring rules in tests
"ANN", # Ignore type annotations in tests
"S101", # Allow assertions in tests
"S103", # Allow `os.chmod` setting a permissive mask `0o555` on file or directory
"S108", # Allow Probable insecure usage of temporary file or directory
"S103", # Allow `os.chmod` setting a permissive mask `0o555` on file or directory
"S105", # Allow (fake) secrets in tests.
"S108", # Allow Probable insecure usage of temporary file or directory
"PLR0913", # Allow many arguments for test functions
"PLR2004", # Allow magic values in tests
]
# isort leaves init files alone by default, this makes ruff ignore them too.
"__init__.py" = ["I001"]
Expand Down
87 changes: 39 additions & 48 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@ annotated-types==0.7.0
anyio==4.4.0
apeye==1.4.1
apeye-core==1.1.5
astroid==3.2.4
autodocsumm==0.2.13
autoflake==1.7.8
babel==2.16.0
backports.tarfile==1.2.0
beautifulsoup4==4.12.3
black==24.8.0
boolean.py==4.0
boolean-py==4.0
bracex==2.5
CacheControl==0.14.0
cachetools==5.4.0
cachecontrol==0.14.0
cachetools==5.5.0
canonical-sphinx==0.1.0
canonical-sphinx-extensions==0.0.23
certifi==2024.7.4
Expand All @@ -33,46 +31,43 @@ craft-providers==2.0.0
cryptography==43.0.0
cssutils==2.11.1
dict2css==0.3.0.post1
dill==0.3.8
distlib==0.3.8
distro==1.9.0
docutils==0.21.2
domdf-python-tools==3.9.0
exceptiongroup==1.2.2
filelock==3.15.4
flake8==4.0.1
furo==2024.8.6
gitdb==4.0.11
GitPython==3.1.43
gitpython==3.1.43
h11==0.14.0
html5lib==1.1
httplib2==0.22.0
idna==3.7
imagesize==1.4.1
importlib_metadata==8.2.0
importlib-metadata==8.2.0
iniconfig==2.0.0
isort==5.13.2
jaraco.classes==3.4.0
jaraco.context==5.3.0
jaraco.functools==4.0.2
jaraco-classes==3.4.0
jaraco-context==6.0.1
jaraco-functools==4.0.2
jeepney==0.8.0
Jinja2==3.1.4
jinja2==3.1.4
keyring==25.3.0
launchpadlib==2.0.0
lazr.restfulclient==0.14.6
lazr.uri==1.0.6
lazr-restfulclient==0.14.6
lazr-uri==1.0.6
license-expression==30.3.0
linkify-it-py==2.0.3
lxml==5.2.2
Markdown==3.6
lxml==5.3.0
markdown==3.7
markdown-it-py==3.0.0
MarkupSafe==2.1.5
markupsafe==2.1.5
mccabe==0.6.1
mdit-py-plugins==0.4.1
mdurl==0.1.2
more-itertools==10.4.0
msgpack==1.0.8
mypy==1.11.1
mypy==1.11.2
mypy-extensions==1.0.0
myst-parser==4.0.0
natsort==8.4.0
Expand All @@ -88,56 +83,53 @@ polib==1.2.0
pycodestyle==2.8.0
pycparser==2.22
pydantic==2.8.2
pydantic_core==2.20.1
pydantic_yaml==1.3.0
pydantic-core==2.20.1
pydantic-yaml==1.3.0
pydocstyle==6.3.0
pyflakes==2.4.0
pygit2==1.14.1
Pygments==2.18.0
pylint==3.2.6
pylint-fixme-info==1.0.4
pylint-pytest==1.1.8
pygments==2.18.0
pyparsing==3.1.2
pyproject-api==1.7.1
pyspelling==2.10
pytest==8.2.0
pytest-check==2.3.1
pytest==8.3.2
pytest-check==2.4.0
pytest-mock==3.14.0
pytest-subprocess==1.5.2
pyxdg==0.28
PyYAML==6.0.2
readme_renderer==44.0
pyyaml==6.0.2
readme-renderer==44.0
regex==2024.7.24
requests==2.31.0
requests-toolbelt==1.0.0
requests-unixsocket==0.3.0
rfc3986==2.0.0
rich==13.7.1
ruamel.yaml==0.18.6
ruamel.yaml.clib==0.2.8
ruff==0.3.5
SecretStorage==3.3.3
rich==13.8.0
ruamel-yaml==0.18.6
ruamel-yaml-clib==0.2.8
secretstorage==3.3.3
setuptools==74.0.0
six==1.16.0
smmap==5.0.1
snap-helpers==0.4.2
sniffio==1.3.1
snowballstemmer==2.2.0
soupsieve==2.5
soupsieve==2.6
spdx==2.5.1
spdx-lookup==0.3.3
Sphinx==7.4.7
sphinx==7.4.7
sphinx-autobuild==2024.4.16
sphinx-autodoc-typehints==2.2.3
sphinx-basic-ng==1.0.0b2
sphinx-copybutton==0.5.2
sphinx-design==0.6.1
sphinx-jinja2-compat==0.3.0
sphinx-lint==0.9.1
sphinx-notfound-page==1.0.4
sphinx-prompt==1.8.0
sphinx-reredirects==0.1.5
sphinx-tabs==3.4.5
sphinx-toolbox==3.7.0
sphinx_design==0.6.1
sphinx_reredirects==0.1.5
sphinx-toolbox==3.8.0
sphinxcontrib-applehelp==2.0.0
sphinxcontrib-details-directive==0.1.0
sphinxcontrib-devhelp==2.0.0
Expand All @@ -149,23 +141,22 @@ sphinxcontrib-serializinghtml==2.0.0
sphinxext-opengraph==0.9.1
starlette==0.38.2
tabulate==0.9.0
tomli==2.0.1
tomlkit==0.13.0
tox==4.17.1
tox==4.18.0
twine==5.1.1
types-PyYAML==6.0.12.20240808
types-pyyaml==6.0.12.20240808
types-requests==2.31.0.6
types-setuptools==71.1.0.20240806
types-setuptools==73.0.0.20240822
types-tabulate==0.9.0.20240106
types-urllib3==1.26.25.14
typing_extensions==4.12.2
typing-extensions==4.12.2
uc-micro-py==1.0.3
urllib3==1.26.19
uvicorn==0.30.5
uvicorn==0.30.6
virtualenv==20.26.3
wadllib==1.3.6
watchfiles==0.23.0
wcmatch==9.0
webencodings==0.5.1
websockets==12.0
websockets==13.0
wheel==0.44.0
zipp==3.19.2
Loading

0 comments on commit b7d7059

Please sign in to comment.