Skip to content

Commit

Permalink
Add ruff to testing dependencies #512 #515
Browse files Browse the repository at this point in the history
Signed-off-by: Jono Yang <[email protected]>
  • Loading branch information
JonoYang committed Aug 13, 2024
1 parent b873555 commit f164569
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 15 deletions.
25 changes: 10 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,27 +56,22 @@ envfile_testing: envfile
@echo SCANCODEIO_DB_USER=\"postgres\" >> ${ENV_FILE}
@echo SCANCODEIO_DB_PASSWORD=\"postgres\" >> ${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 --exclude etc/scripts/ --exclude purldb-toolkit/ --exclude purl2vcs/
@echo "-> Run Ruff linter"
@${ACTIVATE} ruff check --fix --exclude etc/scripts/ --exclude purldb-toolkit/ --exclude purl2vcs/

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 --exclude etc/scripts/ --exclude purldb-toolkit/ --exclude purl2vcs/
@echo "-> Run Ruff format validation"
@${ACTIVATE} ruff format --check --exclude etc/scripts/ --exclude purldb-toolkit/ --exclude purl2vcs/
@$(MAKE) doc8

clean:
@echo "-> Clean the Python env"
Expand Down
59 changes: 59 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,62 @@ 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", # one-blank-line-before-class
"D205", # blank-line-after-summary
"D212", # multi-line-summary-first-line
"D400", # ends-in-period
"D415", # ends-in-punctuation
"E501", # line-too-long
# TODO: we want to address these issues in the codebase, then get rid of
# the following ignores
"C901", # complex-structure
"S101", # assert
"S103", # bad-file-permissions
"S113", # request-without-timeout
"S202", # tarfile-unsafe-members
"S314", # suspicious-xml-element-tree-usage
"S320", # suspicious-xmle-tree-usage
"S324", # hashlib-insecure-hash-function
"S506", # unsafe-yaml-load
"S602", # subprocess-popen-with-shell-equals-true
]

[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]
"**/testfiles/**.py" = ["F821"] # Ignore undefined names from test files
"matchcode_project/settings.py" = ["F403", "F405"] # Ignore undefined names from star imports and star imports
"purldb_public_project/settings.py" = ["F403", "F405"] # Ignore undefined names from star imports and star imports
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ testing =
black
mock
flot
ruff

docs =
Sphinx>=5.0.2
Expand Down

0 comments on commit f164569

Please sign in to comment.