diff --git a/Makefile b/Makefile index 691ba6fc..fc889d8b 100644 --- a/Makefile +++ b/Makefile @@ -57,27 +57,22 @@ envfile_testing: @echo SECRET_KEY=\"${GET_SECRET_KEY}\" >> ${ENV_FILE} @echo SCANCODEIO_DB_PORT=\"5433\" >> ${ENV_FILE} -isort: - @echo "-> Apply isort changes to ensure proper imports ordering" - ${VENV}/bin/isort . - -black: - @echo "-> Apply black code formatter" - ${VENV}/bin/black . - doc8: @echo "-> Run doc8 validation" @${ACTIVATE} doc8 --max-line-length 100 --ignore-path docs/_build/ --quiet docs/ -valid: isort black +valid: + @echo "-> Run Ruff format" + @${ACTIVATE} ruff format + @echo "-> Run Ruff linter" + @${ACTIVATE} ruff check --fix check: - @echo "-> Run pycodestyle (PEP8) validation" - @${ACTIVATE} pycodestyle --max-line-length=100 --exclude=venv,lib,thirdparty,docs,migrations,settings.py . - @echo "-> Run isort imports ordering validation" - @${ACTIVATE} isort --check-only . - @echo "-> Run black validation" - @${ACTIVATE} black --check ${BLACK_ARGS} + @echo "-> Run Ruff linter validation (pycodestyle, bandit, isort, and more)" + @${ACTIVATE} ruff check + @echo "-> Run Ruff format validation" + @${ACTIVATE} ruff format --check + @$(MAKE) doc8 clean: @echo "-> Clean the Python env" diff --git a/configure b/configure index 906137be..2ca14c39 100755 --- a/configure +++ b/configure @@ -31,7 +31,7 @@ CUSTOM_PACKAGES="" # Requirement arguments passed to pip and used by default or with --dev. REQUIREMENTS="$CUSTOM_PACKAGES --editable purldb-toolkit/ --editable purl2vcs/ --editable . --constraint requirements.txt" -DEV_REQUIREMENTS="$CUSTOM_PACKAGES --editable purldb-toolkit/[testing] --editable .[testing] --editable purl2vcs/[testing] --constraint requirements.txt --constraint requirements-dev.txt" +DEV_REQUIREMENTS="$CUSTOM_PACKAGES --editable purldb-toolkit/[testing] --editable .[testing,docs] --editable purl2vcs/[testing] --constraint requirements.txt --constraint requirements-dev.txt" DOCS_REQUIREMENTS="$CUSTOM_PACKAGES --editable purldb-toolkit/ --editable .[docs] --constraint requirements.txt" # where we create a virtualenv diff --git a/pyproject.toml b/pyproject.toml index cde79074..b95b8061 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -50,3 +50,42 @@ addopts = [ "--strict-markers", "--doctest-modules" ] + +[tool.ruff] +line-length = 88 +extend-exclude = ["migrations", "var"] +target-version = "py310" + +[tool.ruff.lint] +# Rules: https://docs.astral.sh/ruff/rules/ +select = [ + "E", # pycodestyle + "W", # pycodestyle warnings + "D", # pydocstyle + "F", # Pyflakes + "UP", # pyupgrade + "S", # flake8-bandit + "I", # isort + "C9", # McCabe complexity +] +ignore = ["D1", "D203", "D205", "D212", "D400", "D415"] + +[tool.ruff.lint.isort] +force-single-line = true +sections = { django = ["django"] } +section-order = [ + "future", + "standard-library", + "django", + "third-party", + "first-party", + "local-folder", +] + +[tool.ruff.lint.mccabe] +max-complexity = 10 + +[tool.ruff.lint.per-file-ignores] +# Allow the usage of assert in the test_spdx file. +"**/test_spdx.py*" = ["S101"] +"scanpipe/pipes/spdx.py" = ["UP006", "UP035"] diff --git a/setup.cfg b/setup.cfg index 1bfa9fa6..743c8393 100644 --- a/setup.cfg +++ b/setup.cfg @@ -80,6 +80,7 @@ testing = black mock flot + ruff docs = Sphinx>=5.0.2