From 33447d1fee9292a6603efb68933311536abf446c Mon Sep 17 00:00:00 2001 From: Lars Asplund Date: Fri, 26 Jan 2024 21:39:47 +0100 Subject: [PATCH] Fixed linting --- examples/vhdl/embedded_python/run.py | 10 ++--- vunit/builtins.py | 9 ++-- vunit/python_pkg.py | 67 +++++++++++++++++----------- vunit/sim_if/activehdl.py | 3 +- vunit/test/runner.py | 14 +++--- vunit/test/suites.py | 2 +- vunit/ui/__init__.py | 52 ++++++++++----------- vunit/vhdl/check/src/check.vhd | 14 +++--- vunit/vhdl/python/run.py | 4 +- vunit/vhdl/run/src/run_api.vhd | 2 +- 10 files changed, 95 insertions(+), 82 deletions(-) diff --git a/examples/vhdl/embedded_python/run.py b/examples/vhdl/embedded_python/run.py index e1e043ec1..83f874f9d 100644 --- a/examples/vhdl/embedded_python/run.py +++ b/examples/vhdl/embedded_python/run.py @@ -13,7 +13,7 @@ def hello_world(): print("Hello World") -class Plot(): +class Plot: def __init__(self, x_points, y_limits, title, x_label, y_label): from matplotlib import pyplot as plt @@ -30,7 +30,7 @@ def __init__(self, x_points, y_limits, title, x_label, y_label): plt.ylim(*y_limits) x_vector = [x_points[0]] * len(x_points) y_vector = [(y_limits[0] + y_limits[1]) / 2] * len(x_points) - line, = plt.plot(x_vector, y_vector, 'r-') + (line,) = plt.plot(x_vector, y_vector, "r-") fig.canvas.draw() fig.canvas.flush_events() plt.show(block=False) @@ -78,8 +78,8 @@ def main(): lib = vu.add_library("lib") lib.add_source_files(root / "*.vhd") - vu.set_compile_option("rivierapro.vcom_flags" , ["-dbg"]) - vu.set_sim_option("rivierapro.vsim_flags" , ["-interceptcoutput"]) + vu.set_compile_option("rivierapro.vcom_flags", ["-dbg"]) + vu.set_sim_option("rivierapro.vsim_flags", ["-interceptcoutput"]) # Crashes RPRO for some reason. TODO: Fix when the C code is properly # integrated into the project. Must be able to debug the C code. # vu.set_sim_option("rivierapro.vsim_flags" , ["-cdebug"]) @@ -88,4 +88,4 @@ def main(): if __name__ == "__main__": - main() + main() diff --git a/vunit/builtins.py b/vunit/builtins.py index 332c6c232..d09625d14 100755 --- a/vunit/builtins.py +++ b/vunit/builtins.py @@ -89,9 +89,11 @@ def _add_data_types(self, external=None): for key in ["string", "integer_vector"]: self._add_files( - pattern=str(VHDL_PATH / "data_types" / "src" / "api" / f"external_{key!s}_pkg.vhd") - if external is None or key not in external or not external[key] or external[key] is True - else external[key], + pattern=( + str(VHDL_PATH / "data_types" / "src" / "api" / f"external_{key!s}_pkg.vhd") + if external is None or key not in external or not external[key] or external[key] is True + else external[key] + ), allow_empty=False, ) @@ -213,7 +215,6 @@ def _add_python(self): if not self._vhdl_standard >= VHDL.STD_2008: raise RuntimeError("Python package only supports vhdl 2008 and later") - # TODO: Create enums for FLIs python_package_supported_flis = set(["VHPI", "FLI"]) simulator_supported_flis = self._simulator_class.supported_foreign_language_interfaces() if not python_package_supported_flis & simulator_supported_flis: diff --git a/vunit/python_pkg.py b/vunit/python_pkg.py index 909625866..2ef1aa653 100644 --- a/vunit/python_pkg.py +++ b/vunit/python_pkg.py @@ -4,6 +4,9 @@ # # Copyright (c) 2014-2023, Lars Asplund lars.anders.asplund@gmail.com +""" +Temporary helper module to compile C-code used by python_pkg. +""" from pathlib import Path from glob import glob import subprocess @@ -11,6 +14,9 @@ def compile_vhpi_application(run_script_root, vu): + """ + Compile VHPI application used by Aldec's simulators. + """ path_to_shared_lib = (run_script_root / "vunit_out" / vu.get_simulator_name() / "libraries").resolve() if not path_to_shared_lib.exists(): path_to_shared_lib.mkdir(parents=True, exist_ok=True) @@ -20,31 +26,34 @@ def compile_vhpi_application(run_script_root, vu): python_shared_lib = f"python{sys.version_info[0]}{sys.version_info[1]}" path_to_python_pkg = Path(__file__).parent.resolve() / "vhdl" / "python" / "src" c_file_paths = [path_to_python_pkg / "python_pkg_vhpi.c", path_to_python_pkg / "python_pkg.c"] - path_to_simulator = Path(vu._simulator_class.find_prefix()).resolve() + path_to_simulator = Path(vu._simulator_class.find_prefix()).resolve() # pylint: disable=protected-access ccomp_executable = path_to_simulator / "ccomp.exe" - proc = subprocess.run([ - str(ccomp_executable), - "-vhpi", - "-dbg", - "-verbose", - "-o", - '"' + str(shared_lib) + '"', - "-l", - python_shared_lib, - "-l", - "python3", - "-l", - "_tkinter", - "-I", - '"' + str(path_to_python_include) + '"', - "-I", - '"' + str(path_to_python_pkg) + '"', - "-L", - '"' + str(path_to_python_libs) + '"', - " ".join(['"' + str(path) + '"' for path in c_file_paths])], + proc = subprocess.run( + [ + str(ccomp_executable), + "-vhpi", + "-dbg", + "-verbose", + "-o", + '"' + str(shared_lib) + '"', + "-l", + python_shared_lib, + "-l", + "python3", + "-l", + "_tkinter", + "-I", + '"' + str(path_to_python_include) + '"', + "-I", + '"' + str(path_to_python_pkg) + '"', + "-L", + '"' + str(path_to_python_libs) + '"', + " ".join(['"' + str(path) + '"' for path in c_file_paths]), + ], capture_output=True, text=True, + check=False, ) if proc.returncode != 0: @@ -53,8 +62,11 @@ def compile_vhpi_application(run_script_root, vu): raise RuntimeError("Failed to compile VHPI application") -def compile_fli_application(run_script_root, vu): - path_to_simulator = Path(vu._simulator_class.find_prefix()).resolve() +def compile_fli_application(run_script_root, vu): # pylint: disable=too-many-locals + """ + Compile FLI application used by Questa. + """ + path_to_simulator = Path(vu._simulator_class.find_prefix()).resolve() # pylint: disable=protected-access path_to_simulator_include = (path_to_simulator / ".." / "include").resolve() # 32 or 64 bit installation? @@ -63,6 +75,7 @@ def compile_fli_application(run_script_root, vu): [vsim_executable, "-version"], capture_output=True, text=True, + check=False, ) if proc.returncode != 0: print(proc.stderr) @@ -94,16 +107,17 @@ def compile_fli_application(run_script_root, vu): args += ["-ansi", "-pedantic"] args += [ - '-I' + str(path_to_simulator_include), - '-I' + str(path_to_python_include), + "-I" + str(path_to_simulator_include), + "-I" + str(path_to_python_include), "-freg-struct-return", - str(c_file_path) + str(c_file_path), ] proc = subprocess.run( args, capture_output=True, text=True, + check=False, ) if proc.returncode != 0: print(proc.stdout) @@ -139,6 +153,7 @@ def compile_fli_application(run_script_root, vu): args, capture_output=True, text=True, + check=False, ) if proc.returncode != 0: print(proc.stdout) diff --git a/vunit/sim_if/activehdl.py b/vunit/sim_if/activehdl.py index 7d0f92cc4..ac83c62ae 100644 --- a/vunit/sim_if/activehdl.py +++ b/vunit/sim_if/activehdl.py @@ -136,8 +136,7 @@ def compile_vhdl_file_command(self, source_file): str(Path(self._library_cfg).parent), ] + source_file.compile_options.get("activehdl.vcom_flags", []) - + - [ + + [ self._std_str(source_file.get_vhdl_standard()), "-work", source_file.library.name, diff --git a/vunit/test/runner.py b/vunit/test/runner.py index 86ec32ce5..9b12fae43 100644 --- a/vunit/test/runner.py +++ b/vunit/test/runner.py @@ -33,7 +33,7 @@ class TestRunner(object): # pylint: disable=too-many-instance-attributes VERBOSITY_NORMAL = 1 VERBOSITY_VERBOSE = 2 - def __init__(# pylint: disable=too-many-arguments + def __init__( # pylint: disable=too-many-arguments self, report, output_path, @@ -200,7 +200,7 @@ def _add_skipped_tests(self, test_suite, results, start_time, num_tests, output_ results[name] = SKIPPED self._add_results(test_suite, results, start_time, num_tests, output_file_name) - def _run_test_suite(# pylint: disable=too-many-locals + def _run_test_suite( # pylint: disable=too-many-locals self, test_suite, write_stdout, num_tests, output_path, output_file_name ): """ @@ -226,7 +226,7 @@ def _run_test_suite(# pylint: disable=too-many-locals if write_stdout: output_from = self._stdout_ansi else: - color_output_file = Path(color_output_file_name).open(# pylint: disable=consider-using-with + color_output_file = Path(color_output_file_name).open( # pylint: disable=consider-using-with "w", encoding="utf-8" ) output_from = color_output_file @@ -244,9 +244,7 @@ def read_output(): return contents results = test_suite.run( - output_path=output_path, - read_output=read_output, - run_script_path=self._run_script_path + output_path=output_path, read_output=read_output, run_script_path=self._run_script_path ) except KeyboardInterrupt as exk: self._add_skipped_tests(test_suite, results, start_time, num_tests, output_file_name) @@ -302,7 +300,7 @@ def _create_test_mapping_file(self, test_suites): mapping.add(f"{Path(test_output).name!s} {test_suite.name!s}") # Sort by everything except hash - mapping = sorted(mapping, key=lambda value: value[value.index(" "):]) + mapping = sorted(mapping, key=lambda value: value[value.index(" ") :]) with mapping_file_name.open("w", encoding="utf-8") as fptr: for value in mapping: @@ -457,7 +455,7 @@ def wrap(file_obj, use_color=True): NOTE: imports colorama here to avoid dependency from setup.py importing VUnit before colorama is installed """ - from colorama import (# type: ignore # pylint: disable=import-outside-toplevel + from colorama import ( # type: ignore # pylint: disable=import-outside-toplevel AnsiToWin32, ) diff --git a/vunit/test/suites.py b/vunit/test/suites.py index 4e138c379..70faa500e 100644 --- a/vunit/test/suites.py +++ b/vunit/test/suites.py @@ -260,7 +260,7 @@ def _read_test_results(self, file_name): # pylint: disable=too-many-branches for line in test_results.splitlines(): if line.startswith("test_start:"): - test_name = line[len("test_start:"):] + test_name = line[len("test_start:") :] if test_name not in test_starts: test_starts.append(test_name) diff --git a/vunit/ui/__init__.py b/vunit/ui/__init__.py index 21a33b79e..4a511f187 100644 --- a/vunit/ui/__init__.py +++ b/vunit/ui/__init__.py @@ -60,7 +60,7 @@ class VUnit(object): # pylint: disable=too-many-instance-attributes, too-many-p def from_argv( cls, argv=None, - vhdl_standard: Optional[str]=None, + vhdl_standard: Optional[str] = None, ): """ Create VUnit instance from command line arguments. @@ -91,7 +91,7 @@ def from_argv( def from_args( cls, args, - vhdl_standard: Optional[str]=None, + vhdl_standard: Optional[str] = None, ): """ Create VUnit instance from args namespace. @@ -115,7 +115,7 @@ def from_args( def __init__( self, args, - vhdl_standard: Optional[str]=None, + vhdl_standard: Optional[str] = None, ): self._args = args @@ -217,7 +217,7 @@ def _which_vhdl_standard(self, vhdl_standard: Optional[str]) -> VHDLStandard: return VHDL.standard(vhdl_standard) - def add_external_library(self, library_name, path: Union[str, Path], vhdl_standard: Optional[str]=None): + def add_external_library(self, library_name, path: Union[str, Path], vhdl_standard: Optional[str] = None): """ Add an externally compiled library as a black-box @@ -243,7 +243,7 @@ def add_external_library(self, library_name, path: Union[str, Path], vhdl_standa ) return self.library(library_name) - def add_source_files_from_csv(self, project_csv_path: Union[str, Path], vhdl_standard: Optional[str]=None): + def add_source_files_from_csv(self, project_csv_path: Union[str, Path], vhdl_standard: Optional[str] = None): """ Add a project configuration, mapping all the libraries and files @@ -278,8 +278,8 @@ def add_source_files_from_csv(self, project_csv_path: Union[str, Path], vhdl_sta def add_library( self, library_name: str, - vhdl_standard: Optional[str]=None, - allow_duplicate: Optional[bool]=False, + vhdl_standard: Optional[str] = None, + allow_duplicate: Optional[bool] = False, ): """ Add a library managed by VUnit. @@ -321,7 +321,7 @@ def library(self, library_name: str): def get_libraries( self, pattern="*", - allow_empty: Optional[bool]=False, + allow_empty: Optional[bool] = False, ): """ Get a list of libraries @@ -342,7 +342,7 @@ def get_libraries( return LibraryList(results) - def set_attribute(self, name: str, value: str, allow_empty: Optional[bool]=False): + def set_attribute(self, name: str, value: str, allow_empty: Optional[bool] = False): """ Set a value of attribute in all |configurations| @@ -363,7 +363,7 @@ def set_attribute(self, name: str, value: str, allow_empty: Optional[bool]=False for test_bench in check_not_empty(test_benches, allow_empty, "No test benches found"): test_bench.set_attribute(name, value) - def set_generic(self, name: str, value: str, allow_empty: Optional[bool]=False): + def set_generic(self, name: str, value: str, allow_empty: Optional[bool] = False): """ Set a value of generic in all |configurations| @@ -384,7 +384,7 @@ def set_generic(self, name: str, value: str, allow_empty: Optional[bool]=False): for test_bench in check_not_empty(test_benches, allow_empty, "No test benches found"): test_bench.set_generic(name.lower(), value) - def set_parameter(self, name: str, value: str, allow_empty: Optional[bool]=False): + def set_parameter(self, name: str, value: str, allow_empty: Optional[bool] = False): """ Set value of parameter in all |configurations| @@ -409,8 +409,8 @@ def set_sim_option( self, name: str, value: str, - allow_empty: Optional[bool]=False, - overwrite: Optional[bool]=True, + allow_empty: Optional[bool] = False, + overwrite: Optional[bool] = True, ): """ Set simulation option in all |configurations| @@ -433,7 +433,7 @@ def set_sim_option( for test_bench in check_not_empty(test_benches, allow_empty, "No test benches found"): test_bench.set_sim_option(name, value, overwrite) - def set_compile_option(self, name: str, value: str, allow_empty: Optional[bool]=False): + def set_compile_option(self, name: str, value: str, allow_empty: Optional[bool] = False): """ Set compile option of all files @@ -455,7 +455,7 @@ def set_compile_option(self, name: str, value: str, allow_empty: Optional[bool]= for source_file in check_not_empty(source_files, allow_empty, "No source files found"): source_file.set_compile_option(name, value) - def add_compile_option(self, name: str, value: str, allow_empty: Optional[bool]=False): + def add_compile_option(self, name: str, value: str, allow_empty: Optional[bool] = False): """ Add compile option to all files @@ -470,7 +470,7 @@ def add_compile_option(self, name: str, value: str, allow_empty: Optional[bool]= for source_file in check_not_empty(source_files, allow_empty, "No source files found"): source_file.add_compile_option(name, value) - def get_source_file(self, file_name: Union[str, Path], library_name: Optional[str]=None): + def get_source_file(self, file_name: Union[str, Path], library_name: Optional[str] = None): """ Get a source file @@ -494,8 +494,8 @@ def get_source_file(self, file_name: Union[str, Path], library_name: Optional[st def get_source_files( self, pattern="*", - library_name: Optional[str]=None, - allow_empty: Optional[bool]=False, + library_name: Optional[str] = None, + allow_empty: Optional[bool] = False, ): """ Get a list of source files @@ -523,21 +523,21 @@ def get_source_files( results, allow_empty, f"Pattern {pattern!r} did not match any file" - +(f"within library {library_name!s}" if library_name is not None else ""), + + (f"within library {library_name!s}" if library_name is not None else ""), ) return SourceFileList(results) - def add_source_files(# pylint: disable=too-many-arguments + def add_source_files( # pylint: disable=too-many-arguments self, pattern, library_name: str, preprocessors=None, include_dirs=None, defines=None, - allow_empty: Optional[bool]=False, - vhdl_standard: Optional[str]=None, - no_parse: Optional[bool]=False, + allow_empty: Optional[bool] = False, + vhdl_standard: Optional[str] = None, + no_parse: Optional[bool] = False, file_type=None, ): """ @@ -573,15 +573,15 @@ def add_source_files(# pylint: disable=too-many-arguments file_type=file_type, ) - def add_source_file(# pylint: disable=too-many-arguments + def add_source_file( # pylint: disable=too-many-arguments self, file_name: Union[str, Path], library_name: str, preprocessors=None, include_dirs=None, defines=None, - vhdl_standard: Optional[str]=None, - no_parse: Optional[bool]=False, + vhdl_standard: Optional[str] = None, + no_parse: Optional[bool] = False, file_type=None, ): """ diff --git a/vunit/vhdl/check/src/check.vhd b/vunit/vhdl/check/src/check.vhd index 6deab5a10..bc0649d62 100644 --- a/vunit/vhdl/check/src/check.vhd +++ b/vunit/vhdl/check/src/check.vhd @@ -139,37 +139,37 @@ package body check_pkg is end if; log(check_result); end; - + impure function is_pass(check_result : check_result_t) return boolean is begin return check_result.p_is_pass; end; - + impure function get_checker(check_result : check_result_t) return checker_t is begin return check_result.p_checker; end; - + impure function get_msg(check_result : check_result_t) return string is begin return to_string(check_result.p_msg); end; - + impure function get_log_level(check_result : check_result_t) return log_level_t is begin return check_result.p_level; end; - + impure function get_line_num(check_result : check_result_t) return natural is begin return check_result.p_line_num; end; - + impure function get_file_name(check_result : check_result_t) return string is begin return to_string(check_result.p_file_name); end; - + ----------------------------------------------------------------------------- diff --git a/vunit/vhdl/python/run.py b/vunit/vhdl/python/run.py index 9b10d80c4..7e052d90a 100644 --- a/vunit/vhdl/python/run.py +++ b/vunit/vhdl/python/run.py @@ -31,8 +31,8 @@ def main(): lib = vu.add_library("lib") lib.add_source_files(root / "test" / "*.vhd") - vu.set_compile_option("rivierapro.vcom_flags" , ["-dbg"]) - vu.set_sim_option("rivierapro.vsim_flags" , ["-interceptcoutput"]) + vu.set_compile_option("rivierapro.vcom_flags", ["-dbg"]) + vu.set_sim_option("rivierapro.vsim_flags", ["-interceptcoutput"]) # Crashes RPRO for some reason. TODO: Fix when the C code is properly # integrated into the project. Must be able to debug the C code. # vu.set_sim_option("rivierapro.vsim_flags" , ["-cdebug"]) diff --git a/vunit/vhdl/run/src/run_api.vhd b/vunit/vhdl/run/src/run_api.vhd index 2b5487333..de0f5ce60 100644 --- a/vunit/vhdl/run/src/run_api.vhd +++ b/vunit/vhdl/run/src/run_api.vhd @@ -162,7 +162,7 @@ package run_pkg is impure function tb_path ( constant runner_cfg : string) return string; - + impure function run_script_path( constant runner_cfg : string) return string;