|
1 | 1 | # SPDX-License-Identifier: BSD-2-Clause |
2 | | -import inspect |
3 | | -import logging |
| 2 | +""" |
| 3 | +Backward compatibility shim for pin lock functionality. |
4 | 4 |
|
5 | | -from pathlib import Path |
6 | | -from pprint import pformat |
| 5 | +This module re-exports pin lock functionality from the packaging module. |
| 6 | +New code should import directly from chipflow_lib.packaging instead. |
| 7 | +""" |
7 | 8 |
|
8 | | -from . import _parse_config, _ensure_chipflow_root, ChipFlowError |
9 | | -from .platforms._utils import top_components, LockFile |
10 | | -from .platforms._packages import PACKAGE_DEFINITIONS |
| 9 | +# Re-export from packaging module for backward compatibility |
| 10 | +from .packaging import lock_pins, PinCommand # noqa: F401 |
11 | 11 |
|
12 | | -# logging.basicConfig(stream=sys.stdout, level=logging.DEBUG) |
13 | | -logger = logging.getLogger(__name__) |
14 | | - |
15 | | - |
16 | | -def lock_pins() -> None: |
17 | | - config = _parse_config() |
18 | | - |
19 | | - # Parse with Pydantic for type checking and strong typing |
20 | | - |
21 | | - chipflow_root = _ensure_chipflow_root() |
22 | | - lockfile = Path(chipflow_root, 'pins.lock') |
23 | | - oldlock = None |
24 | | - |
25 | | - if lockfile.exists(): |
26 | | - print("Reusing current pin allocation from `pins.lock`") |
27 | | - oldlock = LockFile.model_validate_json(lockfile.read_text()) |
28 | | - logger.debug(f"Old Lock =\n{pformat(oldlock)}") |
29 | | - logger.debug(f"Locking pins: {'using pins.lock' if lockfile.exists() else ''}") |
30 | | - |
31 | | - if not config.chipflow.silicon: |
32 | | - raise ChipFlowError("no [chipflow.silicon] section found in chipflow.toml") |
33 | | - |
34 | | - # Get package definition from dict instead of Pydantic model |
35 | | - package_name = config.chipflow.silicon.package |
36 | | - package_def = PACKAGE_DEFINITIONS[package_name] |
37 | | - process = config.chipflow.silicon.process |
38 | | - |
39 | | - top = top_components(config) |
40 | | - |
41 | | - # Use the PackageDef to allocate the pins: |
42 | | - for name, component in top.items(): |
43 | | - package_def.register_component(name, component) |
44 | | - |
45 | | - newlock = package_def.allocate_pins(config, process, oldlock) |
46 | | - |
47 | | - with open(lockfile, 'w') as f: |
48 | | - f.write(newlock.model_dump_json(indent=2, serialize_as_any=True)) |
49 | | - |
50 | | - |
51 | | -class PinCommand: |
52 | | - def __init__(self, config): |
53 | | - self.config = config |
54 | | - |
55 | | - def build_cli_parser(self, parser): |
56 | | - assert inspect.getdoc(self.lock) is not None |
57 | | - action_argument = parser.add_subparsers(dest="action") |
58 | | - action_argument.add_parser( |
59 | | - "lock", help=inspect.getdoc(self.lock).splitlines()[0]) # type: ignore |
60 | | - |
61 | | - def run_cli(self, args): |
62 | | - logger.debug(f"command {args}") |
63 | | - if args.action == "lock": |
64 | | - self.lock() |
65 | | - |
66 | | - def lock(self): |
67 | | - """Lock the pin map for the design. |
68 | | -
|
69 | | - Will attempt to reuse previous pin positions. |
70 | | - """ |
71 | | - lock_pins() |
| 12 | +__all__ = ['lock_pins', 'PinCommand'] |
0 commit comments