Skip to content

Commit 1af5128

Browse files
committed
use pathlib instead of join, dirname, etc.
1 parent 0fab3c8 commit 1af5128

70 files changed

Lines changed: 1062 additions & 915 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/conf.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import os
44
import sys
5-
from os.path import join
5+
from pathlib import Path
66

77
# blog_title = u"VUnit Blog"
88
# blog_baseurl = "http://vunit.github.io"
@@ -70,9 +70,9 @@
7070

7171
html_static_path = ["_static"]
7272

73-
html_logo = join(html_static_path[0], "VUnit_logo_420x420.png")
73+
html_logo = str(Path(html_static_path[0]) / "VUnit_logo_420x420.png")
7474

75-
html_favicon = join(html_static_path[0], "vunit.ico")
75+
html_favicon = str(Path(html_static_path[0]) / "vunit.ico")
7676

7777
# Output file base name for HTML help builder.
7878
htmlhelp_basename = "vunitdoc"

examples/vhdl/vivado/vivado_util.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# Copyright (c) 2014-2020, Lars Asplund lars.anders.asplund@gmail.com
66

77
import sys
8-
from os.path import join, exists, abspath, dirname
8+
from pathlib import Path
99
from vunit.sim_if.factory import SIMULATOR_FACTORY
1010
from vunit.vivado import (
1111
run_vivado,
@@ -19,35 +19,40 @@ def add_vivado_ip(vunit_obj, output_path, project_file):
1919
Add vivado (and compile if necessary) vivado ip to vunit project.
2020
"""
2121

22-
if not exists(project_file):
22+
if not Path(project_file).exists():
2323
print("Could not find vivado project %s" % project_file)
2424
sys.exit(1)
2525

26-
standard_library_path = join(output_path, "standard")
26+
opath = Path(output_path)
27+
28+
standard_library_path = str(opath / "standard")
2729
compile_standard_libraries(vunit_obj, standard_library_path)
2830

29-
project_ip_path = join(output_path, "project_ip")
31+
project_ip_path = str(opath / "project_ip")
3032
add_project_ip(vunit_obj, project_file, project_ip_path)
3133

3234

3335
def compile_standard_libraries(vunit_obj, output_path):
3436
"""
3537
Compile Xilinx standard libraries using Vivado TCL command
3638
"""
37-
done_token = join(output_path, "all_done.txt")
39+
done_token = str(Path(output_path) / "all_done.txt")
3840

3941
simulator_class = SIMULATOR_FACTORY.select_simulator()
4042

41-
if not exists(done_token):
42-
print("Compiling standard libraries into %s ..." % abspath(output_path))
43+
if not Path(done_token).exists():
44+
print(
45+
"Compiling standard libraries into %s ..."
46+
% str(Path(output_path).resolve())
47+
)
4348
simname = simulator_class.name
4449

4550
# Vivado calls rivierapro for riviera
4651
if simname == "rivierapro":
4752
simname = "riviera"
4853

4954
run_vivado(
50-
join(dirname(__file__), "tcl", "compile_standard_libs.tcl"),
55+
str(Path(__file__).parent / "tcl" / "compile_standard_libs.tcl"),
5156
tcl_args=[
5257
simname,
5358
simulator_class.find_prefix().replace("\\", "/"),
@@ -57,12 +62,13 @@ def compile_standard_libraries(vunit_obj, output_path):
5762

5863
else:
5964
print(
60-
"Standard libraries already exists in %s, skipping" % abspath(output_path)
65+
"Standard libraries already exists in %s, skipping"
66+
% str(Path(output_path).resolve())
6167
)
6268

6369
for library_name in ["unisim", "unimacro", "unifast", "secureip", "xpm"]:
64-
path = join(output_path, library_name)
65-
if exists(path):
70+
path = str(Path(output_path) / library_name)
71+
if Path(path).exists():
6672
vunit_obj.add_external_library(library_name, path)
6773

6874
with open(done_token, "w") as fptr:
@@ -79,16 +85,16 @@ def add_project_ip(vunit_obj, project_file, output_path, vivado_path=None, clean
7985
returns the list of SourceFile objects added
8086
"""
8187

82-
compile_order_file = join(output_path, "compile_order.txt")
88+
compile_order_file = str(Path(output_path) / "compile_order.txt")
8389

84-
if clean or not exists(compile_order_file):
90+
if clean or not Path(compile_order_file).exists():
8591
create_compile_order_file(
8692
project_file, compile_order_file, vivado_path=vivado_path
8793
)
8894
else:
8995
print(
9096
"Vivado project Compile order already exists, re-using: %s"
91-
% abspath(compile_order_file)
97+
% str(Path(compile_order_file).resolve())
9298
)
9399

94100
return add_from_compile_order_file(vunit_obj, compile_order_file)

tests/acceptance/artificial/verilog/run.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
#
55
# Copyright (c) 2014-2020, Lars Asplund lars.anders.asplund@gmail.com
66

7-
from os.path import join, dirname
7+
from pathlib import Path
88
from vunit.verilog import VUnit
99

10-
root = dirname(__file__)
10+
ROOT = Path(__file__).parent
1111

1212
VU = VUnit.from_argv()
1313
LIB = VU.add_library("lib")
14-
LIB.add_source_files(join(root, "*.sv"), defines={"DEFINE_FROM_RUN_PY": ""})
14+
LIB.add_source_files(ROOT / "*.sv", defines={"DEFINE_FROM_RUN_PY": ""})
1515

1616

1717
def configure_tb_with_parameter_config():
@@ -35,7 +35,7 @@ def configure_tb_with_parameter_config():
3535
)
3636

3737
def post_check(output_path):
38-
with open(join(output_path, "post_check.txt"), "r") as fptr:
38+
with (Path(output_path) / "post_check.txt").open("r") as fptr:
3939
return fptr.read() == "Test 4 was here"
4040

4141
tests[4].add_config(
@@ -49,7 +49,7 @@ def post_check(output_path):
4949

5050
def configure_tb_same_sim_all_pass(ui):
5151
def post_check(output_path):
52-
with open(join(output_path, "post_check.txt"), "r") as fptr:
52+
with (Path(output_path) / "post_check.txt").open("r") as fptr:
5353
return fptr.read() == "Test 3 was here"
5454

5555
module = ui.library("lib").module("tb_same_sim_all_pass")
@@ -59,6 +59,6 @@ def post_check(output_path):
5959
configure_tb_with_parameter_config()
6060
configure_tb_same_sim_all_pass(VU)
6161
LIB.module("tb_other_file_tests").scan_tests_from_file(
62-
join(root, "other_file_tests.sv")
62+
str(ROOT / "other_file_tests.sv")
6363
)
6464
VU.main()

tests/acceptance/artificial/vhdl/run.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
#
55
# Copyright (c) 2014-2020, Lars Asplund lars.anders.asplund@gmail.com
66

7-
from os.path import join, dirname
7+
from pathlib import Path
88
from vunit import VUnit
99

10-
root = dirname(__file__)
10+
ROOT = Path(__file__).parent
1111

1212
VU = VUnit.from_argv()
1313
LIB = VU.add_library("lib")
14-
LIB.add_source_files(join(root, "*.vhd"))
14+
LIB.add_source_files(ROOT / "*.vhd")
1515

1616

1717
def configure_tb_with_generic_config():
@@ -33,7 +33,7 @@ def configure_tb_with_generic_config():
3333
)
3434

3535
def post_check(output_path):
36-
with open(join(output_path, "post_check.txt"), "r") as fptr:
36+
with (Path(output_path) / "post_check.txt").open("r") as fptr:
3737
return "Test 4 was here" in fptr.read()
3838

3939
tests[4].add_config(
@@ -45,7 +45,7 @@ def post_check(output_path):
4545

4646
def configure_tb_same_sim_all_pass(ui):
4747
def post_check(output_path):
48-
with open(join(output_path, "post_check.txt"), "r") as fptr:
48+
with (Path(output_path) / "post_check.txt").open("r") as fptr:
4949
return "Test 3 was here" in fptr.read()
5050

5151
ent = ui.library("lib").entity("tb_same_sim_all_pass")
@@ -93,6 +93,6 @@ def configure_tb_assert_stop_level(ui):
9393
LIB.entity("tb_no_generic_override").set_generic("g_val", False)
9494
LIB.entity("tb_ieee_warning").test("pass").set_sim_option("disable_ieee_warnings", True)
9595
LIB.entity("tb_other_file_tests").scan_tests_from_file(
96-
join(root, "other_file_tests.vhd")
96+
str(ROOT / "other_file_tests.vhd")
9797
)
9898
VU.main()

tests/acceptance/test_artificial.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@
99
"""
1010

1111
import unittest
12-
from os.path import join, dirname
12+
from pathlib import Path
1313
from os import environ
1414
from subprocess import call
1515
import sys
1616
from tests.common import check_report
1717
from vunit.sim_if.common import has_simulator, simulator_is
1818

19+
ROOT = Path(__file__).parent
20+
1921

2022
@unittest.skipUnless(has_simulator(), "Requires simulator")
2123
class TestVunitArtificial(unittest.TestCase):
@@ -26,18 +28,14 @@ class TestVunitArtificial(unittest.TestCase):
2628

2729
def setUp(self):
2830
if simulator_is("activehdl"):
29-
self.output_path = join(dirname(__file__), "artificial_out")
31+
self.output_path = str(ROOT / "artificial_out")
3032
else:
3133
# Spaces in path intentional to verify that it is supported
32-
self.output_path = join(dirname(__file__), "artificial _out")
34+
self.output_path = str(ROOT / "artificial _out")
3335

34-
self.report_file = join(self.output_path, "xunit.xml")
35-
self.artificial_run_vhdl = join(
36-
dirname(__file__), "artificial", "vhdl", "run.py"
37-
)
38-
self.artificial_run_verilog = join(
39-
dirname(__file__), "artificial", "verilog", "run.py"
40-
)
36+
self.report_file = str(Path(self.output_path) / "xunit.xml")
37+
self.artificial_run_vhdl = str(ROOT / "artificial" / "vhdl" / "run.py")
38+
self.artificial_run_verilog = str(ROOT / "artificial" / "verilog" / "run.py")
4139

4240
@unittest.skipUnless(
4341
simulator_is("modelsim", "rivierapro"),

tests/acceptance/test_dependencies.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,20 @@
1111

1212

1313
import unittest
14-
from os.path import join, dirname
14+
from pathlib import Path
1515
from vunit import VUnit
1616

17+
ROOT = Path(__file__).parent
18+
1719

1820
class TestDependencies(unittest.TestCase):
1921
"""
2022
Test to expose simulator dependency requirements
2123
"""
2224

2325
def setUp(self):
24-
self.data_path = join(dirname(__file__), "dependencies")
25-
self.output_path = join(dirname(__file__), "dependencies_vunit_out")
26+
self.data_path = str(ROOT / "dependencies")
27+
self.output_path = str(ROOT / "dependencies_vunit_out")
2628

2729
def test_package_body_dependencies(self):
2830
"""
@@ -36,9 +38,11 @@ def run(value):
3638
Utility function to first run with pkg_body1 then pkg_body2
3739
"""
3840

39-
tb_pkg_file_name = join(self.data_path, "tb_pkg.vhd")
40-
pkg_file_name = join(self.data_path, "pkg.vhd")
41-
pkg_body_file_name = join(self.data_path, "pkg_body%i.vhd" % value)
41+
dpath = Path(self.data_path)
42+
43+
tb_pkg_file_name = str(dpath / "tb_pkg.vhd")
44+
pkg_file_name = str(dpath / "pkg.vhd")
45+
pkg_body_file_name = str(dpath / ("pkg_body%i.vhd" % value))
4246

4347
argv = ["--output-path=%s" % self.output_path, "-v"]
4448
if value == 1:

0 commit comments

Comments
 (0)