Skip to content

Commit

Permalink
Merge pull request #482 from zapta/develop
Browse files Browse the repository at this point in the history
Assorted changes. Test fixture, $dumpfile elimination, tests, apio sim --force.
  • Loading branch information
Obijuan authored Dec 2, 2024
2 parents 1b28d89 + 5928b06 commit e5d834b
Show file tree
Hide file tree
Showing 77 changed files with 1,034 additions and 728 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@
"module": "pytest",
"args": [
"-s",
"test/test_scons_util.py::test_make_verilator_config_builder"
"test/commands/test_boards.py"
],
"console": "integratedTerminal",
"justMyCode": false,
Expand Down
22 changes: 20 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
.PHONY: deps cenv env lint test presubmit publish_test publish install

# NOTE: Some targets have a shortcuts or alias names that are listed on the same line.
# The are provided for convinience or for backward competibility. For example
# 'check-all' has the aliases 'check_all' and 'ca'.
Expand All @@ -8,6 +6,8 @@
#
# Usage:
# make deps
#
.PHONY: deps
deps:
python -m pip install --upgrade pip
pip install flit black flake8 pylint tox pytest semantic-version pyserial importlib-metadata
Expand All @@ -17,12 +17,16 @@ deps:
#
# Usage:
# make cenv
#
.PHONY: cenv
cenv:
python3 -m venv venv
python3 -m venv venv --upgrade

# Usage
# make env
#
.PHONY: env
env:
@echo "For entering the virtual-environment just type:"
@echo ". venv/bin/activate"
Expand All @@ -33,6 +37,8 @@ env:
# Usage:
# make lint
# make l
#
.PHONY: lint l
lint l:
python -m tox -e lint

Expand All @@ -43,6 +49,8 @@ lint l:
# Usage:
# make test
# make t
#
.PHONY: test t
test t:
python -m tox --skip-missing-interpreters false -e py312 -- --offline

Expand All @@ -54,6 +62,8 @@ test t:
# Usage:
# make check
# make c
#
.PHONY: check c
check c:
python -m tox --skip-missing-interpreters false -e lint,py312

Expand All @@ -65,6 +75,8 @@ check c:
# make check-all
# make check_all // deprecated, to be deleted.
# make ca
#
.PHONY: check-all check_all ca
check-all check_all ca:
python -m tox --skip-missing-interpreters false

Expand All @@ -74,6 +86,8 @@ check-all check_all ca:
# Usage:
# make publish-test
# make publish_test // deprecated, to be deleted.
#
.PHONY: publish-test publish_test
publish-test publish_test:
flit publish --repository testpypi

Expand All @@ -82,13 +96,17 @@ publish-test publish_test:
#
# Usage:
# make publish
#
.PHONY: publish
publish:
python -m flit publish

## Install the tool locally
#
# Usage:
# make instll
#
.PHONY: install
install:
flit build
flit install
80 changes: 12 additions & 68 deletions apio/apio_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import re
import platform
from collections import OrderedDict
import shutil
from pathlib import Path
from typing import Optional, Dict
import click
Expand Down Expand Up @@ -97,9 +96,6 @@ def __init__(
# -- make the path longer and longer.
self.env_was_already_set = False

# -- Save the load project status.
self._load_project = load_project

# -- Maps the optional project_dir option to a path.
self.project_dir: Path = util.get_project_dir(project_dir)
ApioContext._check_no_spaces_in_dir(self.project_dir, "project")
Expand Down Expand Up @@ -164,6 +160,8 @@ def __init__(
if load_project:
self._project = Project(self.project_dir)
self._project.read()
else:
self._project = None

@staticmethod
def _check_no_spaces_in_dir(dir_path: Path, subject: str):
Expand All @@ -182,17 +180,19 @@ def _check_no_spaces_in_dir(dir_path: Path, subject: str):
click.secho(f"'{str(dir_path)}'", fg="red")
sys.exit(1)

def check_project_loaded(self):
"""Assert that context was created with project loading.."""
assert (
self._load_project
), "Apio context created without project loading."
@property
def has_project_loaded(self):
"""Returns True if the project is loaded."""
return self._project is not None

@property
def project(self):
"""Property to return the project after verification that it was
loaded."""
self.check_project_loaded()
loaded. It's a programming error to call this method on a context
that was initialized with load_project = False."""
assert (
self.has_project_loaded
), "ApioContext.project() called with no project loaded."
return self._project

def _load_resource(self, name: str, allow_custom: bool = False) -> dict:
Expand Down Expand Up @@ -254,7 +254,7 @@ def _load_resource_file(filepath: Path) -> dict:
click.secho(f"{exc}\n", fg="red")

# -- Abort!
sys.exit(2)
sys.exit(1)

# -- Parse the json format!
try:
Expand Down Expand Up @@ -429,62 +429,6 @@ def get_platform_packages_lists(self) -> tuple[list, list]:
# -- Return the packages, classified
return installed_packages, notinstalled_packages

def list_packages(self, installed=True, notinstalled=True):
"""Return a list with all the installed/notinstalled packages"""

# Classify packages
installed_packages, notinstalled_packages = (
self.get_platform_packages_lists()
)

# -- Calculate the terminal width
terminal_width, _ = shutil.get_terminal_size()

# -- String with a horizontal line with the same width
# -- as the terminal
line = "─" * terminal_width
dline = "═" * terminal_width

if installed and installed_packages:

# ------- Print installed packages table
# -- Print the header
click.secho()
click.secho(dline, fg="green")
click.secho("Installed packages:", fg="green")

for package in installed_packages:
click.secho(line)
name = click.style(f"{package['name']}", fg="cyan", bold=True)
version = package["version"]
description = package["description"]

click.secho(f"• {name} {version}")
click.secho(f" {description}")

click.secho(dline, fg="green")
click.secho(f"Total: {len(installed_packages)}")

if notinstalled and notinstalled_packages:

# ------ Print not installed packages table
# -- Print the header
click.secho()
click.secho(dline, fg="yellow")
click.secho("Available packages (Not installed):", fg="yellow")

for package in notinstalled_packages:

click.secho(line)
name = click.style(f"• {package['name']}", fg="red")
description = package["description"]
click.secho(f"{name} {description}")

click.secho(dline, fg="yellow")
click.secho(f"Total: {len(notinstalled_packages)}")

click.secho("\n")

def get_package_dir(self, package_name: str) -> Path:
"""Returns the root path of a package with given name."""

Expand Down
13 changes: 7 additions & 6 deletions apio/cmd_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# ---- Licence Apache v2
"""Utility functionality for apio click commands. """


import sys
from typing import Mapping, List, Tuple, Any, Dict, Union
import click

Expand All @@ -34,13 +34,14 @@ def fatal_usage_error(cmd_ctx: click.Context, msg: str) -> None:
)
click.secho()
click.secho(f"Error: {msg}", fg="red")
cmd_ctx.exit(1)
sys.exit(1)


def _get_params_objs(
def _get_all_params_definitions(
cmd_ctx: click.Context,
) -> Dict[str, Union[click.Option, click.Argument]]:
"""Return a mapping from param id to param obj."""
"""Return a mapping from param id to param obj, for all options and
arguments that are defined for the command."""
result = {}
for param_obj in cmd_ctx.command.get_params(cmd_ctx):
assert isinstance(param_obj, (click.Option, click.Argument)), type(
Expand All @@ -64,7 +65,7 @@ def _params_ids_to_aliases(
e.g. "PACKAGES" for the argument packages.
"""
# Param id -> param obj.
params_dict = _get_params_objs(cmd_ctx)
params_dict = _get_all_params_definitions(cmd_ctx)

# Map the param ids to their canonical aliases.
result = []
Expand All @@ -89,7 +90,7 @@ def _is_param_specified(cmd_ctx, param_id) -> bool:
"""Determine if the param with given id was specified in the
command line."""
# Mapping: param id -> param obj.
params_dict = _get_params_objs(cmd_ctx)
params_dict = _get_all_params_definitions(cmd_ctx)
# Get the official status.
param_src = cmd_ctx.get_parameter_source(param_id)
is_specified = param_src == click.core.ParameterSource.COMMANDLINE
Expand Down
5 changes: 3 additions & 2 deletions apio/commands/boards.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# -- Licence GPLv2
"""Implementation of 'apio boards' command"""

import sys
from pathlib import Path
import click
from apio.apio_context import ApioContext
Expand Down Expand Up @@ -124,7 +125,7 @@ def list_boards(apio_ctx: ApioContext):
@click.pass_context
@options.project_dir_option
def cli(
cmd_ctx: click.core.Context,
_: click.core.Context,
# Options
project_dir: Path,
):
Expand All @@ -136,4 +137,4 @@ def cli(
apio_ctx = ApioContext(project_dir=project_dir, load_project=False)

list_boards(apio_ctx)
cmd_ctx.exit(0)
sys.exit(0)
5 changes: 3 additions & 2 deletions apio/commands/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# -- Licence GPLv2
"""Implementation of 'apio build' command"""

import sys
from pathlib import Path
import click
from apio.managers.scons import SCons
Expand Down Expand Up @@ -56,7 +57,7 @@
@options.type_option_gen(deprecated=True)
@options.pack_option_gen(deprecated=True)
def cli(
cmd_ctx: click.core.Context,
_: click.core.Context,
# Options
project_dir: Path,
verbose: bool,
Expand Down Expand Up @@ -102,7 +103,7 @@ def cli(
)

# -- Done!
cmd_ctx.exit(exit_code)
sys.exit(exit_code)


# Advanced notes: https://github.com/FPGAwars/apio/wiki/Commands#apio-build
5 changes: 3 additions & 2 deletions apio/commands/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# -- Licence GPLv2
"""Implementation of 'apio clean' command"""

import sys
from pathlib import Path
import click
from apio.managers.scons import SCons
Expand Down Expand Up @@ -43,7 +44,7 @@
@options.project_dir_option
@options.board_option_gen(deprecated=True)
def cli(
cmd_ctx: click.core.Context,
_: click.core.Context,
# Options
project_dir: Path,
# Deprecated options.
Expand All @@ -63,4 +64,4 @@ def cli(
exit_code = scons.clean({"board": board})

# -- Done!
cmd_ctx.exit(exit_code)
sys.exit(exit_code)
5 changes: 3 additions & 2 deletions apio/commands/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# -- Licence GPLv2
"""Implementation of 'apio create' command"""

import sys
from pathlib import Path
import click
from apio.managers.project import Project, DEFAULT_TOP_MODULE, PROJECT_FILENAME
Expand Down Expand Up @@ -59,7 +60,7 @@
@options.project_dir_option
@options.sayyes
def cli(
cmd_ctx: click.core.Context,
_: click.core.Context,
# Options
board: str,
top_module: str,
Expand Down Expand Up @@ -89,4 +90,4 @@ def cli(
)

exit_code = 0 if ok else 1
cmd_ctx.exit(exit_code)
sys.exit(exit_code)
Loading

0 comments on commit e5d834b

Please sign in to comment.