Skip to content

Commit 4870f02

Browse files
authored
Fix legacy ruff errors and enable corresponding rules for future linting (#134)
* fix ruff format * manual ruff fixes, addressing all RET errors * fix or ignore mypy errors * fix tests * fix typos and mypy * fix linting * revert print removal * only ignore subset of pylint refactor rules * fix legacy bug mentioned in #134 (comment)
1 parent 189518f commit 4870f02

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+771
-944
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ default_language_version:
33
exclude: ^(.github/|tests/test_data/abinit/)
44
repos:
55
- repo: https://github.com/charliermarsh/ruff-pre-commit
6-
rev: v0.4.5
6+
rev: v0.4.6
77
hooks:
88
- id: ruff
99
args: [--fix]
@@ -39,7 +39,7 @@ repos:
3939
- types-paramiko
4040
- pydantic~=2.0
4141
- repo: https://github.com/codespell-project/codespell
42-
rev: v2.2.6
42+
rev: v2.3.0
4343
hooks:
4444
- id: codespell
4545
stages: [commit, commit-msg]

CODE_OF_CONDUCT.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
We as members, contributors, and leaders pledge to make participation in our
77
community a harassment-free experience for everyone, regardless of age, body
88
size, visible or invisible disability, ethnicity, sex characteristics, gender
9-
identity and expression, level of experience, education, socio-economic status,
9+
identity and expression, level of experience, education, socioeconomic status,
1010
nationality, personal appearance, race, caste, color, religion, or sexual
1111
identity and orientation.
1212

doc/source/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#
1+
# ruff: noqa: INP001
22
# Configuration file for the Sphinx documentation builder.
33
#
44
# This file does only contain a selection of the most common options. For a
@@ -22,7 +22,7 @@
2222
# -- Project information -----------------------------------------------------
2323

2424
project = "Jobflow Remote"
25-
copyright = "2023, Matgenix SRL"
25+
copyright = "2023, Matgenix SRL" # noqa: A001
2626
author = "Guido Petretto, Matthew Evans, David Waroquiers"
2727

2828

pyproject.toml

Lines changed: 8 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,10 @@ target-version = "py39"
7373
[tool.ruff.lint]
7474
select = ["ALL"]
7575
ignore = [
76-
"A001",
77-
"A002",
7876
"ANN", # TODO fix all ANN errors
7977
"ARG", # TODO fix unused method argument
80-
"B007",
81-
"B028",
82-
"B904",
8378
"BLE001",
8479
"C408", # Unnecessary (dict/list/tuple) call - remove call
85-
"C416",
86-
"C419",
8780
"C901", # function too complex
8881
"COM812", # trailing comma missing
8982
"D",
@@ -95,57 +88,34 @@ ignore = [
9588
"FA100", # TODO fix FA errors
9689
"FBT001",
9790
"FBT002",
98-
"FBT003",
9991
"FIX002",
10092
"G004", # logging uses fstring
101-
"G201",
102-
"INP001",
10393
"ISC001",
10494
"N802", # TODO maybe fix these
105-
"N805",
106-
"N818",
10795
"PD011", # pandas-use-of-dot-values
108-
"PERF102",
10996
"PERF203", # try-except-in-loop
110-
"PERF401",
11197
"PGH003",
112-
"PGH004",
113-
"PLR", # pylint-refactor
114-
"PLW0602",
115-
"PLW0603",
116-
"PLW2901",
117-
"PT003",
98+
"PLR0911", # too many returns
99+
"PLR0912", # too many branches
100+
"PLR0913", # too many arguments
101+
"PLR0915", # too many statements
102+
"PLR2004", # magic value used in comparison
118103
"PT004", # pytest-missing-fixture-name-underscore
119104
"PT006", # pytest-parametrize-names-wrong-type
120105
"PT013", # pytest-incorrect-pytest-import
121106
"PTH", # prefer Pathlib to os.path
122-
"PYI024",
123-
"RET",
124-
"RET504",
125-
"RUF005",
126-
"RUF012",
127107
"RUF013", # implicit-optional
128-
"RUF015",
129108
"S106",
130109
"S110",
131-
"S112",
132110
"S311",
133111
"S324", # use of insecure hash function
134112
"S507", # paramiko auto trust
135113
"S602",
136-
"S603",
137-
"S607",
138-
"SIM102",
139-
"SIM105",
140-
"SIM108",
141-
"SIM117",
114+
"SIM105", # contextlib.suppress(Exception) instead of try-except
142115
"SLF", # private member accessed outside class
143-
"SLOT000",
144-
"T201",
145-
"TCH",
116+
"T201", # print statement
146117
"TD", # TODOs
147-
"TRY", # long message outside exception class
148-
"UP031",
118+
"TRY003", # long message outside exception class
149119
]
150120
pydocstyle.convention = "numpy"
151121
isort.known-first-party = ["jobflow_remote"]
@@ -159,7 +129,6 @@ docstring-code-format = true
159129
"**/tests/*" = ["INP001", "S101"]
160130
"**/testing/*" = ["S101"]
161131

162-
163132
[tool.mypy]
164133
ignore_missing_imports = true
165134
strict_optional = false

src/jobflow_remote/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""jobflow-remote is a python package to run jobflow workflows on remote resources"""
1+
"""jobflow-remote is a python package to run jobflow workflows on remote resources."""
22

33
from jobflow_remote._version import __version__
44
from jobflow_remote.config.jobconfig import set_run_config

src/jobflow_remote/cli/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# ruff: noqa: F401
21
# Import the submodules with a local app to register them to the main app
32
import jobflow_remote.cli.admin
43
import jobflow_remote.cli.execution

src/jobflow_remote/cli/admin.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def reset(
5353
),
5454
] = 25,
5555
force: force_opt = False,
56-
):
56+
) -> None:
5757
"""
5858
Reset the jobflow database.
5959
WARNING: deletes all the data. These could not be retrieved anymore.
@@ -73,7 +73,7 @@ def reset(
7373
confirmed = Confirm.ask(text, default=False)
7474
if not confirmed:
7575
raise typer.Exit(0)
76-
with loading_spinner(False) as progress:
76+
with loading_spinner(processing=False) as progress:
7777
progress.add_task(description="Resetting the DB...", total=None)
7878
jc = get_job_controller()
7979
done = jc.reset(reset_output=reset_output, max_limit=max_limit)
@@ -94,11 +94,11 @@ def remove_lock(
9494
start_date: start_date_opt = None,
9595
end_date: end_date_opt = None,
9696
force: force_opt = False,
97-
):
97+
) -> None:
9898
"""
9999
DEPRECATED: use unlock instead
100100
Forcibly removes the lock from the documents of the selected jobs.
101-
WARNING: can lead to inconsistencies if the processes is actually running
101+
WARNING: can lead to inconsistencies if the processes is actually running.
102102
"""
103103
out_console.print(
104104
"remove-lock command has been DEPRECATED. Use unlock instead.",
@@ -123,17 +123,17 @@ def unlock(
123123
start_date: start_date_opt = None,
124124
end_date: end_date_opt = None,
125125
force: force_opt = False,
126-
):
126+
) -> None:
127127
"""
128128
Forcibly removes the lock from the documents of the selected jobs.
129-
WARNING: can lead to inconsistencies if the processes is actually running
129+
WARNING: can lead to inconsistencies if the processes is actually running.
130130
"""
131131
job_ids_indexes = get_job_ids_indexes(job_id)
132132

133133
jc = get_job_controller()
134134

135135
if not force:
136-
with loading_spinner(False) as progress:
136+
with loading_spinner(processing=False) as progress:
137137
progress.add_task(
138138
description="Checking the number of locked documents...", total=None
139139
)
@@ -158,7 +158,7 @@ def unlock(
158158
if not confirmed:
159159
raise typer.Exit(0)
160160

161-
with loading_spinner(False) as progress:
161+
with loading_spinner(processing=False) as progress:
162162
progress.add_task(description="Unlocking jobs...", total=None)
163163

164164
num_unlocked = jc.unlock_jobs(
@@ -181,17 +181,17 @@ def unlock_flow(
181181
start_date: start_date_opt = None,
182182
end_date: end_date_opt = None,
183183
force: force_opt = False,
184-
):
184+
) -> None:
185185
"""
186186
Forcibly removes the lock from the documents of the selected jobs.
187-
WARNING: can lead to inconsistencies if the processes is actually running
187+
WARNING: can lead to inconsistencies if the processes is actually running.
188188
"""
189189
job_ids_indexes = get_job_ids_indexes(job_id)
190190

191191
jc = get_job_controller()
192192

193193
if not force:
194-
with loading_spinner(False) as progress:
194+
with loading_spinner(processing=False) as progress:
195195
progress.add_task(
196196
description="Checking the number of locked documents...", total=None
197197
)
@@ -217,7 +217,7 @@ def unlock_flow(
217217
if not confirmed:
218218
raise typer.Exit(0)
219219

220-
with loading_spinner(False) as progress:
220+
with loading_spinner(processing=False) as progress:
221221
progress.add_task(description="Unlocking flows...", total=None)
222222

223223
num_unlocked = jc.unlock_flows(

src/jobflow_remote/cli/execution.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,8 @@ def run(
2323
help="The path to the folder where the files of the job to run will be executed",
2424
),
2525
] = ".",
26-
):
27-
"""
28-
Run the Job in the selected folder based on the
29-
"""
26+
) -> None:
27+
"""Run the Job in the selected folder based on the."""
3028
run_remote_job(run_dir)
3129

3230

@@ -78,10 +76,8 @@ def run_batch(
7876
help=("The maximum number of jobs that will be executed by the batch job"),
7977
),
8078
] = None,
81-
):
82-
"""
83-
Run Jobs in batch mode
84-
"""
79+
) -> None:
80+
"""Run Jobs in batch mode."""
8581
run_batch_jobs(
8682
base_run_dir,
8783
files_dir,

src/jobflow_remote/cli/flow.py

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,8 @@ def flows_list(
6161
max_results: max_results_opt = 100,
6262
sort: sort_opt = SortOption.UPDATED_ON,
6363
reverse_sort: reverse_sort_flag_opt = False,
64-
):
65-
"""
66-
Get the list of Jobs in the database
67-
"""
64+
) -> None:
65+
"""Get the list of Jobs in the database."""
6866
check_incompatible_opt({"start_date": start_date, "days": days, "hours": hours})
6967
check_incompatible_opt({"end_date": end_date, "days": days, "hours": hours})
7068

@@ -90,12 +88,11 @@ def flows_list(
9088

9189
table = get_flow_info_table(flows_info, verbosity=verbosity)
9290

93-
if SETTINGS.cli_suggestions:
94-
if max_results and len(flows_info) == max_results:
95-
out_console.print(
96-
f"The number of Flows printed is limited by the maximum selected: {max_results}",
97-
style="yellow",
98-
)
91+
if SETTINGS.cli_suggestions and max_results and len(flows_info) == max_results:
92+
out_console.print(
93+
f"The number of Flows printed is limited by the maximum selected: {max_results}",
94+
style="yellow",
95+
)
9996

10097
out_console.print(table)
10198

@@ -130,10 +127,8 @@ def delete(
130127
help="Also delete the outputs of the Jobs in the output Store",
131128
),
132129
] = False,
133-
):
134-
"""
135-
Permanently delete Flows from the database
136-
"""
130+
) -> None:
131+
"""Permanently delete Flows from the database"""
137132
check_incompatible_opt({"start_date": start_date, "days": days, "hours": hours})
138133
check_incompatible_opt({"end_date": end_date, "days": days, "hours": hours})
139134

@@ -145,7 +140,7 @@ def delete(
145140
# the verbosity value will be decreased by one: the first is to enable
146141
# initial print
147142

148-
with loading_spinner(False) as progress:
143+
with loading_spinner(processing=False) as progress:
149144
progress.add_task(description="Fetching data...", total=None)
150145
flows_info = jc.get_flows_info(
151146
job_ids=job_id,
@@ -180,7 +175,7 @@ def delete(
180175
raise typer.Exit(0)
181176

182177
to_delete = [fi.flow_id for fi in flows_info]
183-
with loading_spinner(False) as progress:
178+
with loading_spinner(processing=False) as progress:
184179
progress.add_task(description="Deleting...", total=None)
185180

186181
jc.delete_flows(flow_ids=to_delete, delete_output=delete_output)
@@ -194,10 +189,8 @@ def delete(
194189
def flow_info(
195190
flow_db_id: flow_db_id_arg,
196191
job_id_flag: job_flow_id_flag_opt = False,
197-
):
198-
"""
199-
Provide detailed information on a Flow
200-
"""
192+
) -> None:
193+
"""Provide detailed information on a Flow."""
201194
db_id, jf_id = get_job_db_ids(flow_db_id, None)
202195
db_ids = job_ids = flow_ids = None
203196
if db_id is not None:
@@ -259,10 +252,8 @@ def graph(
259252
help="Print the mermaid graph",
260253
),
261254
] = False,
262-
):
263-
"""
264-
Provide detailed information on a Flow
265-
"""
255+
) -> None:
256+
"""Provide detailed information on a Flow."""
266257
db_id, jf_id = get_job_db_ids(flow_db_id, None)
267258
db_ids = job_ids = flow_ids = None
268259
if db_id is not None:

src/jobflow_remote/cli/formatting.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,21 @@
22

33
import datetime
44
import time
5+
from typing import TYPE_CHECKING
56

67
from monty.json import jsanitize
78
from rich.scope import render_scope
89
from rich.table import Table
910
from rich.text import Text
1011

1112
from jobflow_remote.cli.utils import ReprStr, fmt_datetime
12-
from jobflow_remote.config.base import ExecutionConfig, WorkerBase
13-
from jobflow_remote.jobs.data import FlowInfo, JobDoc, JobInfo
1413
from jobflow_remote.jobs.state import JobState
1514
from jobflow_remote.utils.data import convert_utc_time
1615

16+
if TYPE_CHECKING:
17+
from jobflow_remote.config.base import ExecutionConfig, WorkerBase
18+
from jobflow_remote.jobs.data import FlowInfo, JobDoc, JobInfo
19+
1720

1821
def get_job_info_table(jobs_info: list[JobInfo], verbosity: int):
1922
time_zone_str = f" [{time.tzname[0]}]"

0 commit comments

Comments
 (0)