From 56395a2132e744e3bdaa77f382ac51d80ccf261d Mon Sep 17 00:00:00 2001 From: eine Date: Wed, 15 Jan 2020 06:25:33 +0100 Subject: [PATCH] examples/vhdl: use pathlib instead of join and dirname --- examples/vhdl/array/run.py | 8 ++-- examples/vhdl/array_axis_vcs/run.py | 8 ++-- examples/vhdl/axi_dma/run.py | 6 +-- examples/vhdl/check/run.py | 4 +- examples/vhdl/com/run.py | 8 ++-- examples/vhdl/composite_generics/run.py | 4 +- examples/vhdl/coverage/run.py | 4 +- examples/vhdl/external_buffer/cp.py | 16 +++---- examples/vhdl/external_buffer/run.py | 46 +++++++++----------- examples/vhdl/generate_tests/run.py | 12 +++-- examples/vhdl/json4vhdl/run.py | 8 ++-- examples/vhdl/logging/run.py | 4 +- examples/vhdl/run/run.py | 8 ++-- examples/vhdl/third_party_integration/run.py | 4 +- examples/vhdl/uart/run.py | 8 ++-- examples/vhdl/user_guide/run.py | 4 +- examples/vhdl/vivado/run.py | 14 +++--- vunit/ui/library.py | 2 +- 18 files changed, 79 insertions(+), 89 deletions(-) diff --git a/examples/vhdl/array/run.py b/examples/vhdl/array/run.py index f9c2ebad48..7d14d74d74 100644 --- a/examples/vhdl/array/run.py +++ b/examples/vhdl/array/run.py @@ -13,18 +13,16 @@ loading it from csv and raw files. """ -from os.path import join, dirname +from pathlib import Path from vunit import VUnit -root = dirname(__file__) - vu = VUnit.from_argv() vu.add_osvvm() -src_path = join(dirname(__file__), "src") +src_path = Path(__file__).parent / "src" vu.add_library("lib").add_source_files( - [join(src_path, "*.vhd"), join(src_path, "test", "*.vhd")] + [src_path / "*.vhd", src_path / "test" / "*.vhd"] ) vu.set_compile_option("ghdl.flags", ["-frelaxed"]) diff --git a/examples/vhdl/array_axis_vcs/run.py b/examples/vhdl/array_axis_vcs/run.py index 6fc1d98982..2edbde3700 100644 --- a/examples/vhdl/array_axis_vcs/run.py +++ b/examples/vhdl/array_axis_vcs/run.py @@ -16,17 +16,15 @@ :vunit_file:`vhdl/verification_components/test/tb_axi_stream.vhd `. """ -from os.path import join, dirname +from pathlib import Path from vunit import VUnit vu = VUnit.from_argv() vu.add_verification_components() -src_path = join(dirname(__file__), "src") +src_path = Path(__file__).parent / "src" -vu.add_library("lib").add_source_files( - [join(src_path, "*.vhd"), join(src_path, "**", "*.vhd")] -) +vu.add_library("lib").add_source_files([src_path / "*.vhd", src_path / "**" / "*.vhd"]) # vu.set_sim_option('modelsim.init_files.after_load',['runall_addwave.do']) diff --git a/examples/vhdl/axi_dma/run.py b/examples/vhdl/axi_dma/run.py index 5670922fb3..ca39b816b6 100644 --- a/examples/vhdl/axi_dma/run.py +++ b/examples/vhdl/axi_dma/run.py @@ -15,17 +15,17 @@ via AXI-lite. """ -from os.path import join, dirname +from pathlib import Path from vunit import VUnit vu = VUnit.from_argv() vu.add_osvvm() vu.add_verification_components() -src_path = join(dirname(__file__), "src") +src_path = Path(__file__).parent / "src" vu.add_library("axi_dma_lib").add_source_files( - [join(src_path, "*.vhd"), join(src_path, "test", "*.vhd")] + [src_path / "*.vhd", src_path / "test" / "*.vhd"] ) vu.main() diff --git a/examples/vhdl/check/run.py b/examples/vhdl/check/run.py index 726d95be49..62a0140b11 100644 --- a/examples/vhdl/check/run.py +++ b/examples/vhdl/check/run.py @@ -11,7 +11,7 @@ Demonstrates the VUnit check library. """ -from os.path import join, dirname +from pathlib import Path from vunit import VUnit vu = VUnit.from_argv() @@ -38,6 +38,6 @@ vu.enable_check_preprocessing() -vu.add_library("lib").add_source_files(join(dirname(__file__), "tb_example.vhd")) +vu.add_library("lib").add_source_files(Path(__file__).parent / "tb_example.vhd") vu.main() diff --git a/examples/vhdl/com/run.py b/examples/vhdl/com/run.py index 4dc8667da4..dbec0c4548 100644 --- a/examples/vhdl/com/run.py +++ b/examples/vhdl/com/run.py @@ -13,7 +13,7 @@ can be found in the :ref:`com user guide `. """ -from os.path import join, dirname +from pathlib import Path from vunit import VUnit vu = VUnit.from_argv() @@ -21,7 +21,9 @@ vu.add_verification_components() vu.add_osvvm() -vu.add_library("lib").add_source_files(join(dirname(__file__), "src", "*.vhd")) -vu.add_library("tb_lib").add_source_files(join(dirname(__file__), "test", "*.vhd")) +root = Path(__file__).parent + +vu.add_library("lib").add_source_files(root / "src" / "*.vhd") +vu.add_library("tb_lib").add_source_files(root / "test" / "*.vhd") vu.main() diff --git a/examples/vhdl/composite_generics/run.py b/examples/vhdl/composite_generics/run.py index 197fc04469..8ed607453c 100644 --- a/examples/vhdl/composite_generics/run.py +++ b/examples/vhdl/composite_generics/run.py @@ -11,7 +11,7 @@ See `Enable Your Simulator to Handle Complex Top-Level Generics `_. """ -from os.path import join, dirname +from pathlib import Path from vunit import VUnit @@ -22,7 +22,7 @@ def encode(tb_cfg): vu = VUnit.from_argv() tb_lib = vu.add_library("tb_lib") -tb_lib.add_source_files(join(dirname(__file__), "test", "*.vhd")) +tb_lib.add_source_files(Path(__file__).parent / "test" / "*.vhd") test_1 = tb_lib.test_bench("tb_composite_generics").test("Test 1") diff --git a/examples/vhdl/coverage/run.py b/examples/vhdl/coverage/run.py index 71da7977a1..c118dc63a9 100644 --- a/examples/vhdl/coverage/run.py +++ b/examples/vhdl/coverage/run.py @@ -4,7 +4,7 @@ # # Copyright (c) 2014-2019, Lars Asplund lars.anders.asplund@gmail.com -from os.path import join, dirname +from pathlib import Path from vunit import VUnit @@ -15,7 +15,7 @@ def post_run(results): vu = VUnit.from_argv() lib = vu.add_library("lib") -lib.add_source_files(join(dirname(__file__), "*.vhd")) +lib.add_source_files(Path(__file__).parent / "*.vhd") lib.set_compile_option("rivierapro.vcom_flags", ["-coverage", "bs"]) lib.set_compile_option("rivierapro.vlog_flags", ["-coverage", "bs"]) diff --git a/examples/vhdl/external_buffer/cp.py b/examples/vhdl/external_buffer/cp.py index 49eccc5867..655b65a333 100644 --- a/examples/vhdl/external_buffer/cp.py +++ b/examples/vhdl/external_buffer/cp.py @@ -5,25 +5,23 @@ # Copyright (c) 2014-2019, Lars Asplund lars.anders.asplund@gmail.com from vunit import VUnit -from os import popen -from os.path import join, dirname +from subprocess import check_call +from pathlib import Path -src_path = join(dirname(__file__), "src") +src_path = Path(__file__).parent / "src" -c_obj = join(src_path, "cp.o") +c_obj = src_path / "cp.o" # Compile C application to an object -print( - popen(" ".join(["gcc", "-fPIC", "-c", join(src_path, "cp.c"), "-o", c_obj])).read() -) +check_call(["gcc", "-fPIC", "-c", str(src_path / "cp.c"), "-o", str(c_obj)]) # Enable the external feature for strings vu = VUnit.from_argv(vhdl_standard="2008", compile_builtins=False) vu.add_builtins({"string": True}) lib = vu.add_library("lib") -lib.add_source_files(join(src_path, "tb_extcp_*.vhd")) +lib.add_source_files(str(src_path / "tb_extcp_*.vhd")) # Add the C object to the elaboration of GHDL -vu.set_sim_option("ghdl.elab_flags", ["-Wl," + c_obj]) +vu.set_sim_option("ghdl.elab_flags", ["-Wl," + str(c_obj)]) vu.main() diff --git a/examples/vhdl/external_buffer/run.py b/examples/vhdl/external_buffer/run.py index 586a92e307..c7085aa2e9 100644 --- a/examples/vhdl/external_buffer/run.py +++ b/examples/vhdl/external_buffer/run.py @@ -26,33 +26,29 @@ """ from vunit import VUnit, ROOT -from os import popen -from os.path import join, dirname +from subprocess import check_call +from pathlib import Path -src_path = join(dirname(__file__), "src") -ext_srcs = join(ROOT, "vunit", "vhdl", "data_types", "src", "external", "ghdl") +src_path = Path(__file__).parent / "src" +ext_srcs = Path(ROOT) / "vunit" / "vhdl" / "data_types" / "src" / "external" / "ghdl" # Compile C applications to an objects -c_iobj = join(src_path, "imain.o") -c_bobj = join(src_path, "bmain.o") +c_iobj = src_path / "imain.o" +c_bobj = src_path / "bmain.o" for val in [["int32_t", c_iobj], ["uint8_t", c_bobj]]: - print( - popen( - " ".join( - [ - "gcc", - "-fPIC", - "-DTYPE=" + val[0], - "-I", - ext_srcs, - "-c", - join(src_path, "main.c"), - "-o", - val[1], - ] - ) - ).read() + check_call( + [ + "gcc", + "-fPIC", + "-DTYPE=" + val[0], + "-I", + ext_srcs, + "-c", + src_path / "main.c", + "-o", + val[1], + ] ) # Enable the external feature for strings/byte_vectors and integer_vectors @@ -60,19 +56,19 @@ vu.add_builtins({"string": True, "integer": True}) lib = vu.add_library("lib") -lib.add_source_files(join(src_path, "tb_ext_*.vhd")) +lib.add_source_files(src_path / "tb_ext_*.vhd") # Add the C object to the elaboration of GHDL for tb in lib.get_test_benches(pattern="*tb_ext*", allow_empty=False): tb.set_sim_option( "ghdl.elab_flags", - ["-Wl," + c_bobj, "-Wl,-Wl,--version-script=" + join(ext_srcs, "grt.ver")], + ["-Wl," + str(c_bobj), "-Wl,-Wl,--version-script=" + str(ext_srcs / "grt.ver")], overwrite=True, ) for tb in lib.get_test_benches(pattern="*tb_ext*_integer*", allow_empty=False): tb.set_sim_option( "ghdl.elab_flags", - ["-Wl," + c_iobj, "-Wl,-Wl,--version-script=" + join(ext_srcs, "grt.ver")], + ["-Wl," + str(c_iobj), "-Wl,-Wl,--version-script=" + str(ext_srcs / "grt.ver")], overwrite=True, ) diff --git a/examples/vhdl/generate_tests/run.py b/examples/vhdl/generate_tests/run.py index 7fc1acfc79..7fc6dfdc3c 100644 --- a/examples/vhdl/generate_tests/run.py +++ b/examples/vhdl/generate_tests/run.py @@ -13,7 +13,7 @@ to create test bench output files in location specified by VUnit python runner. """ -from os.path import join, dirname +from pathlib import Path from itertools import product from vunit import VUnit @@ -30,10 +30,10 @@ def post_check(output_path): expected = ", ".join([str(data_width), str(sign).lower()]) + "\n" - output_file = join(output_path, "generics.txt") + output_file = Path(output_path) / "generics.txt" - print("Post check: %s" % output_file) - with open(output_file, "r") as fread: + print("Post check: %s" % str(output_file)) + with output_file.open("r") as fread: got = fread.read() if not got == expected: print("Content mismatch, got %r expected %r" % (got, expected)) @@ -60,11 +60,9 @@ def generate_tests(obj, signs, data_widths): ) -test_path = join(dirname(__file__), "test") - vu = VUnit.from_argv() lib = vu.add_library("lib") -lib.add_source_files(join(test_path, "*.vhd")) +lib.add_source_files(Path(__file__).parent / "test" / "*.vhd") tb_generated = lib.test_bench("tb_generated") diff --git a/examples/vhdl/json4vhdl/run.py b/examples/vhdl/json4vhdl/run.py index 4ff6d10037..3c4a7e2af7 100644 --- a/examples/vhdl/json4vhdl/run.py +++ b/examples/vhdl/json4vhdl/run.py @@ -13,17 +13,17 @@ This is an alternative to composite generics, that supports any depth in the content structure. """ -from os.path import join, dirname +from pathlib import Path from vunit import VUnit, read_json, encode_json -root = dirname(__file__) +test_path = Path(__file__).parent / "src" / "test" vu = VUnit.from_argv() vu.add_json4vhdl() -vu.add_library("test").add_source_files(join(root, "src/test/*.vhd")) +vu.add_library("test").add_source_files(test_path / "*.vhd") -tb_cfg = read_json(join(root, "src/test/data/data.json")) +tb_cfg = read_json(test_path / "data" / "data.json") tb_cfg["dump_debug_data"] = False vu.set_generic("tb_cfg", encode_json(tb_cfg)) diff --git a/examples/vhdl/logging/run.py b/examples/vhdl/logging/run.py index 8f555a5524..1e8194faa1 100644 --- a/examples/vhdl/logging/run.py +++ b/examples/vhdl/logging/run.py @@ -11,10 +11,10 @@ Demonstrates VUnit's support for logging. """ -from os.path import join, dirname +from pathlib import Path from vunit import VUnit vu = VUnit.from_argv() -vu.add_library("lib").add_source_files(join(dirname(__file__), "*.vhd")) +vu.add_library("lib").add_source_files(Path(__file__).parent / "*.vhd") vu.main() diff --git a/examples/vhdl/run/run.py b/examples/vhdl/run/run.py index 5fc7a1d9dd..9e932ce972 100644 --- a/examples/vhdl/run/run.py +++ b/examples/vhdl/run/run.py @@ -11,16 +11,16 @@ Demonstrates the VUnit run library. """ -from os.path import join, dirname +from pathlib import Path from vunit import VUnit -root = dirname(__file__) +root = Path(__file__).parent vu = VUnit.from_argv() lib = vu.add_library("lib") -lib.add_source_files(join(root, "*.vhd")) +lib.add_source_files(root / "*.vhd") tb_with_lower_level_control = lib.entity("tb_with_lower_level_control") -tb_with_lower_level_control.scan_tests_from_file(join(root, "test_control.vhd")) +tb_with_lower_level_control.scan_tests_from_file(root / "test_control.vhd") vu.main() diff --git a/examples/vhdl/third_party_integration/run.py b/examples/vhdl/third_party_integration/run.py index 067d83a248..371fa0c74f 100644 --- a/examples/vhdl/third_party_integration/run.py +++ b/examples/vhdl/third_party_integration/run.py @@ -4,9 +4,9 @@ # # Copyright (c) 2014-2019, Lars Asplund lars.anders.asplund@gmail.com -from os.path import join, dirname +from pathlib import Path from vunit import VUnit vu = VUnit.from_argv() -vu.add_library("lib").add_source_files(join(dirname(__file__), "test", "*.vhd")) +vu.add_library("lib").add_source_files(Path(__file__).parent / "test" / "*.vhd") vu.main() diff --git a/examples/vhdl/uart/run.py b/examples/vhdl/uart/run.py index 4fff1a480a..58236225f4 100644 --- a/examples/vhdl/uart/run.py +++ b/examples/vhdl/uart/run.py @@ -12,16 +12,16 @@ typical module. """ -from os.path import join, dirname +from pathlib import Path from vunit import VUnit vu = VUnit.from_argv() vu.add_osvvm() vu.add_verification_components() -src_path = join(dirname(__file__), "src") +src_path = Path(__file__).parent / "src" -vu.add_library("uart_lib").add_source_files(join(src_path, "*.vhd")) -vu.add_library("tb_uart_lib").add_source_files(join(src_path, "test", "*.vhd")) +vu.add_library("uart_lib").add_source_files(src_path / "*.vhd") +vu.add_library("tb_uart_lib").add_source_files(src_path / "test" / "*.vhd") vu.main() diff --git a/examples/vhdl/user_guide/run.py b/examples/vhdl/user_guide/run.py index 717d9c6d91..bff01486fb 100644 --- a/examples/vhdl/user_guide/run.py +++ b/examples/vhdl/user_guide/run.py @@ -12,9 +12,9 @@ :ref:`User Guide `. """ -from os.path import join, dirname +from pathlib import Path from vunit import VUnit vu = VUnit.from_argv() -vu.add_library("lib").add_source_files(join(dirname(__file__), "*.vhd")) +vu.add_library("lib").add_source_files(Path(__file__).parent / "*.vhd") vu.main() diff --git a/examples/vhdl/vivado/run.py b/examples/vhdl/vivado/run.py index 555ab72399..0dc17149e1 100644 --- a/examples/vhdl/vivado/run.py +++ b/examples/vhdl/vivado/run.py @@ -12,22 +12,22 @@ Vivado IPs with VUnit. """ -from os.path import join, dirname +from pathlib import Path from vunit import VUnit from vivado_util import add_vivado_ip -root = dirname(__file__) -src_path = join(root, "src") +root = Path(__file__).parent +src_path = root / "src" vu = VUnit.from_argv() -vu.add_library("lib").add_source_files(join(src_path, "*.vhd")) -vu.add_library("tb_lib").add_source_files(join(src_path, "test", "*.vhd")) +vu.add_library("lib").add_source_files(src_path / "*.vhd") +vu.add_library("tb_lib").add_source_files(src_path / "test" / "*.vhd") add_vivado_ip( vu, - output_path=join(root, "vivado_libs"), - project_file=join(root, "myproject", "myproject.xpr"), + output_path=root / "vivado_libs", + project_file=root / "myproject" / "myproject.xpr", ) vu.main() diff --git a/vunit/ui/library.py b/vunit/ui/library.py index a7781b6958..fb0dd82744 100644 --- a/vunit/ui/library.py +++ b/vunit/ui/library.py @@ -195,7 +195,7 @@ def add_source_files( # pylint: disable=too-many-arguments file_names: List[str] = [] for pattern_instance in patterns: - new_file_names = glob(pattern_instance) + new_file_names = glob(str(pattern_instance)) check_not_empty( new_file_names, allow_empty,