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

Migrate to Ruff #62

Merged
merged 56 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
355e44b
test: add reproducibility tests for BH models
marcofavorito Aug 30, 2023
cafc338
dev: remove isort usage throughout the repository
marcofavorito Aug 24, 2023
1e31ced
dev: remove isort from pyproject.toml and poetry.lock
marcofavorito Aug 24, 2023
df7c051
dev: remove pylint usage throughout the repository
marcofavorito Aug 24, 2023
e5940c1
fix: remove '# pylint: disable' directives
marcofavorito Aug 24, 2023
70e1c6b
dev: remove pylint from pyproject.toml and poetry.lock
marcofavorito Aug 24, 2023
a73c4d5
dev: remove flake8 usage throughout the repository
marcofavorito Aug 24, 2023
4c1441e
dev: remove flake8-* packages from pyproject.toml and poetry.lock
marcofavorito Aug 24, 2023
a8a96f9
dev: add ruff to pyproject.toml as dev dependency
marcofavorito Aug 25, 2023
f5ba617
dev: fix 'make lint' with 'make lint-all'
marcofavorito Aug 25, 2023
92be0dd
dev: add .ruff.toml configuration file
marcofavorito Aug 25, 2023
c93729e
dev: add ruff in tox, Makefile, and in contributing guidelines
marcofavorito Aug 25, 2023
477cfa5
lint: fix pyflakes errors
marcofavorito Aug 25, 2023
d8c9673
lint: fix pep8-naming errors
marcofavorito Aug 25, 2023
de169ea
lint: fix pydocstyle errors
marcofavorito Aug 25, 2023
65ed299
lint: fix pyupgrade errors
marcofavorito Aug 25, 2023
128dcfa
lint: fix flake8-annotations errors
marcofavorito Aug 25, 2023
412dc9b
lint: ignore 'S' checks in Ruff config
marcofavorito Aug 25, 2023
4036e7d
lint: fix flake8-blind-except errors
marcofavorito Aug 25, 2023
3b9f964
lint: ignore flake8-boolean-trap errors
marcofavorito Aug 28, 2023
62cc667
lint: fix flake8-builtins errors
marcofavorito Aug 28, 2023
33d968c
lint: fix flake8-commas errors
marcofavorito Aug 29, 2023
c37ff05
lint: fix flake8-copyright errors
marcofavoritobi Sep 20, 2023
443eea7
lint: fix flake8-comprehensions errors
marcofavorito Aug 29, 2023
9c5da9d
lint: fix flake8-errmsg errors
marcofavorito Aug 29, 2023
dfeb9d2
lint: fix flake8-executable errors
marcofavorito Aug 29, 2023
692dbd1
lint: fix flake8-future-annotations errors
marcofavorito Aug 29, 2023
fbdb708
lint: fix flake8-no-pep420 errors
marcofavorito Aug 29, 2023
6b35968
dev: add examples/ folder in copyright-checked files
marcofavorito Aug 29, 2023
785ee29
lint: fix flake8-print errors
marcofavorito Aug 29, 2023
b51dd16
lint: fix flake8-pytest-style errors
marcofavorito Aug 29, 2023
48024da
lint: fix flake8-return errors
marcofavorito Aug 29, 2023
7d36d14
lint: fix flake8-self errors
marcofavorito Aug 29, 2023
eef7cc9
lint: fix flake8-simplify errors
marcofavorito Aug 29, 2023
99222dc
lint: fix flake8-type-checking errors
marcofavorito Aug 29, 2023
5837237
lint: fix flake8-unused-arguments errors
marcofavorito Aug 29, 2023
add9476
lint: fix flake8-use-pathlib errors
marcofavorito Aug 29, 2023
7ed39ae
lint: fix flake8-todos
marcofavorito Aug 29, 2023
97a5d43
lint: ignore eradicate errors
marcofavorito Aug 29, 2023
e918605
lint: fix pandas-vet errors
marcofavorito Aug 29, 2023
55d7395
lint: fix pygrep-hooks errors
marcofavorito Aug 29, 2023
a4a50ad
lint: fix PLR2004 errors
marcofavorito Aug 30, 2023
b0e1d6d
lint: fix all remaining pylint errors
marcofavorito Aug 30, 2023
95d0f16
lint: fix tryceratops errors
marcofavorito Aug 30, 2023
a67a1f6
lint: ignore NumPy-specific rules errors for specific modules
marcofavorito Aug 30, 2023
b21d259
lint: fix NPY002 for Brock-Hommes model
marcofavorito Aug 30, 2023
bca1344
lint: fix NPY002 for examples/models/simple_models.py
marcofavorito Aug 30, 2023
2269dfa
lint: fix NPY002 for examples/models/sir/sir_python.py
marcofavorito Aug 30, 2023
859f063
lint: fix NPY002 in tests/*
marcofavorito Sep 1, 2023
a9b58ff
lint: fix Perflint errors
marcofavorito Sep 1, 2023
ef0a5a2
lint: automatically fix RUF fixable errors
marcofavorito Sep 1, 2023
dc7c87f
fix: update coordinate_filters argument type annotation in BaseLoss._…
marcofavorito Sep 1, 2023
f61be8b
lint: fix remaining Ruff-specific-rules errors
marcofavorito Sep 1, 2023
72f85cb
ci: add ruff-check step in lint workflow
marcofavorito Sep 1, 2023
0f2b6b0
chore: add --show-fixes in tox.ini ruff-check testenv command
marcofavorito Sep 1, 2023
628399d
ci: run all tox testenv in a single command
marcofavoritobi Sep 22, 2023
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
11 changes: 2 additions & 9 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,13 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: pip install tox
- name: Pylint
run: tox -e pylint
- name: Code style check
run: |
tox -e black-check
tox -e isort-check
tox -e flake8
tox -e vulture
tox -e darglint
tox -e black-check,ruff-check,vulture,darglint
- name: Static type check
run: tox -e mypy
- name: Check copyright
run: tox -e check-copyright
- name: Misc checks
run: |
tox -e bandit
tox -e safety
tox -e bandit,safety
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -362,3 +362,5 @@ Java\ model/

examples/output

!tests/fixtures/data/test_sir_python.npy
!tests/fixtures/data/test_sir_python_w_breaks_python.npy
50 changes: 0 additions & 50 deletions .pylintrc

This file was deleted.

67 changes: 67 additions & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
select = ["F","W","E","C90","I","N","D","UP","YTT","ANN","ASYNC","BLE","B","A","COM","CPY","C4","DTZ","T10","DJ","EM","EXE","FA","ISC","ICN","G","INP","PIE","PYI","PT","Q","RSE","RET","SLF","SLOT","SIM","TID","TCH","INT","ARG","PTH","TD","FIX","ERA","PD","PGH","PL","TRY","FLY","NPY","AIR","PERF","FURB","LOG","RUF"]
ignore = ["ANN101", "ANN102", "E203", "S", "FBT", "T20"]

# Allow autofix for all enabled rules (when `--fix`) is provided.
#fixable = ["ALL"]
#unfixable = []

include = ["black_it/**/*.py", "tests/**/*.py", "scripts/**/*.py", "examples/**/*.py"]

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

# Same as Black.
line-length = 120

# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"

# Whether to enable preview mode. When preview mode is enabled, Ruff will use unstable rules and fixes.
preview = true

# Assume Python 3.8
target-version = "py38"

[per-file-ignores]
"examples/docker-sir.py" = ["INP001", "T201"]
"examples/main.py" = ["INP001", "T201"]
"examples/models/simple_models.py" = ["ERA001", "INP001"]
"examples/models/economics/brock_hommes.py" = ["ERA001"]
"examples/models/forest_fire/forest_fire.py" = ["T201"]
"examples/models/sir/simlib.py" = ["T201"]
"scripts/check_copyright.py" = ["T201"]
"tests/**.py" = ["PLR2004"]


[mccabe]
# Unlike Flake8, default to a complexity level of 10.
max-complexity = 10

[pydocstyle]
convention = "google"

[pylint]
max-args = 7
2 changes: 2 additions & 0 deletions .spelling
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,5 @@ AldoGl
marcofavoritobi
codecoverage
Codecov
- CONTRIBUTING.md
linter
12 changes: 7 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,25 @@ We have various commands which are helpful during development.

- For linting and static analysis use:
```
make lint
make lint-all
make static
make pylint
make safety
make bandit
```

- To apply [`black`](https://black.readthedocs.io/en/stable/) and [`isort`](https://pycqa.github.io/isort/index.html) code formatters:
- To apply [`black`](https://black.readthedocs.io/en/stable/) code formatter:
```
make black
make isort
```

- whereas, to only check compliance:
```
make black-check
make isort-check
```

- To apply [`ruff`](https://beta.ruff.rs/docs/) linter:
```
make ruff-check
```

- To run tests: `make test`.
Expand Down
59 changes: 21 additions & 38 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,10 @@ clean-test: ## remove test and coverage artifacts
rm -fr coverage.xml

PHONY.: lint-all
lint-all: black isort flake8 static bandit safety vulture darglint pylint ## run all linters
lint-all: black ruff static bandit safety vulture darglint ## run all linters

PHONY.: lint-all-files
lint-all-files: black-files isort-files flake8-files static-files bandit-files vulture-files darglint-files pylint-files ## run all linters for specific files (specified with files="file1 file2 somedir ...")

PHONY.: flake8
flake8: ## check style with flake8
flake8 black_it tests scripts examples

PHONY.: flake8-files
flake8-files: ## check style with flake8 for specific files (specified with files="file1 file2 somedir ...")
$(call check_defined, files)
flake8 $(files)
lint-all-files: black-files ruff-files static-files bandit-files vulture-files darglint-files ## run all linters for specific files (specified with files="file1 file2 somedir ...")

PHONY.: static
static: ## static type checking with mypy
Expand All @@ -86,24 +77,6 @@ static-files: ## static type checking with mypy for specific files (specified wi
$(call check_defined, files)
mypy $(files)

PHONY.: isort
isort: ## sort import statements with isort
isort black_it tests scripts examples

PHONY.: isort-files
isort-files: ## sort import statements with isort for specific files (specified with files="file1 file2 somedir ...")
$(call check_defined, files)
isort $(files)

PHONY.: isort-check
isort-check: ## check import statements order with isort
isort --check-only black_it tests scripts examples

PHONY.: isort-check-files
isort-check-files: ## check import statements order with isort for specific files (specified with files="file1 file2 somedir ...")
$(call check_defined, files)
isort --check-only $(files)

PHONY.: black
black: ## apply black formatting
black black_it tests scripts examples
Expand All @@ -117,10 +90,29 @@ PHONY.: black-check
black-check: ## check black formatting
black --check --verbose black_it tests scripts examples

PHONY.: black-check-files
black-check-files: ## check black formatting for specific files (specified with files="file1 file2 somedir ...")
$(call check_defined, files)
black --check --verbose $(files)

PHONY.: ruff
ruff: ## run ruff linter
ruff check --fix --show-fixes .

PHONY.: ruff-files
ruff-files: ## run ruff linter for specific files (specified with files="file1 file2 somedir ...")
$(call check_defined, files)
ruff check --fix --show-fixes $(files)

PHONY.: ruff-check
ruff-check: ## check ruff linter rules
ruff check .

PHONY.: ruff-check-files
ruff-check-files: ## check ruff linter rules for specific files (specified with files="file1 file2 somedir ...")
$(call check_defined, files)
ruff check $(files)

PHONY.: bandit
bandit: ## run bandit
bandit --configfile .bandit.yaml --recursive black_it tests scripts examples
Expand All @@ -134,15 +126,6 @@ PHONY.: safety
safety: ## run safety
safety check

PHONY.: safety-files
pylint: ## run pylint
pylint black_it tests scripts examples

PHONY.: pylint-files
pylint-files: ## run pylint for specific files (specified with files="file1 file2 somedir ...")
$(call check_defined, files)
pylint $(files)

PHONY.: vulture
vulture: ## run vulture
vulture black_it scripts/whitelists/package_whitelist.py
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ When the calibration terminates (~half a minute), towards the end of the output
you should see the following messages:
```
True parameters: [0.2, 0.2, 0.75]
Best parameters found: [0.19 0.19 0.74]
Best parameters found: [0.19 0.21 0.68]
```

## Docs
Expand Down
Loading