Skip to content

Commit

Permalink
Add ruff to testing dependencies #515
Browse files Browse the repository at this point in the history
    * Update code validation Make command
    * Install doc dependencies when running configure

Signed-off-by: Jono Yang <jyang@nexb.com>
  • Loading branch information
JonoYang committed Aug 6, 2024
1 parent d9ca298 commit c9750ad
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 16 deletions.
25 changes: 10 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 39 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
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 c9750ad

Please sign in to comment.