Skip to content

Commit 94377e4

Browse files
robtaylorclaude
andcommitted
Replace os.path with pathlib throughout codebase
Addresses review comment from gatecat: "while doing this refactor probably worth also unifying the use of pathlib rather than os.path" Changes: - chipflow_lib/config/parser.py: Use Path(__file__).parent instead of os.path.dirname(__file__), remove os import - chipflow_lib/platform/silicon.py: Use Path / operator for path joining instead of os.path.join(), convert to str where needed for compatibility with subprocess and string operations All 5 instances of os.path usage in the codebase have been converted. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 62e13c3 commit 94377e4

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

chipflow_lib/config/parser.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
Configuration file parsing and utilities.
44
"""
55

6-
import os
76
import tomli
87

98
from pathlib import Path
@@ -13,11 +12,11 @@
1312
from .models import Config
1413

1514
def get_dir_models():
16-
return os.path.dirname(__file__) + "/models"
15+
return str(Path(__file__).parent / "models")
1716

1817

1918
def get_dir_software():
20-
return os.path.dirname(__file__) + "/software"
19+
return str(Path(__file__).parent / "software")
2120

2221

2322
def _parse_config_file(config_file) -> 'Config':

chipflow_lib/platform/silicon.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import subprocess
99
import warnings
1010

11+
from pathlib import Path
1112
from pprint import pformat
1213
from typing import TYPE_CHECKING, List, Generic, TypeVar
1314

@@ -525,17 +526,17 @@ def build(self, elaboratable, name="top"):
525526
b"hierarchy"
526527
]
527528

528-
build_dir = os.path.join(os.environ["CHIPFLOW_ROOT"], "build")
529-
os.makedirs(build_dir, exist_ok=True)
529+
build_dir = Path(os.environ["CHIPFLOW_ROOT"]) / "build"
530+
build_dir.mkdir(parents=True, exist_ok=True)
530531

531532
name = re.sub(r"[-_.]+", "_", name).lower()
532-
link_script = os.path.join(build_dir, name + "_link.ys")
533+
link_script = build_dir / (name + "_link.ys")
533534
with open(link_script, "wb") as script_fp:
534535
script_fp.write(b"\n".join(yosys_script))
535-
output_rtlil = os.path.join(build_dir, name + ".il")
536+
output_rtlil = build_dir / (name + ".il")
536537
subprocess.check_call([
537538
# yowasp supports forward slashes *only*
538-
"yowasp-yosys", "-q", link_script.replace("\\", "/"),
539-
"-o", output_rtlil.replace("\\", "/")
539+
"yowasp-yosys", "-q", str(link_script).replace("\\", "/"),
540+
"-o", str(output_rtlil).replace("\\", "/")
540541
])
541-
return output_rtlil
542+
return str(output_rtlil)

0 commit comments

Comments
 (0)