From 176f44d360949c1c27554988409eef9f3c0ef7d1 Mon Sep 17 00:00:00 2001 From: Obijuan Date: Sun, 17 Mar 2024 22:04:32 +0100 Subject: [PATCH] apio time refactoring --- apio/commands/build.py | 2 + apio/commands/time.py | 76 ++++++++++++++++++++++++-------------- apio/managers/installer.py | 2 + 3 files changed, 52 insertions(+), 28 deletions(-) diff --git a/apio/commands/build.py b/apio/commands/build.py index 89862d57..32b46504 100644 --- a/apio/commands/build.py +++ b/apio/commands/build.py @@ -13,6 +13,8 @@ from apio.managers.scons import SCons from apio import util +# R0801: Similar lines in 2 files +# pylint: disable=R0801 # ------------------ # -- CONSTANTS # ------------------ diff --git a/apio/commands/time.py b/apio/commands/time.py index c461b333..13973309 100644 --- a/apio/commands/time.py +++ b/apio/commands/time.py @@ -1,33 +1,48 @@ # -*- coding: utf-8 -*- # -- This file is part of the Apio project -# -- (C) 2016-2019 FPGAwars -# -- Author Jesús Arroyo +# -- (C) 2016-2024 FPGAwars +# -- Authors +# -- * Jesús Arroyo (2016-2019) +# -- * Juan Gonzalez (obijuan) (2019-2024) # -- Licence GPLv2 -"""TODO""" +"""Main implementation of APIO time command""" import click - from apio.managers.scons import SCons from apio import util +# ------------------ +# -- CONSTANTS +# ------------------ +CMD = "time" # -- Comand name +BOARD = "board" # -- Option +FPGA = "fpga" # -- Option +SIZE = "size" # -- Option +PACK = "pack" # -- Option +TYPE = "type" # -- Option +PROJECT_DIR = "project_dir" # -- Option +VERBOSE = "verbose" # -- Option +VERBOSE_YOSYS = "verbose_yosys" # -- Option +VERBOSE_PNR = "verbose_pnr" # -- Option +TOP_MODULE = "top_module" # -- Option + -# R0913: Too many arguments (6/5) -# pylint: disable=R0913 -# pylint: disable=W0622 -@click.command("time", context_settings=util.context_settings()) +# R0801: Similar lines in 2 files +# pylint: disable=R0801 +@click.command(CMD, context_settings=util.context_settings()) @click.pass_context @click.option( - "-b", "--board", type=str, metavar="board", help="Set the board." + "-b", f"--{BOARD}", type=str, metavar="str", help="Set the board." ) -@click.option("--fpga", type=str, metavar="fpga", help="Set the FPGA.") +@click.option(f"--{FPGA}", type=str, metavar="str", help="Set the FPGA.") @click.option( - "--size", type=str, metavar="size", help="Set the FPGA type (1k/8k)." + f"--{SIZE}", type=str, metavar="str", help="Set the FPGA type (1k/8k)." ) @click.option( - "--type", type=str, metavar="type", help="Set the FPGA type (hx/lp)." + f"--{TYPE}", type=str, metavar="str", help="Set the FPGA type (hx/lp)." ) @click.option( - "--pack", type=str, metavar="package", help="Set the FPGA package." + f"--{PACK}", type=str, metavar="str", help="Set the FPGA package." ) @click.option( "-p", @@ -38,7 +53,7 @@ ) @click.option( "-v", - "--verbose", + f"--{VERBOSE}", is_flag=True, help="Show the entire output of the command.", ) @@ -50,27 +65,30 @@ @click.option( "--verbose-pnr", is_flag=True, help="Show the pnr output of the command." ) -def cli( - ctx, - board, - fpga, - pack, - type, - size, - project_dir, - verbose, - verbose_yosys, - verbose_pnr, -): +def cli(ctx, **kwargs): """Bitstream timing analysis.""" + # -- Extract the arguments + project_dir = kwargs[PROJECT_DIR] + board = kwargs[BOARD] + fpga = kwargs[FPGA] + pack = kwargs[PACK] + _type = kwargs[TYPE] + size = kwargs[SIZE] + verbose = kwargs[VERBOSE] + verbose_yosys = kwargs[VERBOSE_YOSYS] + verbose_pnr = kwargs[VERBOSE_PNR] + + # -- Create the scons object + scons = SCons(project_dir) + # Run scons - exit_code = SCons(project_dir).time( + exit_code = scons.time( { "board": board, "fpga": fpga, "size": size, - "type": type, + "type": _type, "pack": pack, "verbose": { "all": verbose, @@ -79,4 +97,6 @@ def cli( }, } ) + + # -- Done! ctx.exit(exit_code) diff --git a/apio/managers/installer.py b/apio/managers/installer.py index b3673db4..a5c6fd06 100644 --- a/apio/managers/installer.py +++ b/apio/managers/installer.py @@ -21,6 +21,8 @@ # R0902: Too many instance attributes (12/7) (too-many-instance-attributes) # pylint: disable=R0902 +# R0801: Similar lines in 2 files +# pylint: disable=R0801 class Installer: """Installer. Class with methods for installing and managing apio packages"""