Skip to content

Commit 42cf459

Browse files
committed
Update ruff lint select rules
1 parent bbfd74c commit 42cf459

36 files changed

Lines changed: 225 additions & 219 deletions

pyproject.toml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ output-format = "grouped"
7272
isort.lines-after-imports = 2
7373
select = [
7474
"C", # Complexity checks (e.g., McCabe complexity, comprehensions)
75-
# "ANN001", "ANN201", "ANN401", # flake8-annotations (required strict type annotations for public functions)
75+
"ANN001", "ANN201", "ANN401", # flake8-annotations (required strict type annotations for public functions)
7676
"S", # flake8-bandit (checks basic security issues in code)
77-
# "BLE", # flake8-blind-except (checks the except blocks that do not specify exception)
78-
# "FBT", # flake8-boolean-trap (ensure that boolean args can be used with kw only)
77+
"BLE", # flake8-blind-except (checks the except blocks that do not specify exception)
78+
"FBT", # flake8-boolean-trap (ensure that boolean args can be used with kw only)
7979
"E", # pycodestyle errors (PEP 8 style guide violations)
8080
"W", # pycodestyle warnings (e.g., extra spaces, indentation issues)
81-
# "DOC", # pydoclint issues (e.g., extra or missing return, yield, warnings)
81+
"DOC", # pydoclint issues (e.g., extra or missing return, yield, warnings)
8282
"A", # flake8-buitins (check variable and function names to not shadow builtins)
8383
"N", # Naming convention checks (e.g., PEP 8 variable and function names)
8484
"F", # Pyflakes errors (e.g., unused imports, undefined variables)
@@ -87,10 +87,11 @@ select = [
8787
"TID", # flake8-tidy-imports (Checks for banned or misplaced imports)
8888
"UP", # pyupgrade (Automatically updates old Python syntax)
8989
"YTT", # flake8-2020 (Detects outdated Python 2/3 compatibility issues)
90+
"PTH", # flake8-use-pathlib (Suggests using pathlib over os.path, open, etc.)
9091
"FLY", # flynt (Converts old-style string formatting to f-strings)
9192
"PIE", # flake8-pie
92-
# "PL", # pylint
93-
# "RUF", # Ruff-specific rules (Additional optimizations and best practices)
93+
"PL", # pylint
94+
"RUF", # Ruff-specific rules (Additional optimizations and best practices)
9495
]
9596

9697
ignore = [

src/lasso/diffcrash/diffcrash_run.py

Lines changed: 49 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import sys
1010
import time
1111
import typing
12+
from collections.abc import Sequence
1213
from concurrent import futures
1314
from pathlib import Path
1415
from typing import Union
@@ -38,7 +39,7 @@
3839
]
3940

4041

41-
def get_application_header():
42+
def get_application_header() -> str:
4243
"""Prints the header of the command line tool"""
4344

4445
return """
@@ -49,7 +50,7 @@ def get_application_header():
4950
"""
5051

5152

52-
def str2bool(value) -> bool:
53+
def str2bool(value: str) -> bool:
5354
"""Converts some value from the cmd line to a boolean
5455
5556
Parameters
@@ -64,14 +65,14 @@ def str2bool(value) -> bool:
6465

6566
if isinstance(value, bool):
6667
return value
67-
if value.lower() in ("yes", "true", "t", "y", "1"):
68+
if value.lower() in {"yes", "true", "t", "y", "1"}:
6869
return True
69-
if value.lower() in ("no", "false", "f", "n", "0"):
70+
if value.lower() in {"no", "false", "f", "n", "0"}:
7071
return False
7172
raise argparse.ArgumentTypeError("Boolean value expected.")
7273

7374

74-
def parse_diffcrash_args():
75+
def parse_diffcrash_args() -> argparse.Namespace:
7576
"""Parse the arguments from the command line
7677
7778
Returns
@@ -166,7 +167,7 @@ def parse_diffcrash_args():
166167
return parser.parse_args(sys.argv[1:])
167168

168169

169-
def run_subprocess(args):
170+
def run_subprocess(args: Union[list[str], str]) -> int:
170171
"""Run a subprocess with the specified arguments
171172
172173
Parameters:
@@ -200,10 +201,10 @@ def __init__(
200201
exclude_runs: typing.Sequence[str],
201202
diffcrash_home: str = "",
202203
use_id_mapping: bool = False,
203-
config_file: str = None,
204-
parameter_file: str = None,
204+
config_file: typing.Optional[str] = None,
205+
parameter_file: typing.Optional[str] = None,
205206
n_processes: int = 1,
206-
logfile_dir: str = None,
207+
logfile_dir: typing.Optional[str] = None,
207208
):
208209
"""Object handling a diffcrash run
209210
@@ -251,7 +252,7 @@ def __init__(
251252

252253
# diffcrash home
253254
self.diffcrash_home = Path(self._parse_diffcrash_home(diffcrash_home))
254-
self.diffcrash_home = self.diffcrash_home / "bin"
255+
self.diffcrash_home /= "bin"
255256
self.diffcrash_lib = self.diffcrash_home.parent / "lib"
256257

257258
if platform.system() == "Linux":
@@ -310,7 +311,7 @@ def _setup_logger(self) -> logging.Logger:
310311

311312
return logger
312313

313-
def _parse_diffcrash_home(self, diffcrash_home) -> str:
314+
def _parse_diffcrash_home(self, diffcrash_home: str) -> str:
314315
diffcrash_home_ok = len(diffcrash_home) != 0
315316

316317
msg = self._msg_option.format("diffcrash-home", diffcrash_home)
@@ -327,7 +328,7 @@ def _parse_diffcrash_home(self, diffcrash_home) -> str:
327328

328329
return diffcrash_home
329330

330-
def _parse_crash_code(self, crash_code) -> str:
331+
def _parse_crash_code(self, crash_code: str) -> str:
331332
# these guys are allowed
332333
valid_crash_codes = ["dyna", "radioss", "pam"]
333334

@@ -344,12 +345,12 @@ def _parse_crash_code(self, crash_code) -> str:
344345

345346
return crash_code
346347

347-
def _parse_reference_run(self, reference_run) -> str:
348-
reference_run_ok = Path(reference_run).is_file()
348+
def _parse_reference_run(self, reference_run: str) -> str:
349+
reference_run_ok: bool = Path(reference_run).is_file()
349350

350351
msg = self._msg_option.format("reference-run", reference_run)
351-
print(str_info(msg))
352-
self.logger.info(msg)
352+
print(str_info(msg=msg))
353+
self.logger.info(msg=msg)
353354

354355
if not reference_run_ok:
355356
err_msg = f"Filepath '{reference_run}' is not a file."
@@ -358,14 +359,14 @@ def _parse_reference_run(self, reference_run) -> str:
358359

359360
return reference_run
360361

361-
def _parse_use_id_mapping(self, use_id_mapping) -> bool:
362+
def _parse_use_id_mapping(self, use_id_mapping: bool) -> bool:
362363
msg = self._msg_option.format("use-id-mapping", use_id_mapping)
363364
print(str_info(msg))
364365
self.logger.info(msg)
365366

366367
return use_id_mapping
367368

368-
def _parse_project_dir(self, project_dir):
369+
def _parse_project_dir(self, project_dir: str) -> Path:
369370
project_dir = Path(project_dir).resolve()
370371

371372
msg = self._msg_option.format("project-dir", project_dir)
@@ -376,9 +377,9 @@ def _parse_project_dir(self, project_dir):
376377

377378
def _parse_simulation_runs(
378379
self,
379-
simulation_run_patterns: typing.Sequence[str],
380+
simulation_run_patterns: Sequence[str],
380381
reference_run: str,
381-
exclude_runs: typing.Sequence[str],
382+
exclude_runs: Sequence[str],
382383
):
383384
# search all denoted runs
384385
simulation_runs = []
@@ -403,10 +404,10 @@ def _parse_simulation_runs(
403404
simulation_runs.remove(reference_run)
404405

405406
# sort it because we can!
406-
def atoi(text):
407+
def atoi(text: str) -> Union[int, str]:
407408
return int(text) if text.isdigit() else text
408409

409-
def natural_keys(text):
410+
def natural_keys(text: str) -> list[Union[int, str]]:
410411
return [atoi(c) for c in re.split(r"(\d+)", text)]
411412

412413
simulation_runs = sorted(simulation_runs, key=natural_keys)
@@ -435,37 +436,37 @@ def natural_keys(text):
435436
return simulation_runs
436437

437438
def _parse_config_file(self, config_file) -> Union[str, None]:
438-
_msg_config_file = ""
439+
msg_config_file = ""
439440
if len(config_file) > 0 and not Path(config_file).is_file():
440441
config_file = None
441-
_msg_config_file = f"Can not find config file '{config_file}'"
442+
msg_config_file = f"Can not find config file '{config_file}'"
442443

443444
# missing config file
444445
else:
445446
config_file = None
446-
_msg_config_file = (
447+
msg_config_file = (
447448
"Config file missing. Consider specifying the path with the option '--config-file'."
448449
)
449450

450451
msg = self._msg_option.format("config-file", config_file)
451452
print(str_info(msg))
452453
self.logger.info(msg)
453454

454-
if _msg_config_file:
455-
print(str_warn(_msg_config_file))
456-
self.logger.warning(_msg_config_file)
455+
if msg_config_file:
456+
print(str_warn(msg_config_file))
457+
self.logger.warning(msg_config_file)
457458

458459
return config_file
459460

460461
def _parse_parameter_file(self, parameter_file) -> Union[None, str]:
461-
_msg_parameter_file = ""
462+
msg_parameter_file = ""
462463
if len(parameter_file) > 0 and not Path(parameter_file).is_file():
463464
parameter_file = None
464-
_msg_parameter_file = f"Can not find parameter file '{parameter_file}'"
465+
msg_parameter_file = f"Can not find parameter file '{parameter_file}'"
465466
# missing parameter file
466467
else:
467468
parameter_file = None
468-
_msg_parameter_file = (
469+
msg_parameter_file = (
469470
"Parameter file missing. Consider specifying the "
470471
"path with the option '--parameter-file'."
471472
)
@@ -474,9 +475,9 @@ def _parse_parameter_file(self, parameter_file) -> Union[None, str]:
474475
print(str_info(msg))
475476
self.logger.info(msg)
476477

477-
if _msg_parameter_file:
478-
print(str_warn(_msg_parameter_file))
479-
self.logger.warning(_msg_parameter_file)
478+
if msg_parameter_file:
479+
print(str_warn(msg_parameter_file))
480+
self.logger.warning(msg_parameter_file)
480481

481482
return parameter_file
482483

@@ -490,7 +491,7 @@ def _parse_n_processes(self, n_processes) -> int:
490491

491492
return n_processes
492493

493-
def create_project_dirs(self):
494+
def create_project_dirs(self) -> None:
494495
"""Creates all project relevant directores
495496
496497
Notes
@@ -502,7 +503,7 @@ def create_project_dirs(self):
502503
os.makedirs(self.project_dir, exist_ok=True)
503504
os.makedirs(self.logfile_dir, exist_ok=True)
504505

505-
def run_setup(self, pool: futures.ThreadPoolExecutor):
506+
def run_setup(self, pool: futures.ThreadPoolExecutor) -> None:
506507
"""Run diffcrash setup
507508
508509
Parameters
@@ -606,7 +607,7 @@ def run_setup(self, pool: futures.ThreadPoolExecutor):
606607
print(str_success(msg))
607608
self.logger.info(msg)
608609

609-
def run_import(self, pool: futures.ThreadPoolExecutor):
610+
def run_import(self, pool: futures.ThreadPoolExecutor) -> None:
610611
"""Run diffcrash import of runs
611612
612613
Parameters
@@ -707,11 +708,11 @@ def run_import(self, pool: futures.ThreadPoolExecutor):
707708
n_failed_runs = 0
708709
for i_run, return_code in enumerate(return_codes):
709710
if return_code != 0:
710-
_err_msg = str_error(
711+
err_msg_ = str_error(
711712
f"Run {i_run} failed to import with error code '{return_code}'."
712713
)
713-
print(str_error(_err_msg))
714-
self.logger.error(_err_msg)
714+
print(str_error(err_msg_))
715+
self.logger.error(err_msg_)
715716
n_failed_runs += 1
716717

717718
err_msg = f"Running Imports ... done in {time.time() - start_time:.2f}s "
@@ -744,7 +745,7 @@ def run_import(self, pool: futures.ThreadPoolExecutor):
744745
# print success
745746
print(str_success(f"Running Imports ... done in {time.time() - start_time:.2f}s "))
746747

747-
def run_math(self, pool: futures.ThreadPoolExecutor):
748+
def run_math(self, pool: futures.ThreadPoolExecutor) -> None:
748749
"""Run diffcrash math
749750
750751
Parameters
@@ -798,7 +799,7 @@ def run_math(self, pool: futures.ThreadPoolExecutor):
798799
print(str_success(msg))
799800
self.logger.info(msg)
800801

801-
def run_export(self, pool: futures.ThreadPoolExecutor):
802+
def run_export(self, pool: futures.ThreadPoolExecutor) -> None:
802803
"""Run diffcrash export
803804
804805
Parameters
@@ -890,7 +891,7 @@ def run_export(self, pool: futures.ThreadPoolExecutor):
890891
print(str_success(msg))
891892
self.logger.info(msg)
892893

893-
def run_matrix(self, pool: futures.ThreadPoolExecutor):
894+
def run_matrix(self, pool: futures.ThreadPoolExecutor) -> None:
894895
"""Run diffcrash matrix
895896
896897
Parameters
@@ -954,7 +955,7 @@ def run_matrix(self, pool: futures.ThreadPoolExecutor):
954955
print(str_success(msg))
955956
self.logger.info(msg)
956957

957-
def run_eigen(self, pool: futures.ThreadPoolExecutor):
958+
def run_eigen(self, pool: futures.ThreadPoolExecutor) -> None:
958959
"""Run diffcrash eigen
959960
960961
Parameters
@@ -1016,7 +1017,7 @@ def run_eigen(self, pool: futures.ThreadPoolExecutor):
10161017
print(str_success(msg))
10171018
self.logger.info(msg)
10181019

1019-
def run_merge(self, pool: futures.ThreadPoolExecutor):
1020+
def run_merge(self, pool: futures.ThreadPoolExecutor) -> None:
10201021
"""Run diffcrash merge
10211022
10221023
Parameters
@@ -1167,7 +1168,7 @@ def _create_matrix_input_file(self, directory: Path) -> Path:
11671168

11681169
return filepath
11691170

1170-
def clear_project_dir(self):
1171+
def clear_project_dir(self) -> None:
11711172
"""Clears the entire project dir"""
11721173

11731174
# disable logging
@@ -1318,11 +1319,11 @@ def check_if_logfiles_show_success(self, pattern: str) -> list[str]:
13181319
list with messages of failed log checks
13191320
"""
13201321

1321-
_msg_logfile_nok = str_error("Logfile '{0}' reports no success.")
1322+
msg_logfile_nok = str_error("Logfile '{0}' reports no success.")
13221323
messages = []
13231324

13241325
for filepath in self.logfile_dir.glob(pattern):
13251326
if not self.is_logfile_successful(filepath):
1326-
messages.append(_msg_logfile_nok.format(filepath))
1327+
messages.append(msg_logfile_nok.format(filepath))
13271328

13281329
return messages

src/lasso/diffcrash/run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def _parse_stages(start_stage: str, end_stage: str):
3939
return start_stage_index, end_stage_index
4040

4141

42-
def main():
42+
def main() -> None:
4343
"""Main function for running diffcrash"""
4444

4545
# parse command line stuff

0 commit comments

Comments
 (0)