Skip to content

Commit

Permalink
Merge pull request #21 from analog-garage/ruff
Browse files Browse the repository at this point in the history
Add ruff linting support
  • Loading branch information
analog-cbarber authored Jun 23, 2024
2 parents a80eb60 + 722fded commit 3dd61a1
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 7 deletions.
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ PYTEST_ARGS :=
TOX_ARGS :=
PYLINT_ARGS :=
MYPY_ARGS :=
RUFF_ARGS :=

DOC_DIR := docs
MKDOC_CONFIG := mkdocs.yml
Expand All @@ -71,7 +72,7 @@ help:
@$(ECHO)
@$(ECHO) "$(SECTION_COLOR)--- lint ---$(COLORLESS)"
@$(ECHO) "lint - Run linting commands in '$(DEV_ENV)' environment."
@$(ECHO) "pylint - Run pylint in '$(DEV_ENV)' environment."
@$(ECHO) "ruff - Run ruff in '$(DEV_ENV)' environment."
@$(ECHO) "mypy - Run mypy in '$(DEV_ENV)' environment."
@$(ECHO)
@$(ECHO) "$(SECTION_COLOR)--- build ---$(COLORLESS)"
Expand Down Expand Up @@ -137,10 +138,13 @@ coverage-show:
pylint:
$(CONDA_RUN) pylint src/mkdocstrings_handlers tests $(PYLINT_ARGS)

ruff:
$(CONDA_RUN) ruff check src/mkdocstrings_handlers tests $(RUFF_ARGS)

mypy:
$(CONDA_RUN) mypy $(MYPY_ARGS)

lint: pylint mypy
lint: ruff mypy

WHEEL_FILE := dist/$(subst -,_,$(PACKAGE))-$(VERSION)-py3-none-any.whl
CONDA_FILE := dist/$(PACKAGE)-$(VERSION)-py_0.conda
Expand Down
7 changes: 4 additions & 3 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ dependencies:
- hatchling >=1.21
# test
- coverage >=7.4.0
- pytest >=7.4.0
- pytest-cov >=4.1.0
- pytest >=8.2
- pytest-cov >=5.0
- pylint >=3.0.3
- mypy >=1.8
- mypy >=1.10
- ruff >=0.4.10
- beautifulsoup4 >=4.12
# documentation
- black >=23.12
Expand Down
60 changes: 60 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,66 @@ module = [
]
ignore_missing_imports = true

[tool.ruff.lint]
# TODO add "I" (isort)
# TODO add "RUF"
# TODO add "ARG"
# TODO add "SIM"
# TODO add "S" (bandit)
# TODO add "PT" (pytest style)
# TODO add "CPY101"
select = ["E", "F", "PL", "D", "R", "T10", "EXE"]
ignore = [
"D105", # missing doc string for dunder methods
"D200", # one line doc string
"D202", # blank lines after function docstring
"D205", # doc on first line
"D212", # doc on first line
"D410", # blank line after doc section
"D411", # blank line before doc section
"D412", # no blank lines after section header
"D415", # doc title punctuation
"E501", # line too long
"PLC0105", # covariant metatype names
"PLR0913", # too-many-argument
"PLR2004", # magic value
"PT001", # allow @pytest.fixture without parens
"RET504", # unnecessary assignment to variable before return
"S101", # use of assert - do we care?
# TODO: fix the ones below
"D403", # capitalize first word of doc string
"D102", # undocumented public method
"D104", # missing docstring in public package
"D107", # __init__ docstring
"D417", # missing argument description
]
preview = true
explicit-preview-rules = true # only preview explicitly selected rules (E.g. CPY001)

[tool.ruff.lint.per-file-ignores]
# Ignore some issues in tests
"tests/**" = [
"F401", # unused import (pytest fixture)
"F403", # wildcard import (for fixtures)
"F405", # defined from star imports (typicallky a pytest fixture)
"F811", # redefinition of unused (typically a pytest fixture)
"PLR0912", # too many branches
"PLR0915", # too many statements
"S", # bandit rules
]

[tool.ruff.lint.pylint]
#max-locals = 30
max-branches = 15
#max-attributes = 30

[tool.ruff.lint.pydocstyle]
convention = "google"

[too.ruff.format]
skip-magic-trailing-comma = false
line-ending = "lf"

[tool.pylint.main]
jobs = 0
# Minimum Python version to use for version dependent checks.
Expand Down
3 changes: 1 addition & 2 deletions tests/test_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ def test_handler(tmpdir: PathLike,
def fake_collect(_self: PythonHandler, identifier: str, _config: dict) -> Any:
if identifier.startswith('mod'):
return Object(identifier)
else:
raise CollectionError(identifier)
raise CollectionError(identifier)

def fake_render(_self: PythonHandler, data: Object, _config: dict) -> str:
assert data.docstring is not None
Expand Down

0 comments on commit 3dd61a1

Please sign in to comment.