Skip to content

Commit

Permalink
Fix cosmetic things
Browse files Browse the repository at this point in the history
  • Loading branch information
cavearr committed Apr 22, 2024
1 parent 5c41598 commit cef4f56
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 29 deletions.
3 changes: 1 addition & 2 deletions apio/commands/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-
# -*- coding: utf-9 -*-
# -- This file is part of the Apio project
# -- (C) 2016-2024 FPGAwars
# -- Authors
Expand Down Expand Up @@ -52,7 +52,6 @@ def cli(ctx, **kwargs):
elif verbose:
profile.add_config("verbose", verbose)


# -- No paratemers: Show the help
else:
click.secho(ctx.get_help())
71 changes: 46 additions & 25 deletions apio/managers/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@

# TODO(zapta): Deprecate the mutations of existing api.ini file.

# TODO(zapta): Deprecate the copying of the sconstruct file. This is a developer only
# feature and developers can copy it manually as needed.
# TODO(zapta): Deprecate the copying of the sconstruct file.
# This is a developer only feature and developers can copy
# it manually as needed.

import sys
from os.path import isfile
Expand All @@ -33,7 +34,7 @@ class Project:
def __init__(self):
# TODO(zapta): Make these __private and provide getter methods.
self.board = None
self.top_module = None
self.top_module = None
self.exe_mode = None

def create_sconstruct(self, project_dir: Path, arch=None, sayyes=False):
Expand Down Expand Up @@ -197,29 +198,45 @@ def read(self):

for section in config_parser.sections():
if section != "env":
print(f"Project file {PROJECT_FILENAME} has an invalid section named [{section}].")
message = (
f"Project file {PROJECT_FILENAME} "
f"has an invalid section named "
f"[{section}]."
)
print(message)
sys.exit(1)

if "env" not in config_parser.sections():
print(f"Project file {PROJECT_FILENAME} does not have an [env] section.")
message = (
f"Project file {PROJECT_FILENAME}"
f"does not have an [env] section."
)
print(message)
sys.exit(1)

# Parse attributes in the env section.
parsed_attributes = set()
self.board = self._parse_board(config_parser, parsed_attributes)
self.top_module = self._parse_top_module(config_parser, parsed_attributes)
self.top_module = self._parse_top_module(config_parser,
parsed_attributes)
self.exe_mode = self._parse_exe_mode(config_parser, parsed_attributes)

# Verify that the project file (api.ini) doesn't contain additional (illegal) keys that
# where not parsed.
# Verify that the project file (api.ini) doesn't contain additional
# (illegal) keys that where not parsed
for attribute in config_parser.options("env"):
if attribute not in parsed_attributes:
print(f"Project file {PROJECT_FILENAME} contains an unknown attribute '{attribute}'.")
message = (
f"Project file {PROJECT_FILENAME} contains"
f" an unknown attribute '{attribute}'."
)
print(message)
sys.exit(1)

@staticmethod
def _parse_board(config_parser: ConfigParser, parsed_attributes: set[str]) -> str:
"""Parse the configured board from the project file parser and add the keys used
def _parse_board(config_parser: ConfigParser,
parsed_attributes: set[str]) -> str:
"""Parse the configured board from the project
file parser and add the keys used
to parsed_attributes.
RETURN:
* A string with the name of the board
Expand All @@ -233,35 +250,39 @@ def _parse_board(config_parser: ConfigParser, parsed_attributes: set[str]) -> st
return board

@staticmethod
def _parse_top_module(config_parser: ConfigParser, parsed_attributes: set[str]) -> str:
"""Read the configured top-module from the project file parser and add the keys used
def _parse_top_module(config_parser: ConfigParser,
parsed_attributes: set[str]) -> str:
"""Read the configured top-module from the project file
parser and add the keys used
to parsed_attributes.
RETURN:
* A string with the name of the top-module
"""
parsed_attributes.add("top-module")
top_module = config_parser.get("env", "top-module")
top_module = config_parser.get("env", "top-module")
if not top_module:
click.secho(f"Warning! invalid {PROJECT_FILENAME} project file", fg="yellow")
click.secho(f"No 'top-module' in [env] section. Assuming 'main'.")
click.secho(f"Warning! invalid {PROJECT_FILENAME} "
f"project file", fg="yellow")
click.secho("No 'top-module' in [env] section. Assuming 'main'.")
return 'main'
return top_module



@staticmethod
def _parse_exe_mode(config_parser: ConfigParser, parsed_attributes: set[str]) -> str:
"""Read the configured exe mode from the project file parser and add the keys used
def _parse_exe_mode(config_parser: ConfigParser,
parsed_attributes: set[str]) -> str:
"""Read the configured exe mode from the
project file parser and add the keys used
to parsed_attributes.
RETURN:
* A string with "default" (default) or "native"
"""
# print(f"*** project.py: reading exe mode")
parsed_attributes.add("exe-mode")
exe_mode = config_parser.get("env", "exe-mode", fallback="default")
exe_mode = config_parser.get("env", "exe-mode", fallback="default")
if exe_mode not in {"default", "native"}:
print(f"Error: invalid {PROJECT_FILENAME} project file")
print("Optional attribute 'exe-mode' should have the value 'default' or 'native'.")
print(f"Error: invalid {PROJECT_FILENAME}"
"project file")
print("Optional attribute 'exe-mode' should have"
" the value 'default' or 'native'.")
sys.exit(1)
return exe_mode


2 changes: 1 addition & 1 deletion apio/managers/scons.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def __init__(self, project_dir: Path):
# -- Read the project file (apio.ini)
self.proj = Project()
self.proj.read()

# -- Read the apio profile file
self.profile = Profile()

Expand Down
1 change: 0 additions & 1 deletion apio/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ def _load_profile(self, profile: Path):
if "config" in data.keys():
self.config = data["config"]


if "verbose" not in self.config.keys():
self.config["verbose"] = 0

Expand Down

0 comments on commit cef4f56

Please sign in to comment.