Skip to content

Commit

Permalink
Fixed linting
Browse files Browse the repository at this point in the history
  • Loading branch information
LarsAsplund committed Jan 27, 2024
1 parent 73f3764 commit 33447d1
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 82 deletions.
10 changes: 5 additions & 5 deletions examples/vhdl/embedded_python/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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"])
Expand All @@ -88,4 +88,4 @@ def main():


if __name__ == "__main__":
main()
main()
9 changes: 5 additions & 4 deletions vunit/builtins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand Down Expand Up @@ -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:
Expand Down
67 changes: 41 additions & 26 deletions vunit/python_pkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@
#
# Copyright (c) 2014-2023, Lars Asplund [email protected]

"""
Temporary helper module to compile C-code used by python_pkg.
"""
from pathlib import Path
from glob import glob
import subprocess
import sys


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)
Expand All @@ -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:
Expand All @@ -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?
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions vunit/sim_if/activehdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 6 additions & 8 deletions vunit/test/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
):
"""
Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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,
)

Expand Down
2 changes: 1 addition & 1 deletion vunit/test/suites.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Loading

0 comments on commit 33447d1

Please sign in to comment.