Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test-examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ jobs:
working-directory: ${{ env.test_repo_path }}/${{ matrix.repo.design }}
run: |
pdm run chipflow pin lock
pdm run chipflow silicon submit --wait $DRY
pdm run chipflow silicon submit --wait $DRY | cat
env:
CHIPFLOW_API_KEY: ${{ secrets.CHIPFLOW_API_KEY}}
21 changes: 19 additions & 2 deletions chipflow_lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

import importlib.metadata
import logging
import os
import sys
import tomli
Expand All @@ -11,6 +12,8 @@

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

logger = logging.getLogger(__name__)

class ChipFlowError(Exception):
pass

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


def _ensure_chipflow_root():
root = getattr(_ensure_chipflow_root, 'root', None)
if root:
return root

if "CHIPFLOW_ROOT" not in os.environ:
logger.debug(f"CHIPFLOW_ROOT not found in environment. Setting CHIPFLOW_ROOT to {os.getcwd()} for any child scripts")
os.environ["CHIPFLOW_ROOT"] = os.getcwd()
else:
logger.debug(f"CHIPFLOW_ROOT={os.environ['CHIPFLOW_ROOT']} found in environment")

if os.environ["CHIPFLOW_ROOT"] not in sys.path:
sys.path.append(os.environ["CHIPFLOW_ROOT"])
return os.environ["CHIPFLOW_ROOT"]
_ensure_chipflow_root.root = os.environ["CHIPFLOW_ROOT"]
return _ensure_chipflow_root.root


def _parse_config():
"""Parse the chipflow.toml configuration file."""
chipflow_root = _ensure_chipflow_root()
config_file = Path(chipflow_root) / "chipflow.toml"
return _parse_config_file(config_file)
try:
return _parse_config_file(config_file)
except FileNotFoundError:
raise ChipFlowError(f"Config file not found. I expected to find it at {config_file}")
except tomli.TOMLDecodeError as e:
raise ChipFlowError(f"TOML Error found when loading {config_file}: {e.msg} at line {e.lineno}, column {e.colno}")


def _parse_config_file(config_file):
Expand Down
40 changes: 29 additions & 11 deletions chipflow_lib/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import traceback
import logging

from pathlib import Path
from pprint import pformat

from . import (
Expand All @@ -14,13 +15,10 @@
)
from .pin_lock import PinCommand


logging.basicConfig(stream=sys.stdout, level=logging.INFO)


class UnexpectedError(ChipFlowError):
pass

log_level = logging.WARNING

def run(argv=sys.argv[1:]):
config = _parse_config()
Expand All @@ -43,10 +41,15 @@ def run(argv=sys.argv[1:]):
parser.add_argument(
"--verbose", "-v",
dest="log_level",
action="append_const",
const=10,
action="count",
default=0,
help="increase verbosity of messages; can be supplied multiple times to increase verbosity"
)
parser.add_argument(
"--log-file", help=argparse.SUPPRESS,
default=None, action="store"
)


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

# each verbose flag increases versbosity (e.g. -v -v, -vv, --verbose --verbose)
# cute trick using append_const and summing
args = parser.parse_args(argv)
if args.log_level:
log_level = max(logging.DEBUG, logging.WARNING - sum(args.log_level))
logging.getLogger().setLevel(log_level)
global log_level
log_level = max(logging.WARNING - args.log_level * 10, 0)
logging.getLogger().setLevel(logging.NOTSET)

# Add stdout handler, with level as set
console = logging.StreamHandler(sys.stdout)
console.setLevel(log_level)
formatter = logging.Formatter('%(name)-13s: %(levelname)-8s %(message)s')
console.setFormatter(formatter)
logging.getLogger().addHandler(console)

#Log to file with DEBUG level
if args.log_file:
filename = Path(args.log_file).absolute()
print(f"> Logging to {str(filename)}")
fh = logging.FileHandler(filename)
fh.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
fh.setFormatter(formatter)
logging.getLogger().addHandler(fh)

try:
try:
Expand Down
6 changes: 3 additions & 3 deletions chipflow_lib/config_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ class StepsConfig(BaseModel):

class ChipFlowConfig(BaseModel):
"""Root configuration for chipflow.toml."""
project_name: Optional[str] = None
project_name: str
top: Dict[str, Any] = {}
steps: StepsConfig
silicon: SiliconConfig
steps: Optional[Dict[str, str]] = None
silicon: Optional[SiliconConfig] = None
clocks: Optional[Dict[str, str]] = None
resets: Optional[Dict[str, str]] = None

Expand Down
Loading
Loading