Skip to content

Commit cc26b34

Browse files
committed
style: fix auto-fixable PTH issues
Remove the CI lint rule exclusions for the rules that now pass. Signed-off-by: James McCorrie <[email protected]>
1 parent a5290dc commit cc26b34

File tree

12 files changed

+56
-47
lines changed

12 files changed

+56
-47
lines changed

ruff-ci.toml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,9 @@ ignore = [
8181
"PLW2901",
8282
"PT009",
8383
"PT011",
84-
"PTH100",
85-
"PTH101",
8684
"PTH103",
87-
"PTH107",
88-
"PTH109",
89-
"PTH110",
9085
"PTH116",
9186
"PTH118",
92-
"PTH120",
9387
"PTH123",
9488
"PYI024",
9589
"RUF001",

src/dvsim/cli.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def copy_repo(src, dest) -> None:
218218

219219
# Supply `.gitignore` from the src area to skip temp files.
220220
ignore_patterns_file = os.path.join(src, ".gitignore")
221-
if os.path.exists(ignore_patterns_file):
221+
if Path(ignore_patterns_file).exists():
222222
# TODO: hack - include hw/foundry since it is excluded in .gitignore.
223223
rsync_cmd += [
224224
"--include=hw/foundry",
@@ -831,7 +831,7 @@ def main() -> None:
831831
log_level = log.DEBUG
832832
log.basicConfig(format=log_format, level=log_level)
833833

834-
if not os.path.exists(args.cfg):
834+
if not Path(args.cfg).exists():
835835
log.fatal("Path to config file %s appears to be invalid.", args.cfg)
836836
sys.exit(1)
837837

@@ -849,7 +849,7 @@ def main() -> None:
849849
# core files.
850850
(Path(args.scratch_root) / "FUSESOC_IGNORE").touch()
851851

852-
args.cfg = os.path.abspath(args.cfg)
852+
args.cfg = Path(args.cfg).resolve()
853853
if args.remote:
854854
cfg_path = args.cfg.replace(proj_root_src + "/", "")
855855
args.cfg = os.path.join(proj_root, cfg_path)

src/dvsim/flow/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def __init__(self, flow_cfg_file, hjson_data, args, mk_config) -> None:
102102
self.revision = ""
103103
self.results_server_prefix = ""
104104
self.results_server_cmd = ""
105-
self.css_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), "style.css")
105+
self.css_file = os.path.join(Path(os.path.realpath(__file__)).parent, "style.css")
106106
# `self.results_*` below will be updated after `self.rel_path` and
107107
# `self.scratch_base_root` variables are updated.
108108
self.results_dir = ""
@@ -140,7 +140,7 @@ def __init__(self, flow_cfg_file, hjson_data, args, mk_config) -> None:
140140
self._load_child_cfg(entry, mk_config)
141141

142142
if self.rel_path == "":
143-
self.rel_path = os.path.dirname(self.flow_cfg_file).replace(self.proj_root + "/", "")
143+
self.rel_path = Path(self.flow_cfg_file).parent.replace(self.proj_root + "/", "")
144144

145145
# Process overrides before substituting wildcards
146146
self._process_overrides()

src/dvsim/flow/factory.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# SPDX-License-Identifier: Apache-2.0
44

55
import logging as log
6-
import os
6+
import pathlib
77
import sys
88

99
from dvsim.flow.cdc import CdcCfg
@@ -27,7 +27,7 @@ def _load_cfg(path, initial_values):
2727
# Set the `self_dir` template variable to the path of the currently
2828
# processed Hjson file.
2929
assert "self_dir" in initial_values
30-
initial_values["self_dir"] = os.path.dirname(path)
30+
initial_values["self_dir"] = pathlib.Path(path).parent
3131

3232
# Start by loading up the hjson file and any included files
3333
hjson_data = load_hjson(path, initial_values)
@@ -105,7 +105,7 @@ def make_cfg(path, args, proj_root):
105105
"""
106106
initial_values = {
107107
"proj_root": proj_root,
108-
"self_dir": os.path.dirname(path),
108+
"self_dir": pathlib.Path(path).parent,
109109
}
110110
if args.tool is not None:
111111
initial_values["tool"] = args.tool

src/dvsim/launcher/base.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,7 @@ def _dump_env_vars(self, exports) -> None:
201201
encoding="UTF-8",
202202
errors="surrogateescape",
203203
) as f:
204-
for var in sorted(exports.keys()):
205-
f.write(f"{var}={exports[var]}\n")
204+
f.writelines(f"{var}={exports[var]}\n" for var in sorted(exports.keys()))
206205

207206
def _pre_launch(self) -> None:
208207
"""Do pre-launch activities.

src/dvsim/launcher/nc.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import datetime
66
import logging as log
77
import os
8+
import pathlib
89
import subprocess
910
import sys
1011

@@ -43,7 +44,7 @@ def create_run_sh(self, full_path, cmd) -> None:
4344
]
4445
with open(run_file, "w") as f:
4546
f.write("\n".join(lines))
46-
os.chmod(run_file, 0o755)
47+
pathlib.Path(run_file).chmod(0o755)
4748

4849
def get_submit_cmd(self):
4950
exetool = self.deploy.sim_cfg.tool

src/dvsim/launcher/sge/engine.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
import subprocess
1414
import time
1515

16-
from dvsim.launcher.sge.qsubopts import QSubOptions
17-
1816

1917
class _JobData:
2018
"""Internal helper class to manage job data from qstat."""

src/dvsim/launcher/sge/launcher.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"""SgeLauncher Class."""
66

77
import os
8+
import pathlib
89
import shlex
910
import subprocess
1011
from subprocess import PIPE, Popen
@@ -101,15 +102,14 @@ def poll(self):
101102
return "D"
102103
# -------------------------------------
103104
# copy SGE jobb results to log file
104-
if os.path.exists(self.deploy.get_log_path() + ".sge"):
105+
if pathlib.Path(self.deploy.get_log_path() + ".sge").exists():
105106
file1 = open(self.deploy.get_log_path() + ".sge", errors="replace")
106107
lines = file1.readlines()
107108
file1.close()
108109
f = open(self.deploy.get_log_path(), "a", encoding="UTF-8", errors="surrogateescape")
109-
for line in lines:
110-
f.write(line)
110+
f.writelines(lines)
111111
f.flush()
112-
os.remove(self.deploy.get_log_path() + ".sge")
112+
pathlib.Path(self.deploy.get_log_path() + ".sge").unlink()
113113
f.close()
114114
# -------------------------------------
115115

src/dvsim/launcher/sge/qsubopts.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"""
1515

1616
import argparse
17+
import pathlib
1718

1819

1920
class QSubOptions:
@@ -1933,7 +1934,7 @@ def execute(self, mode="local", path=""):
19331934
args = getattr(self.args, "command_args", [])
19341935
args = getattr(self.args, "xterm_args", args)
19351936
# ---------------- command file -------------
1936-
cwd = os.getcwd()
1937+
cwd = pathlib.Path.cwd()
19371938
command_file = cwd + "/command_file_" + str(os.getpid()) + "_" + test_id
19381939
try:
19391940
with open(command_file, "w") as f_command:
@@ -1944,7 +1945,7 @@ def execute(self, mode="local", path=""):
19441945
error_msg = "Error: problem with open File: " + str(f_command)
19451946
raise OSError(error_msg)
19461947

1947-
os.chmod(command_file, 0o0777)
1948+
pathlib.Path(command_file).chmod(0o0777)
19481949
exestring = " ".join([program, *options, command_file, *args])
19491950
exestring = exestring.replace("-pe lammpi 1", "")
19501951
exestring = exestring.replace("-slot", "-pe make")

src/dvsim/launcher/slurm.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import logging as log
66
import os
7+
import pathlib
78
import shlex
89
import shutil
910
import subprocess
@@ -96,7 +97,7 @@ def poll(self):
9697
return "D"
9798

9899
# Copy slurm job results to log file
99-
if os.path.exists(self.slurm_log_file):
100+
if pathlib.Path(self.slurm_log_file).exists():
100101
try:
101102
with open(self.slurm_log_file) as slurm_file:
102103
try:
@@ -108,7 +109,7 @@ def poll(self):
108109
msg,
109110
)
110111
# Remove the temporary file from the slurm process
111-
os.remove(self.slurm_log_file)
112+
pathlib.Path(self.slurm_log_file).unlink()
112113
except OSError as e:
113114
msg = f"File Error: {e} when handling {self.slurm_log_file}"
114115
raise LauncherError(msg)

0 commit comments

Comments
 (0)