Skip to content

Commit

Permalink
GitHub Action to lint Python code with ruff (#1771)
Browse files Browse the repository at this point in the history
* GitHub Action to lint Python code with ruff
  • Loading branch information
cclauss committed Mar 26, 2023
1 parent 3ec2799 commit f7fdf0f
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 44 deletions.
44 changes: 10 additions & 34 deletions .github/workflows/pr-run-linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,15 @@ name: Linter
on: pull_request

jobs:
flake8-lint:
lint:
runs-on: ubuntu-latest
name: flake8 linter
steps:
- uses: actions/checkout@v2

- name: Set up Python environment
uses: actions/setup-python@v2
with:
python-version: "3.10"

- name: flake8 errors
uses: reviewdog/action-flake8@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
flake8_args: "--select=E901,E999,F821,F822,F823"
level: error
fail_on_error: true

- name: flake8 warnings
uses: reviewdog/action-flake8@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
level: warning

black-lint:
runs-on: ubuntu-latest
name: black formatter
steps:
- uses: actions/checkout@v2
- name: black
uses: reviewdog/action-black@v2
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
level: warning
filter_mode: diff_context
- uses: actions/checkout@v3
- run: pip install --user ruff
- run: ruff --format=github .
- name: black
uses: reviewdog/action-black@v2
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
level: warning
filter_mode: diff_context
7 changes: 3 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
# caution: testing won't work on windows

test-code:
py.test pydicom
pytest pydicom

test-doc:
pytest doc/*.rst

test-coverage:
rm -rf coverage .coverage
py.test pydicom --cov-report term-missing --cov=pydicom
pytest pydicom --cov-report term-missing --cov=pydicom

test: test-code test-doc

Expand All @@ -30,5 +30,4 @@ clean:
rm -rf examples/.ipynb_checkpoints

code-analysis:
flake8 pydicom | grep -v __init__ | grep -v external
pylint -E -i y pydicom/ -d E1103,E0611,E1101
ruff .
2 changes: 1 addition & 1 deletion pydicom/sr/_snomed_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -15076,4 +15076,4 @@
'R-FFFEA': '716940001',
'R0-0000B': '716941002',
'R-FFFD9': '717027004',
}
}
8 changes: 4 additions & 4 deletions pydicom/tests/test_JPEG_LS_transfer_syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@


try:
import pydicom.pixel_data_handlers.numpy_handler as numpy_handler
from pydicom.pixel_data_handlers import numpy_handler
HAVE_NP = numpy_handler.HAVE_NP
except ImportError:
HAVE_NP = False
numpy_handler = None

try:
import pydicom.pixel_data_handlers.pillow_handler as pillow_handler
from pydicom.pixel_data_handlers import pillow_handler
HAVE_PIL = pillow_handler.HAVE_PIL
HAVE_JPEG = pillow_handler.HAVE_JPEG
HAVE_JPEG2K = pillow_handler.HAVE_JPEG2K
Expand All @@ -36,14 +36,14 @@
HAVE_JPEG2K = False

try:
import pydicom.pixel_data_handlers.jpeg_ls_handler as jpeg_ls_handler
from pydicom.pixel_data_handlers import jpeg_ls_handler
HAVE_JPEGLS = jpeg_ls_handler.HAVE_JPEGLS
except ImportError:
jpeg_ls_handler = None
HAVE_JPEGLS = False

try:
import pydicom.pixel_data_handlers.gdcm_handler as gdcm_handler
from pydicom.pixel_data_handlers import gdcm_handler
HAVE_GDCM = gdcm_handler.HAVE_GDCM
except ImportError:
gdcm_handler = None
Expand Down
2 changes: 1 addition & 1 deletion pydicom/util/leanread.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def __exit__(
) -> Optional[bool]:
self.fobj.close()

return None
return None # noqa: PLR1711

def __iter__(self) -> Iterator[_ElementType]:
# Need the transfer_syntax later
Expand Down
38 changes: 38 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[tool.ruff]
select = [
"C9",
"E",
"F",
"PL",
"W",
]
ignore = [
"E402",
"F401",
"F403",
"F405",
"F541",
"F601",
"F811",
"F841",
"PLR5501",
"PLC1901",
"PLR2004",
"PLW0603",
"PLW2901",
]
line-length = 214
target-version = "py37"

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

[tool.ruff.pylint]
max-args = 17
max-branches = 39
max-returns = 9
max-statements = 106

[tool.ruff.per-file-ignores]
"*/__init__.py" = ["F401"]
"pydicom/config.py" = ["PLW0602"]

0 comments on commit f7fdf0f

Please sign in to comment.