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

Improving ruff setup #224

Merged
merged 44 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
b3edb62
Redefining ruff, starting with target-version = "py38"
castelao Jun 26, 2024
8c9f307
Excluding CSV and ref.*?py
castelao Jun 26, 2024
5db2b31
Disabling rules according to .python-lint
castelao Jun 26, 2024
e29073e
max-nested-blocks
castelao Jun 26, 2024
ece6552
Confirming with expected-line-ending-format
castelao Jun 26, 2024
ec2fa95
Defining line-lenght as .python-lint line 267
castelao Jun 26, 2024
8024105
indent-width
castelao Jun 26, 2024
47f0635
multiple-statements-on-one-line-colon
castelao Jun 27, 2024
7293026
task-tags
castelao Jun 27, 2024
5889784
In respect t ologging-modules, line 285 of .python-lint
castelao Jun 27, 2024
2368874
unused imports
castelao Jun 27, 2024
f93b7b1
Defining max-args
castelao Jun 27, 2024
576763c
Defining DESIGN explicit setup
castelao Jun 27, 2024
0316003
Closest option of satisfy EXCEPTIONS
castelao Jun 27, 2024
4f3c334
Re-introducing all (W) Warning rules
castelao Jun 27, 2024
56f5c9d
Re-introducing (Q) flake8-quotes rules
castelao Jun 27, 2024
bc06fad
Re-introducing (I) isort rules
castelao Jun 27, 2024
2340702
Re-introducing (NPY) NymPy-specific rules
castelao Jun 27, 2024
3d482a3
style: Conforming with UP039
castelao Jun 27, 2024
070d7b9
Re-introducing (UP) pyupgrade rules
castelao Jun 27, 2024
80b8ee2
Re-introducing (A) flake8-builtins
castelao Jun 27, 2024
ebfbc74
Re-introducing (ARG) flake8-unused-arguments rules
castelao Jun 27, 2024
2f921d6
Re-introducing (E) pycodestyle rules
castelao Jun 27, 2024
e319929
Re-introducing (F) Pyflakes rules
castelao Jun 27, 2024
43c0dd3
Re-introducing (COM) flake8-commas rules
castelao Jun 27, 2024
2454b47
Introducing (N) pep8-naming rules
castelao Jun 27, 2024
6ac9622
Introducing (D) pydocstyle rules
castelao Jun 27, 2024
92ed73d
Introducing (PL) Pylint rules
castelao Jun 27, 2024
e14a08d
Running ruff with GA
castelao Jun 27, 2024
c12f36f
Nothing is fixable for now
castelao Jun 27, 2024
ec3e916
Using ruff with pre-commmit
castelao Jun 27, 2024
7234595
style: Conforming with NPY003 & NPY201
castelao Jun 27, 2024
4390315
style: Conforming with COM819
castelao Jun 27, 2024
12521db
Forgot to include: quote-style & indent-style
castelao Jun 27, 2024
eadd1cb
Updating requirements on ruff
castelao Jun 27, 2024
2330df6
GA outputs ruff with github style
castelao Jun 27, 2024
163e63e
Adding (C4) flake8-comprehensions
castelao Jun 27, 2024
57ff41c
Adding rule (C90) mccabe
castelao Jun 27, 2024
2c4b4d5
Adding convention (C) and flake8-logging (LOG)
castelao Jun 27, 2024
e1a08ec
validate all codebase with super-linter
castelao Jun 27, 2024
f860ff6
Adding (SIM) flake8-simplify rules
castelao Jun 27, 2024
90a0af9
Adding (PERF) Perflint rules
castelao Jun 27, 2024
c843ae7
We don't need to run on the full code base anymore
castelao Jun 27, 2024
8180a82
clean: Removing implicit rules
castelao Jun 27, 2024
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
12 changes: 12 additions & 0 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ on:
push:
branches-ignore:
- 'gh-pages'
pull_request:
branches: [main]

jobs:
build:
Expand All @@ -28,3 +30,13 @@ jobs:
VALIDATE_YAML: false
castelao marked this conversation as resolved.
Show resolved Hide resolved
DEFAULT_BRANCH: main
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ruff:
name: Ruff
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: chartboost/ruff-action@v1
with:
version: 0.4.10
args: check --output-format=github
src: "./sup3r ./tests"
4 changes: 4 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ repos:
rev: v3.1.0
hooks:
- id: pylint
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.10
hooks:
- id: ruff
4,093 changes: 2,282 additions & 1,811 deletions pixi.lock

Large diffs are not rendered by default.

155 changes: 139 additions & 16 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,49 +71,172 @@ line-length = 79
indent-width = 4

target-version = "py38"
exclude = [
"CSV",
"ref.*?py",
]

[tool.ruff.lint]
fixable = ["ALL"]
preview = true
fixable = []
# preview = true
# logger-objects = []
task-tags = ["TODO", "FIXME", "XXX"]
select = [
castelao marked this conversation as resolved.
Show resolved Hide resolved
"A", # flake8-builtins
"ARG", # flake8-unused-arguments
"C",
"C4", # flake8-comprehensions
"C90", # mccabe
"COM", # flake8-commas
castelao marked this conversation as resolved.
Show resolved Hide resolved
"D", # pydocstyle
"E", # pycodestyle
"F", # Pyflakes
"G", # flake8-logging-format
"I", # isort
castelao marked this conversation as resolved.
Show resolved Hide resolved
"LOG", # flake8-logging
"N", # pep8-naming
"NPY", # numpy-specific
"PERF", # Perflint
"PL", # Pylint
"Q", # flake8-quotes
"SIM", # flake8-simplify
"UP", # pyupgrade
castelao marked this conversation as resolved.
Show resolved Hide resolved
"W", # Warning
]
castelao marked this conversation as resolved.
Show resolved Hide resolved

ignore = [
"B008", # function-call-in-default-argument
"B024", # abstract-base-class-without-abstract-method
"B028", # no-explicit-stacklevel
"B905", # zip-without-explicit-strict
# Currently don't conform but we might want to reconsider
"A001", # builtin-variable-shadowing
# Currently don't conform but we might want to reconsider
"A002", # builtin-argument-shadowing
"ARG002", # unused-method-argument
castelao marked this conversation as resolved.
Show resolved Hide resolved
"ARG003", # unused-class-method-argument
"ARG004", # unused-static-method-argument
"ARG005", # unused-lambda-argument
# "B008", # function-call-in-default-argument
# "B024", # abstract-base-class-without-abstract-method
# "B028", # no-explicit-stacklevel
# "B905", # zip-without-explicit-strict
"C408", # unnecessary-collection-call
"C414", # unnecessary-double-cast-or-process
"COM812", # missing-trailing-comma
"D105", # undocumented-magic-method
"D200", # fits-on-one-line
"D202", # no-blank-line-after-function
"D204", # one-blank-line-after-class
"D205", # blank-line-after-summary
"D207", # under-indentation
"D209", # new-line-after-last-paragraph
"D212", # multi-line-summary-first-line
"D213", # multi-line-summary-second-linek
# "D212", # multi-line-summary-first-line
castelao marked this conversation as resolved.
Show resolved Hide resolved
# "D213", # multi-line-summary-second-linek
"D400", # ends-in-period
"D401", # non-imperative-mood
"D413", # blank-line-after-last-section
"D415", # ends-in-punctuation
"E902", # io-error
"D404", # docstring-starts-with-this
# "D413", # blank-line-after-last-section
# "D415", # ends-in-punctuation
# "E902", # io-error
"FIX001", # line-contains-fixme
# We currently don't conform but we might want to reconsider
"G001", # logging-string-format
# We currently don't conform but we might want to reconsider
"G004", # logging-f-string
"I001", # unsorted-imports
"N802", # invalid-function-name
"N803", # invalid-argument-name
"N806", # non-lowercase-variable-in-function
# Consider conforming with NPY002
"NPY002", # numpy-legacy-random
"PERF102", # incorrect-dict-iterator
"PERF203", # try-except-in-loop
"PERF401", # manual-list-comprehension
"PLR0904", # too-many-public-methods
"PLR0912", # too-many-branches
"PLR0913", # too-many-arguments
"PLR0914", # too-many-locals
"PLR0915", # too-many-statements
"PLR1702", # too-many-nested-blocks
"PLR1704", # redefined-argument-from-local
"PLR2004", # magic-value-comparison
"PLW1514", # unspecified-encoding
"PLW2901", # redefined-loop-name
"Q000", # bad-quotes-inline-string
"Q004", # unnecessary-escaped-quote
"SIM108", # if-else-block-instead-of-if-exp
"SIM117", #multiple-with-statements
"SIM118", # in-dict-keys
"SIM211", # if-expr-with-false-true
"UP009", # utf8-encoding-declaration
"UP015", # redundant-open-modes
"UP032", # f-string
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one is for @grantbuster ;)

"UP038" # non-pep604-isinstance
# "UP038" # non-pep604-isinstance
]
# Ignored in pylint setup but missing on ruff. We shall delete from the
# following lines what is not intended to follow anymore.
# arguments-renamed
# consider-using-f-string
# raw-checker-failed
# bad-inline-option
# locally-disabled
# file-ignored
# suppressed-message
# useless-suppression
# deprecated-pragma
# protected-access
# redefined-outer-name
# redefined-builtin
# broad-except
# logging-format-interpolation
# logging-fstring-interpolation
# wrong-import-order
# wrong-import-position
# relative-beyond-top-level
# too-many-instance-attributes
# too-few-public-methods
# invalid-name
# import-error
# try-except-raise
# no-else-raise
# no-else-return
# unexpected-keyword-arg
# no-value-for-parameter
# too-many-lines
# arguments-differ
# import-outside-toplevel
# super-init-not-called
# isinstance-second-argument-not-valid-type
# inconsistent-return-statements
# no-else-break
# too-many-function-args
# redundant-keyword-arg
# c-extension-no-member

[tool.ruff.lint.mccabe]
# Flag errors (`C901`) whenever the complexity level exceeds 5.
max-complexity = 12

[tool.ruff.lint.per-file-ignores]
"__init__.py" = [
"F401", # unused-import
]
"docs/source/conf.py" = [
"E402", # unused-import
]
#"docs/source/conf.py" = [
# "E402", # unused-import
# ]

[tool.ruff.lint.pylint]
max-args = 5 # (PLR0913) Maximum number of arguments for function / method
max-bool-expr = 5 # ( PLR0916) Boolean in a single if statement
max-branches=12 # (PLR0912) branches allowed for a function or method body
max-locals=15 # (PLR0912) local variables allowed for a function or method body
max-nested-blocks = 5 # (PLR1702) nested blocks within a function or method body
max-public-methods=20 # (R0904) public methods allowed for a class
max-returns=6 # (PLR0911) return statements for a function or method body
max-statements=50 # (PLR0915) statements allowed for a function or method body

[tool.ruff.format]
quote-style = "single"
indent-style = "space"
# Consider adopting "lf" instead
castelao marked this conversation as resolved.
Show resolved Hide resolved
line-ending = "auto"

[tool.ruff.lint.pydocstyle]
convention = "numpy"
Expand Down Expand Up @@ -167,4 +290,4 @@ pytest = ">=5.2"
[tool.pixi.feature.dev.dependencies]
build = ">=0.6"
twine = ">=5.0"
ruff = ">=0.2"
ruff = ">=0.4"
2 changes: 1 addition & 1 deletion sup3r/bias/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
logger = logging.getLogger(__name__)


class FillAndSmoothMixin():
class FillAndSmoothMixin:
"""Fill and extend parameters for calibration on missing positions"""
def fill_and_smooth(self,
out,
Expand Down
2 changes: 1 addition & 1 deletion tests/data_handling/test_data_handling_h5.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
val_split = 0.2
dh_kwargs = {'target': target, 'shape': shape, 'max_delta': 20,
'sample_shape': sample_shape,
'lr_only_features': ('BVF*m', 'topography',),
'lr_only_features': ('BVF*m', 'topography'),
'temporal_slice': slice(None, None, 1),
'worker_kwargs': {'max_workers': 1}}
bh_kwargs = {'batch_size': 8, 'n_batches': 20,
Expand Down
2 changes: 1 addition & 1 deletion tests/data_handling/test_data_handling_nc.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
dh_kwargs = dict(target=target,
shape=shape,
max_delta=20,
lr_only_features=('BVF*m', 'topography',),
lr_only_features=('BVF*m', 'topography'),
sample_shape=sample_shape,
temporal_slice=slice(None, None, 1),
worker_kwargs=dict(max_workers=1),
Expand Down
6 changes: 3 additions & 3 deletions tests/forward_pass/test_forward_pass_exo.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def test_fwp_multi_step_spatial_model_topo_noskip():
max_workers = 1
fwp_chunk_shape = (4, 4, 8)
s_enhancements = [2, 2, 1]
s_enhance = np.product(s_enhancements)
s_enhance = np.prod(s_enhancements)

exo_kwargs = {
'topography': {
Expand Down Expand Up @@ -299,7 +299,7 @@ def test_fwp_multi_step_model_topo_noskip():
max_workers = 1
fwp_chunk_shape = (4, 4, 8)
s_enhancements = [2, 2, 3]
s_enhance = np.product(s_enhancements)
s_enhance = np.prod(s_enhancements)
t_enhance = 4

exo_kwargs = {
Expand Down Expand Up @@ -955,7 +955,7 @@ def test_fwp_multi_step_model_multi_exo():
max_workers = 1
fwp_chunk_shape = (4, 4, 8)
s_enhancements = [2, 2, 3]
s_enhance = np.product(s_enhancements)
s_enhance = np.prod(s_enhancements)
t_enhance = 4

exo_kwargs = {
Expand Down
2 changes: 1 addition & 1 deletion tests/output/test_output_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def test_h5_collect_mask(log=False):
(out_files, data, _, _, features, _, _, _, _, _, _) = out

CollectorH5.collect(out_files, fp_out, features=features)
indices = np.arange(np.product(data.shape[:2]))
indices = np.arange(np.prod(data.shape[:2]))
indices = indices[slice(-len(indices) // 2, None)]
removed = []
for _ in range(10):
Expand Down
4 changes: 2 additions & 2 deletions tests/utilities/test_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def test_weighted_box_sampler():
or chunks[5][0] <= slice_3.start <= chunks[5][-1])

shape = (1, 1)
weights = np.zeros(np.product(data.shape))
weights = np.zeros(np.prod(data.shape))
weights_4 = weights.copy()
weights_4[5] = 1

Expand Down Expand Up @@ -366,7 +366,7 @@ def test_t_coarsen():
"""Test temporal coarsening of 5D array"""
t_enhance = 4
hr_shape = (3, 10, 10, 48, 2)
arr = np.arange(np.product(hr_shape)).reshape(hr_shape).astype(float)
arr = np.arange(np.prod(hr_shape)).reshape(hr_shape).astype(float)

# test 4x temporal enhancement averaging
arr_lr = temporal_coarsening(arr, t_enhance=t_enhance, method='average')
Expand Down
Loading