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

Replace black and pylint with ruff #3333

Open
wants to merge 13 commits into
base: develop
Choose a base branch
from
Open
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
33 changes: 1 addition & 32 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,6 @@ jobs:
paths:
- .venv
- integreat_cms.egg-info
black:
docker:
- image: cimg/python:3.11.7
resource_class: small
steps:
- checkout
- attach_workspace:
at: .
- run:
name: Enable virtual environment
command: echo "source .venv/bin/activate" >> $BASH_ENV
- run:
name: Check black code style
command: black --check .
djlint:
docker:
- image: cimg/python:3.11.7
Expand All @@ -61,17 +47,6 @@ jobs:
- run:
name: Check formatting of Django templates
command: djlint --check --lint integreat_cms
pylint:
docker:
- image: cimg/python:3.11.7
resource_class: small
steps:
- checkout
- attach_workspace:
at: .
- run:
name: Run pylint
command: ./tools/pylint.sh
ruff:
docker:
- image: cimg/python:3.11.7
Expand All @@ -87,7 +62,7 @@ jobs:
name: Run ruff
command: |
ruff check
# ruff format
charludo marked this conversation as resolved.
Show resolved Hide resolved
ruff format --check
mypy:
docker:
- image: cimg/python:3.11.7
Expand Down Expand Up @@ -668,15 +643,9 @@ workflows:
- /.*-publish-dev-package/
requires:
- build-dev-package
- black:
requires:
- pip-install
- djlint:
requires:
- pip-install
- pylint:
requires:
- pip-install
- ruff:
requires:
- pip-install
Expand Down
22 changes: 17 additions & 5 deletions .circleci/scripts/create_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,33 @@ def main() -> None:
# Parse command line arguments
parser = argparse.ArgumentParser(description="Create GitHub release")
parser.add_argument(
"-p", "--prerelease", action="store_true", help="mark the release as prerelease"
"-p",
"--prerelease",
action="store_true",
help="mark the release as prerelease",
)
parser.add_argument("token", metavar="TOKEN", help="GitHub API token")
parser.add_argument("tag", metavar="TAG", help="tag for the release")
parser.add_argument(
"prev_tag", metavar="PREV_TAG", help="the previous tag of the release"
"prev_tag",
metavar="PREV_TAG",
help="the previous tag of the release",
)
parser.add_argument(
"changelog", metavar="CHANGELOG", help="changelog of the release"
"changelog",
metavar="CHANGELOG",
help="changelog of the release",
)
parser.add_argument(
"contributors", metavar="CONTRIBUTORS", help="contributors of the release"
"contributors",
metavar="CONTRIBUTORS",
help="contributors of the release",
)
parser.add_argument(
"assets", metavar="ASSET", help="uploadable asset file", nargs="*"
"assets",
metavar="ASSET",
help="uploadable asset file",
nargs="*",
)
args = parser.parse_args()

Expand Down
6 changes: 4 additions & 2 deletions .circleci/scripts/get_access_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def main() -> None:
deliverino_private_key = os.environ["DELIVERINO_PRIVATE_KEY"]
except KeyError as e:
raise RuntimeError(
"Please make sure this step has access to the 'deliverino' CircleCI context."
"Please make sure this step has access to the 'deliverino' CircleCI context.",
) from e

# Generate payload for the JWT
Expand All @@ -39,7 +39,9 @@ def main() -> None:

# Sign payload and encode JWT
encoded_jwt = jwt.encode(
payload, b64decode(deliverino_private_key), algorithm="RS256"
payload,
b64decode(deliverino_private_key),
algorithm="RS256",
)

# Request access token
Expand Down
8 changes: 6 additions & 2 deletions .circleci/scripts/get_contributors.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,17 @@ def parse_args() -> argparse.Namespace:

# Parse command line arguments
parser = argparse.ArgumentParser(
description="Get contributors between two given git references"
description="Get contributors between two given git references",
)
parser.add_argument("token", metavar="TOKEN", help="GitHub API token")
parser.add_argument("base", metavar="BASE", help="the base branch/tag/commit")
parser.add_argument("head", metavar="HEAD", help="the head branch/tag/commit")
parser.add_argument(
"-v", "--verbose", action="count", default=0, help="increase logging verbosity"
"-v",
"--verbose",
action="count",
default=0,
help="increase logging verbosity",
)
args: argparse.Namespace = parser.parse_args()

Expand Down
21 changes: 1 addition & 20 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,14 @@ repos:
- id: ruff
name: ruff (custom script)
entry: ./tools/ruff.sh
args: ["--as-precommit"]
types_or: ["python", "pyi"]
args: ["--as-precommit", "."]
language: script
pass_filenames: false
- repo: https://github.com/shellcheck-py/shellcheck-py
rev: v0.10.0.1
hooks:
- id: shellcheck
args: [--external-sources]
- repo: local
charludo marked this conversation as resolved.
Show resolved Hide resolved
hooks:
- id: black
name: black (custom script)
entry: ./tools/black.sh
args: ["--as-precommit"]
types_or: ["python", "pyi"]
language: script
pass_filenames: true
- repo: local
hooks:
- id: djlint-django
Expand Down Expand Up @@ -92,12 +82,3 @@ repos:
types_or: ["python", "pyi"]
language: script
pass_filenames: true
- repo: local
hooks:
- id: pylint
name: pylint (custom script)
entry: ./tools/pylint.sh
args: ["--as-precommit"]
types_or: ["python", "pyi"]
language: script
pass_filenames: true
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
build/**
webpack-stats.json
.mypy_cache/**
.ruff_cache/**
charludo marked this conversation as resolved.
Show resolved Hide resolved
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
[![CircleCI](https://circleci.com/gh/digitalfabrik/integreat-cms.svg?style=shield)](https://circleci.com/gh/digitalfabrik/integreat-cms)
[![Pylint](https://img.shields.io/badge/pylint-10.00-brightgreen)](https://www.pylint.org/)
[![Ruff](https://img.shields.io/badge/ruff-0.9.2-brightgreen)](https://docs.astral.sh/ruff/)
![Coverage](https://img.shields.io/codeclimate/coverage/digitalfabrik/integreat-cms)
[![PyPi](https://img.shields.io/pypi/v/integreat-cms.svg)](https://pypi.org/project/integreat-cms/)
[![Release Notes](https://img.shields.io/badge/%F0%9F%93%9C-release%20notes-blue)](https://digitalfabrik.github.io/integreat-cms/release-notes.html)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

# Integreat Django CMS

Expand Down Expand Up @@ -93,7 +92,7 @@ and then start your code editor (`code .`, `nvim`,...) from within that same she
On MacOS, installing `libmagic` separately through `brew install libmagic` might be required.

### CMS configuration file
After setup you will be able to run the cms with most of it's functionality. In order to use a couple of features like translations or the HIX value, you need to set some settings which can be defined in a configuration file. It should be located at `/etc/integreat-cms.ini`. If you want to place the file at a different location, pass the absolute path via the environment variable `INTEGREAT_CMS_CONFIG`. An example file is located at `example-configs` in the project folder.
After setup you will be able to run the cms with most of it's functionality. In order to use a couple of features like translations or the HIX value, you need to set some settings which can be defined in a configuration file. It should be located at `/etc/integreat-cms.ini`. If you want to place the file at a different location, pass the absolute path via the environment variable `INTEGREAT_CMS_CONFIG`. An example file is located at `example-configs` in the project folder.
All these settings can also be configured via environment variables with the prefix `INTEGREAT_CMS_`, e.g. `INTEGREAT_CMS_SECRET_KEY`.

#### Using a CMS configuration file with devcontainer
Expand Down
53 changes: 15 additions & 38 deletions docs/src/code-style.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@
Code Style Guidelines
*********************

.. _ruff:

.. _black-code-style:

Black
-----
Ruff
------

We use the `black <https://github.com/psf/black>`_ coding style, a flavour of `PEP-8 <https://www.python.org/dev/peps/pep-0008/>`_ for Python.
We use `ruff <https://github.com/astral-sh/ruff/>`__ to format and lint our Python files.

We use a `pre-commit-hook <https://pre-commit.com/>`_ to apply this style before committing, so you don't have to bother about formatting.
We use a `pre-commit-hook <https://pre-commit.com/>`_ to apply these rules before committing, so you don't have to bother about doing so manually.
charludo marked this conversation as resolved.
Show resolved Hide resolved
Just code how you feel comfortable and let the tool do the work for you (see :ref:`pre-commit-hooks`).

If you want to apply the formatting without committing, use our developer tool :github-source:`tools/black.sh`::
If you want to lint your code and apply the formatting without committing, use our developer tool :github-source:`tools/ruff.sh`::

./tools/black.sh
./tools/ruff.sh


.. _djlint:
Expand Down Expand Up @@ -48,36 +47,6 @@ If you want to apply the formatting without committing, use our developer tool :
./tools/prettier.sh


.. _pylint:

Linting
-------

In addition to black, we use pylint to check the code for semantic correctness.
Run pylint with our developer tool :github-source:`tools/pylint.sh`::

./tools/pylint.sh

When you think a warning is a false positive, add a comment (see :doc:`pylint:user_guide/messages/message_control`)::

def some_function(
something: SomeModel, # pylint: disable=unused-argument
*args,
**kwargs) -> None:
# pylint: disable=too-many-branches

.. Note::

Please use the string identifiers (``unused-argument``) instead of the alphanumeric code (``W0613``) when disabling warnings.

.. Hint::

If you want to run both tools at once, use our developer tool :github-source:`tools/code_style.sh`::

./tools/code_style.sh

.. include:: _docstrings.rst


.. _mypy:

Expand All @@ -104,6 +73,14 @@ If you want to apply the formatting without committing, use our developer tool :

If a third party library is incorrectly typed or missing type hints, and this results in errors you cannot fix, then you can add ``# type: ignore[<error-class>]`` (where the ``<error-class>`` is the identifier of the error you're experiencing, e.g. ``attr-defined``) in the end of the line where the error is thrown.

.. Hint::

If you want to run all tools at once, use our developer tool :github-source:`tools/code_style.sh`::

./tools/code_style.sh

.. include:: _docstrings.rst


.. _shellcheck:

Expand Down
16 changes: 7 additions & 9 deletions docs/src/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,28 @@
import os
import sys
from datetime import date
from typing import Final
from typing import Final, TYPE_CHECKING

from django import VERSION as django_version_tuple
from sphinx.application import Sphinx
from django import VERSION as DJANGO_VERSION_TUPLE

from integreat_cms.core import settings

if TYPE_CHECKING:
from sphinx.application import Sphinx

# Append project source directory to path environment variable
sys.path.append(os.path.abspath("../.."))
# Append sphinx source directory to path environment variable to allow documentation for this file
sys.path.append(os.path.abspath("."))
#: The path to the django settings module (see :doc:`sphinxcontrib-django:readme`)
django_settings: Final[str] = "integreat_cms.core.sphinx_settings"
#: The "major.minor" version of Django
django_version: Final[str] = f"{django_version_tuple[0]}.{django_version_tuple[1]}"
django_version: Final[str] = f"{DJANGO_VERSION_TUPLE[0]}.{DJANGO_VERSION_TUPLE[1]}"

# -- Project information -----------------------------------------------------

#: The project name
project: Final[str] = "integreat-cms"
# pylint: disable=redefined-builtin
#: The copyright notice
copyright: Final[str] = f"{date.today().year} {settings.COMPANY}"
#: The project author
Expand Down Expand Up @@ -77,7 +78,6 @@
"dateutil": ("https://dateutil.readthedocs.io/en/stable/", None),
"geopy": ("https://geopy.readthedocs.io/en/stable/", None),
"lxml": ("https://lxml.de/apidoc/", None),
"pylint": ("https://pylint.readthedocs.io/en/latest/", None),
"python": (
f"https://docs.python.org/{sys.version_info.major}.{sys.version_info.minor}/",
None,
Expand Down Expand Up @@ -139,9 +139,7 @@
"django-source": (f"{django_github_url}/%s", "%s"),
}
#: A string of reStructuredText that will be included at the end of every source file that is read. Used for substitutions.
rst_epilog: Final[
str
] = f"""
rst_epilog: Final[str] = f"""
.. |github-username| replace:: {github_username}
.. |github-repository| replace:: {github_repository}
.. |github-pages-url| replace:: {github_pages_url}
Expand Down
10 changes: 0 additions & 10 deletions docs/src/continuous-integration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,6 @@ This job executes ``npm ci`` and makes use of the `CircleCI Dependency Cache <ht
After that, it compiles all static files with webpack (``npm run prod``) and passes the output in
``integreat_cms/static/dist`` to the subsequent jobs.

pylint
------

This job executes ``pylint_runner``, which checks whether the :ref:`pylint` throws any errors or warnings.

black
-----

This job executes ``black --check .``, which checks whether the code matches the :ref:`black-code-style` code style.

check-migrations
----------------

Expand Down
2 changes: 1 addition & 1 deletion docs/src/git-flow.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ All hooks for this repository are defined in :github-source:`.pre-commit-config.
At the moment, the following hooks are configured:

* ``shellcheck``: a static analysis tool for shell scripts (see: :ref:`shellcheck` and `ShellCheck wiki <https://github.com/koalaman/shellcheck/wiki>`_)
* ``black``: A formatter which applies automatic code formatting to Python files (see :ref:`black-code-style`)
* ``ruff``: A formatter and linter which applies automatic code formatting to Python files (see :ref:`ruff`)
* ``prettier``: A formatter which applies automatic code formatting to CSS/JS files (see :ref:`prettier-code-style`)
* ``djlint``: A formatter which applies automatic code formatting to Django HTML templates (see :ref:`djlint`)
* ``translations`` A script which checks whether the translation file is up-to-date (see: :doc:`internationalization` and :ref:`translations`)
Expand Down
Loading
Loading