Skip to content

Commit

Permalink
Set up ruff and fix trivial rules (#165)
Browse files Browse the repository at this point in the history
* Add `ruff.toml`

* Remove isort and flake8 from pre-commit

* Add ruff to pre-commit

* Remove isort and flake8 from `setup.cfg`

* Set target version to 3.10 for ruff

* Automatically fix ruff linter

* Add `mypy` and `ruff` as dev dependencies

* Run `ruff check  .` on codebase

* Ruff ignore `ANN001` (missing type function arguments)

* Ignore more ruff rules

* Run `ruff check --unsafe-fixes .`

* Remove commented out code

* Fix TODO comment

* Add file-specific ignore rules for ruff

* Add GH issue links to TODOs

* Fix ruff `B905`: add `strict=True` in `zip()`

* Fix ruff `TRY200`: use `raise from`

* Fix ruff `PTH123`: `open()` -> `Path.open()`

* Fix ruff `PLR2004`: use of magic values

* Fix ruff `PTH` rules

* Fix ruff `S` rules

* Remove unused ruff ignore comments

* Add more rules to the ruff ignore list

* Fix ruff rule PT

* Fix single quotes

* Fix Ruff rules PL

* Fix ruff rule TRY

* Fix ruff rule RET

* Fix ruff rule FBT001 and whitespace

* Fix ruff rule B

* Fix ruff rule DTZ007

* Add missing imports

* Set `orthanc` plugins as `namespace-packages`

* Fix ruff rules remaining (not ignored)

* ignore rules in ruff.toml

* Fix ruff ignore comment

* Fix ruff rules in orthanc-raw - add docstrings

* Fix (some) ruff rules in orthanc-anon - add docstrings

* `pixl_core`: fix ruff rule D100

Add docstrings to public modules

* `pixl_core`: fix ruff rule D103

Add missing docstrings to public functions

* `pixl_core`: fix ruff rule D101

* `pixl_core`: ignore ruff rule ARG001

Need further testing to check whether these arguments can be removed

* `pixl_core`: fix ruff rule G004

* `pixl_core`: fix test checking datetime

Fixing ruff rule DTZ007 in e96307b caused this test to fail because the timestamp didn't include the timezone.
Also requires `import datetime` to access the `timezone` attribute

* `cli`: fix ruff rule D100 (module docstrings)

* `cli`: fix ruff rule D103

* `cli`: fix remaining ruff D10* rules

* `cli`: fix failing tests after previous ruff issue fixes

- `yaml.safe_load()` does not have a `Loader` argument
- `import datetime` to get access to `timezone`
- `datetime` -> `datetime.datetime` because of the previous

* `cli`: fix ruff rule S101, replace `assert` with exceptions

* `cli`: replace `print()` with `logger.info()`

* `cli`: fix ruff rule S113, set request timeouts

* `pixl_ehr`: ignore D1** ruff rules for tests

* `pixl_ehr`: formatting

* Ignore ruff rule S608

See #154

* Fix remaining ruff rules in orthanc-anon - add docstrings Azure Token

* Fix ruff ignore comment PLW0602

* Fix ruff rules for orthanc-raw adding docstrings

* Fix (some) ruff rules in orthanc-anon - add docstrings

* Fix remaining ruff rules in orthanc-anon - add docstrings Azure Token

* Fix ruff rule G004 in pixl_pacs

* Fix datetime import error

* Fix ruff rule RUF006 in pixl_pacs

* Fix ruff rule RUF006 in pixl_ehr

* Fix datetime import error

* Fix ruff rules in pixl_ehr _processing

* Ignore ruff rule PLW2901 see #157

* Fix ruff rule missing docstrings for pixl_pacs

* `hasher`: fix expected error message

* `hasher`: use `@pytest.mark` to define `dummy_key` fixture

* Formatting

* `hasher`: ignore `D1` rules for tests

* `hasher`: ignore ruff rule T201 (print statements)

* Fix ruff rule G004 for pixl_ehr

* `hasher`: replace logging `f`-string

* `hasher`: fix ruff rule D100, public module docstrings

* `hasher`: ignore rule D103 for `endpoints` functions

Docstrings feel like overkill for these functions

* pre-commit applied locally

* Fix ruff setup

Specifying the `config=ruff.toml` ignores subdirectory `ruff.toml` files

* More `ruff` autofixes

* Ruff pixl_ehr docstrings

* Fix `Path` API calls

* Fix unspported left operand error

* Fix `RuntimeError` message

* Fix `fromisoformat()` call

---------

Co-authored-by: ruaridhg <ruaridhg@users.noreply.github.com>
  • Loading branch information
milanmlft and ruaridhg authored Dec 4, 2023
1 parent 3f75c7b commit e0190a1
Show file tree
Hide file tree
Showing 64 changed files with 763 additions and 456 deletions.
25 changes: 8 additions & 17 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,15 @@
# limitations under the License.
---
repos:
- repo: https://github.com/pycqa/isort
rev: 5.12.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.6
hooks:
- id: isort
name: isort (python)
args: ["--profile", "black", "--settings-path", "setup.cfg"]

- repo: https://github.com/ambv/black
rev: 23.9.1
hooks:
- id: black

- repo: https://github.com/pycqa/flake8
rev: 6.1.0
hooks:
- id: flake8
args: ["--config", "setup.cfg"]
exclude: "tests|orthanc"
- id: ruff
args:
- --fix
- id: ruff-format
args:
- --config=ruff.toml

- repo: local
hooks:
Expand Down
5 changes: 5 additions & 0 deletions cli/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ dependencies = [
test = [
"pytest==7.4.*"
]
dev = [
"mypy",
"pre-commit",
"ruff",
]

[project.scripts]
pixl = "pixl_cli.main:cli"
Expand Down
2 changes: 2 additions & 0 deletions cli/src/pixl_cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""PIXL command line interface"""

from pixl_cli.main import cli

__all__ = ["cli"]
5 changes: 2 additions & 3 deletions cli/src/pixl_cli/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
from pathlib import Path


def clear_file(filepath: Path) -> None:
"""Clear the contents of a file"""
open(filepath, "w").close()
Path.open(filepath, "w").close()


def string_is_non_empty(string: str) -> bool:
Expand All @@ -28,4 +27,4 @@ def string_is_non_empty(string: str) -> bool:
def remove_file_if_it_exists(filepath: Path) -> None:
"""If a file exists remove it"""
if filepath.exists():
os.remove(filepath)
Path.unlink(filepath)
Loading

0 comments on commit e0190a1

Please sign in to comment.