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

Added ruff for linting and formatting #28

Merged
merged 4 commits into from
Jan 19, 2024
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
shell: cmd
if: runner.os == 'Windows'

docs_black:
docs:
runs-on: ubuntu-latest

steps:
Expand All @@ -77,6 +77,22 @@ jobs:
run: |
tox -e docs

- name: Run tox env black
ruff:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Set up Python 3.12
uses: actions/setup-python@v2
with:
python-version: 3.12

- name: Install poetry and tox
run: |
python -m pip install poetry tox

- name: Run ruff
continue-on-error: true # deactivate for now (need to fix the issues over time)
run: |
tox -e black
tox -e lint
96 changes: 27 additions & 69 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 68 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,21 +83,83 @@ pytest-cov = "*"
tox = "*"
pytest-xdist = "*" # parallelisation

black = { version = "^22", allow-prereleases = true }
# linting, formatting
ruff = "^0.1.13"

# docs
sphinx = "*"
sphinx_rtd_theme = "*"
sphinxcontrib-plantuml = "*"

[tool.ruff]
# Exclude a variety of commonly ignored directories.
exclude = [
".bzr",
".direnv",
".eggs",
".git",
".hg",
".mypy_cache",
".nox",
".pants.d",
".pytype",
".ruff_cache",
".svn",
".tox",
".venv",
"__pypackages__",
"_build",
"buck-out",
"build",
"dist",
"node_modules",
"venv",
".venv",
]

# use Black's default
line-length = 88

# Assume Python 3.11.
target-version = "py311"

[tool.ruff.lint]
# concept: select all rules by default and ignore unwanted (maybe just per file)
# this comes at a cost: new added rules are applied automatically, so a CI that
# runs green today might fail tomorow in case ruff gets updated
# (which brings more good than bad)
# TODO ENABLE NEXT LINE
select = ["ALL"]
# select = [] # commented out (don't want to fix all issues with this PR)
ignore = [
"COM812", # may conflict with Ruff formatter
"D107", # undocumented-public-init - commonly the docstring provides no helpful information
"D203", # D203 and D211 are mutually exclusive: https://github.com/PyCQA/pydocstyle/issues/141
"D212", # D212 and D213 are mutually exclusive: https://stackoverflow.com/a/45990465
"FIX002", # line-contains-todo - TODOs are considered helpful
"ISC001", # may conflict with Ruff formatter
"TD003", # missing-todo-link - no big processes for us
]

# Allow autofix for all enabled rules (when `--fix`) is provided.
fixable = ["ALL"]
unfixable = [
"D400", # ends-in-period - dangerous to use (ruff may confuse summary line and content)
"ERA001", # commented-out-code - commented code is commonly there for a reason
]

[tool.ruff.mccabe]
max-complexity = 20

[tool.ruff.per-file-ignores]
# "docs/conf.py" = ["E402"]
"**/__init__.py" = [
"D104",
] # Missing docstring in public package - not needed for inits

[tool.poetry.scripts]
libpdf = 'libpdf.core:main_cli'

[tool.black]
line-length = 120
target-version = ['py38']
skip-string-normalization = 'True'

[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"
18 changes: 14 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ envlist = py{38,39,310,311,312}, docs, black
allowlist_externals = poetry
skip_install = True
passenv = *
py_folders = examples libpdf tests

commands=
poetry install
Expand All @@ -19,22 +20,31 @@ commands=
[testenv:py12]
commands=
poetry install
py.test -n auto --tb=long --cov=libpdf
poetry run py.test -n auto --tb=long --cov=libpdf

[testenv:docs]
envdir = {toxworkdir}/py312
basepython = python3.12
changedir = docs
commands =
poetry install
sphinx-build -W -b html . _build/html
poetry run sphinx-build -W -b html . _build/html

[testenv:black]
[testenv:lint]
envdir = {toxworkdir}/py312
basepython = python3.12
commands=
poetry install --no-root
black --check examples libpdf tests
poetry run ruff format --check {[testenv]py_folders}
poetry run ruff {[testenv]py_folders}

[testenv:format]
envdir = {toxworkdir}/py312
basepython = python3.12
commands=
poetry install --no-root
poetry run ruff format {[testenv]py_folders}
poetry run ruff check --fix --exit-zero --silent {[testenv]py_folders}

[pytest]
testpaths = tests
Loading