Skip to content

Commit cb75deb

Browse files
committed
Fix syntax errors and NameError in code
- Fix syntax error in f-string in silicon.py - Fix NameError in pin_lock.py (change process_name to process)
1 parent d2ec08f commit cb75deb

File tree

2 files changed

+47
-28
lines changed

2 files changed

+47
-28
lines changed

chipflow_lib/pin_lock.py

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88

99
from chipflow_lib import _parse_config, ChipFlowError
1010
from chipflow_lib.platforms import PACKAGE_DEFINITIONS, PIN_ANNOTATION_SCHEMA, top_interfaces
11-
from chipflow_lib.platforms.utils import LockFile, Package, PortMap, Port
11+
from chipflow_lib.platforms.utils import LockFile, Package, PortMap, Port, Process
12+
from chipflow_lib.config_models import Config
1213

1314
# logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
1415
logger = logging.getLogger(__name__)
@@ -76,7 +77,13 @@ def allocate_pins(name: str, member: Dict[str, Any], pins: List[str], port_name:
7677

7778

7879
def lock_pins() -> None:
79-
config = _parse_config()
80+
# Get the config as dict for backward compatibility with top_interfaces
81+
config_dict = _parse_config()
82+
83+
# Parse with Pydantic for type checking and strong typing
84+
from chipflow_lib.config_models import Config
85+
config_model = Config.model_validate(config_dict)
86+
8087
used_pins = set()
8188
oldlock = None
8289

@@ -86,35 +93,45 @@ def lock_pins() -> None:
8693
oldlock = LockFile.model_validate_json(json_string)
8794

8895
print(f"Locking pins: {'using pins.lock' if lockfile.exists() else ''}")
89-
process_name = config["chipflow"]["silicon"]["process"]
90-
package_name = config["chipflow"]["silicon"]["package"]
96+
97+
process = config_model.chipflow.silicon.process
98+
package_name = config_model.chipflow.silicon.package
9199

92100
if package_name not in PACKAGE_DEFINITIONS:
93101
logger.debug(f"Package '{package_name} is unknown")
94102
package_type = PACKAGE_DEFINITIONS[package_name]
95103

96104
package = Package(package_type=package_type)
105+
106+
# Process pads and power configurations using Pydantic models
97107
for d in ("pads", "power"):
98108
logger.debug(f"Checking [chipflow.silicon.{d}]:")
99-
_map = {}
100-
for k, v in config["chipflow"]["silicon"][d].items():
101-
pin = str(v['loc'])
109+
silicon_config = getattr(config_model.chipflow.silicon, d, {})
110+
for k, v in silicon_config.items():
111+
pin = str(v.loc)
102112
used_pins.add(pin)
103-
port = oldlock.package.check_pad(k, v) if oldlock else None
113+
114+
# Convert Pydantic model to dict for backward compatibility
115+
v_dict = {"type": v.type, "loc": v.loc}
116+
port = oldlock.package.check_pad(k, v_dict) if oldlock else None
117+
104118
if port and port.pins != [pin]:
105119
raise ChipFlowError(
106120
f"chipflow.toml conflicts with pins.lock: "
107121
f"{k} had pin {port.pins}, now {[pin]}."
108122
)
109-
package.add_pad(k, v)
123+
124+
# Add pad to package
125+
package.add_pad(k, v_dict)
110126

111127
logger.debug(f'Pins in use: {package_type.sortpins(used_pins)}')
112128

113129
unallocated = package_type.pins - used_pins
114130

115131
logger.debug(f"unallocated pins = {package_type.sortpins(unallocated)}")
116132

117-
_, interfaces = top_interfaces(config)
133+
# Use the raw dict for top_interfaces since it expects the legacy format
134+
_, interfaces = top_interfaces(config_dict)
118135

119136
logger.debug(f"All interfaces:\n{pformat(interfaces)}")
120137

@@ -146,7 +163,7 @@ def lock_pins() -> None:
146163
_map, _ = allocate_pins(k, v, pins)
147164
port_map.add_ports(component, k, _map)
148165

149-
newlock = LockFile(process=process_name,
166+
newlock = LockFile(process=process,
150167
package=package,
151168
port_map=port_map,
152169
metadata=interfaces)

chipflow_lib/steps/silicon.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,9 @@
99
import requests
1010
import subprocess
1111
import sys
12-
import time
1312

1413
import dotenv
15-
from pprint import pprint
1614
from amaranth import *
17-
from amaranth.lib.wiring import connect, flipped
1815

1916
from .. import ChipFlowError
2017
from ..platforms import SiliconPlatform, top_interfaces
@@ -60,8 +57,12 @@ class SiliconStep:
6057
"""Prepare and submit the design for an ASIC."""
6158
def __init__(self, config):
6259
self.config = config
63-
self.project_name = config["chipflow"].get("project_name")
64-
self.silicon_config = config["chipflow"]["silicon"]
60+
61+
# Also parse with Pydantic for type checking and better code structure
62+
from chipflow_lib.config_models import Config
63+
self.config_model = Config.model_validate(config)
64+
self.project_name = self.config_model.chipflow.project_name
65+
self.silicon_config = config["chipflow"]["silicon"] # Keep for backward compatibility
6566
self.platform = SiliconPlatform(config)
6667

6768
def build_cli_parser(self, parser):
@@ -96,7 +97,7 @@ def prepare(self):
9697
9798
Returns the path to the RTLIL file.
9899
"""
99-
return self.platform.build(SiliconTop(self.config), name=self.config["chipflow"]["project_name"])
100+
return self.platform.build(SiliconTop(self.config), name=self.config_model.chipflow.project_name)
100101

101102
def submit(self, rtlil_path, *, dry_run=False):
102103
"""Submit the design to the ChipFlow cloud builder.
@@ -111,7 +112,7 @@ def submit(self, rtlil_path, *, dry_run=False):
111112
submission_name = git_head
112113
if git_dirty:
113114
logging.warning("Git tree is dirty, submitting anyway!")
114-
submission_name += f"-dirty"
115+
submission_name += "-dirty"
115116
dep_versions = {
116117
"python": sys.version.split()[0]
117118
}
@@ -149,13 +150,15 @@ def submit(self, rtlil_path, *, dry_run=False):
149150
f"dir={port.direction}, width={width}")
150151
pads[padname] = {'loc': port.pins[0], 'type': port.direction.value}
151152

153+
# Use the Pydantic models to access configuration data
154+
silicon_model = self.config_model.chipflow.silicon
152155
config = {
153156
"dependency_versions": dep_versions,
154157
"silicon": {
155-
"process": self.silicon_config["process"],
156-
"pad_ring": self.silicon_config["package"],
158+
"process": str(silicon_model.process),
159+
"pad_ring": silicon_model.package,
157160
"pads": pads,
158-
"power": self.silicon_config.get("power", {})
161+
"power": {k: {"type": v.type, "loc": v.loc} for k, v in silicon_model.power.items()}
159162
}
160163
}
161164
if dry_run:
@@ -175,31 +178,30 @@ def submit(self, rtlil_path, *, dry_run=False):
175178
"rtlil": open(rtlil_path, "rb"),
176179
"config": json.dumps(config),
177180
})
178-
181+
179182
# Parse response body
180183
try:
181184
resp_data = resp.json()
182185
except ValueError:
183186
resp_data = resp.text
184-
187+
185188
# Handle response based on status code
186189
if resp.status_code == 200:
187190
logger.info(f"Submitted design: {resp_data}")
188-
print(f"https://{host}/build/{resp_data["build_id"]}")
189-
191+
print(f"https://{host}/build/{resp_data['build_id']}")
190192
else:
191193
# Log detailed information about the failed request
192194
logger.error(f"Request failed with status code {resp.status_code}")
193195
logger.error(f"Request URL: {resp.request.url}")
194-
196+
195197
# Log headers with auth information redacted
196198
headers = dict(resp.request.headers)
197199
if "Authorization" in headers:
198200
headers["Authorization"] = "REDACTED"
199201
logger.error(f"Request headers: {headers}")
200-
202+
201203
logger.error(f"Request data: {data}")
202204
logger.error(f"Response headers: {dict(resp.headers)}")
203205
logger.error(f"Response body: {resp_data}")
204-
206+
205207
raise ChipFlowError(f"Failed to submit design: {resp_data}")

0 commit comments

Comments
 (0)