Skip to content

Commit 7e1d451

Browse files
committed
Various tweaks to user experience
* Make chipflow submit default to a spinner with useful information * Also some reliability improvments to log streaming (in conjunction with chipflow-api 0.2.3) * Add ability to log debug to file
1 parent 234104d commit 7e1d451

File tree

13 files changed

+492
-248
lines changed

13 files changed

+492
-248
lines changed

.github/workflows/test-examples.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,6 @@ jobs:
6363
working-directory: ${{ env.test_repo_path }}/${{ matrix.repo.design }}
6464
run: |
6565
pdm run chipflow pin lock
66-
pdm run chipflow silicon submit --wait $DRY
66+
pdm run chipflow silicon submit --wait $DRY | cat
6767
env:
6868
CHIPFLOW_API_KEY: ${{ secrets.CHIPFLOW_API_KEY}}

chipflow_lib/__init__.py

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

55
import importlib.metadata
6+
import logging
67
import os
78
import sys
89
import tomli
@@ -11,6 +12,8 @@
1112

1213
__version__ = importlib.metadata.version("chipflow_lib")
1314

15+
logger = logging.getLogger(__name__)
16+
1417
class ChipFlowError(Exception):
1518
pass
1619

@@ -29,18 +32,32 @@ def _get_cls_by_reference(reference, context):
2932

3033

3134
def _ensure_chipflow_root():
35+
root = getattr(_ensure_chipflow_root, 'root', None)
36+
if root:
37+
return root
38+
3239
if "CHIPFLOW_ROOT" not in os.environ:
40+
logger.debug(f"CHIPFLOW_ROOT not found in environment. Setting CHIPFLOW_ROOT to {os.getcwd()} for any child scripts")
3341
os.environ["CHIPFLOW_ROOT"] = os.getcwd()
42+
else:
43+
logger.debug(f"CHIPFLOW_ROOT={os.environ['CHIPFLOW_ROOT']} found in environment")
44+
3445
if os.environ["CHIPFLOW_ROOT"] not in sys.path:
3546
sys.path.append(os.environ["CHIPFLOW_ROOT"])
36-
return os.environ["CHIPFLOW_ROOT"]
47+
_ensure_chipflow_root.root = os.environ["CHIPFLOW_ROOT"]
48+
return _ensure_chipflow_root.root
3749

3850

3951
def _parse_config():
4052
"""Parse the chipflow.toml configuration file."""
4153
chipflow_root = _ensure_chipflow_root()
4254
config_file = Path(chipflow_root) / "chipflow.toml"
43-
return _parse_config_file(config_file)
55+
try:
56+
return _parse_config_file(config_file)
57+
except FileNotFoundError:
58+
raise ChipFlowError(f"Config file not found. I expected to find it at {config_file}")
59+
except tomli.TOMLDecodeError as e:
60+
raise ChipFlowError(f"TOML Error found when loading {config_file}: {e.msg} at line {e.lineno}, column {e.colno}")
4461

4562

4663
def _parse_config_file(config_file):

chipflow_lib/cli.py

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import traceback
66
import logging
77

8+
from pathlib import Path
89
from pprint import pformat
910

1011
from . import (
@@ -14,13 +15,10 @@
1415
)
1516
from .pin_lock import PinCommand
1617

17-
18-
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
19-
20-
2118
class UnexpectedError(ChipFlowError):
2219
pass
2320

21+
log_level = logging.WARNING
2422

2523
def run(argv=sys.argv[1:]):
2624
config = _parse_config()
@@ -43,10 +41,15 @@ def run(argv=sys.argv[1:]):
4341
parser.add_argument(
4442
"--verbose", "-v",
4543
dest="log_level",
46-
action="append_const",
47-
const=10,
44+
action="count",
45+
default=0,
4846
help="increase verbosity of messages; can be supplied multiple times to increase verbosity"
4947
)
48+
parser.add_argument(
49+
"--log-file", help=argparse.SUPPRESS,
50+
default=None, action="store"
51+
)
52+
5053

5154
command_argument = parser.add_subparsers(dest="command", required=True)
5255
for command_name, command in commands.items():
@@ -57,12 +60,27 @@ def run(argv=sys.argv[1:]):
5760
raise ChipFlowError(f"Encountered error while building CLI argument parser for "
5861
f"step `{command_name}`")
5962

60-
# each verbose flag increases versbosity (e.g. -v -v, -vv, --verbose --verbose)
61-
# cute trick using append_const and summing
6263
args = parser.parse_args(argv)
63-
if args.log_level:
64-
log_level = max(logging.DEBUG, logging.WARNING - sum(args.log_level))
65-
logging.getLogger().setLevel(log_level)
64+
global log_level
65+
log_level = max(logging.WARNING - args.log_level * 10, 0)
66+
logging.getLogger().setLevel(logging.NOTSET)
67+
68+
# Add stdout handler, with level as set
69+
console = logging.StreamHandler(sys.stdout)
70+
console.setLevel(log_level)
71+
formatter = logging.Formatter('%(name)-13s: %(levelname)-8s %(message)s')
72+
console.setFormatter(formatter)
73+
logging.getLogger().addHandler(console)
74+
75+
#Log to file with DEBUG level
76+
if args.log_file:
77+
filename = Path(args.log_file).absolute()
78+
print(f"> Logging to {str(filename)}")
79+
fh = logging.FileHandler(filename)
80+
fh.setLevel(logging.DEBUG)
81+
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
82+
fh.setFormatter(formatter)
83+
logging.getLogger().addHandler(fh)
6684

6785
try:
6886
try:

chipflow_lib/config_models.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ class StepsConfig(BaseModel):
6565

6666
class ChipFlowConfig(BaseModel):
6767
"""Root configuration for chipflow.toml."""
68-
project_name: Optional[str] = None
68+
project_name: str
6969
top: Dict[str, Any] = {}
70-
steps: StepsConfig
71-
silicon: SiliconConfig
70+
steps: Optional[Dict[str, str]] = None
71+
silicon: Optional[SiliconConfig] = None
7272
clocks: Optional[Dict[str, str]] = None
7373
resets: Optional[Dict[str, str]] = None
7474

0 commit comments

Comments
 (0)