Skip to content

Commit 7b81938

Browse files
anton schulteAnton Schulte
authored andcommitted
all checked for UI
1 parent 7d7ae16 commit 7b81938

17 files changed

Lines changed: 525 additions & 450 deletions

mypy.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[mypy]
2+
[mypy-vunit.ui.*]
3+
disallow_untyped_defs = True

vunit/configuration.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import inspect
1313
from pathlib import Path
1414
from copy import copy
15+
from typing import Any, Callable, OrderedDict, Union
1516
from vunit.sim_if.factory import SIMULATOR_FACTORY
1617

1718

@@ -111,7 +112,7 @@ def set_vhdl_configuration_name(self, name):
111112
"""
112113
self.vhdl_configuration_name = name
113114

114-
def set_generic(self, name, value):
115+
def set_generic(self, name: str, value: Any) -> None:
115116
"""
116117
Set generic
117118
"""
@@ -128,7 +129,7 @@ def set_generic(self, name, value):
128129
else:
129130
self.generics[name] = value
130131

131-
def set_sim_option(self, name, value):
132+
def set_sim_option(self, name: str, value: Union[str, list[str], bool]):
132133
"""
133134
Set sim option
134135
"""
@@ -195,11 +196,10 @@ class ConfigurationVisitor(object):
195196
def _check_enabled(self):
196197
pass
197198

198-
@staticmethod
199-
def get_configuration_dicts():
199+
def get_configuration_dicts(self) -> list[OrderedDict[Any, Configuration]]:
200200
raise NotImplementedError
201201

202-
def set_attribute(self, name, value):
202+
def set_attribute(self, name: str, value: Any):
203203
"""
204204
Set attribute
205205
"""
@@ -226,7 +226,7 @@ def set_vhdl_configuration_name(self, value: str):
226226
for config in configs.values():
227227
config.set_vhdl_configuration_name(value)
228228

229-
def set_sim_option(self, name, value, overwrite=True):
229+
def set_sim_option(self, name: str, value: Union[str, list[str], bool], overwrite=True) -> None:
230230
"""
231231
Set sim option
232232
@@ -240,7 +240,7 @@ def set_sim_option(self, name, value, overwrite=True):
240240
continue
241241
config.set_sim_option(name, value)
242242

243-
def set_pre_config(self, value):
243+
def set_pre_config(self, value: Callable) -> None:
244244
"""
245245
Set pre_config function
246246
"""

vunit/library.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
"""
1212

1313
import logging
14+
from typing import cast
15+
from vunit.design_unit import Entity, VHDLDesignUnit
16+
from vunit.source_file import SourceFile, VHDLSourceFile, VerilogSourceFile
1417
from vunit.vhdl_standard import VHDLStandard
1518

1619
LOGGER = logging.getLogger(__name__)
@@ -46,7 +49,7 @@ def __init__(self, name: str, directory: str, vhdl_standard: VHDLStandard, is_ex
4649

4750
self._is_external = is_external
4851

49-
def add_source_file(self, source_file):
52+
def add_source_file(self, source_file: SourceFile) -> SourceFile:
5053
"""
5154
Add source file to library unless it exists
5255
@@ -104,7 +107,7 @@ def _check_duplication(self, dictionary, design_unit):
104107
if design_unit.name in dictionary:
105108
self._warning_on_duplication(design_unit, dictionary[design_unit.name].source_file.name)
106109

107-
def add_vhdl_design_units(self, design_units):
110+
def add_vhdl_design_units(self, design_units: list[VHDLDesignUnit]):
108111
"""
109112
Add VHDL design units to the library
110113
"""
@@ -119,7 +122,7 @@ def add_vhdl_design_units(self, design_units):
119122
self._entities[design_unit.name] = design_unit
120123

121124
for architecture in self._architectures[design_unit.name].values():
122-
design_unit.add_architecture(architecture)
125+
cast(Entity, design_unit).add_architecture(architecture)
123126

124127
else:
125128
if design_unit.unit_type == "architecture":

vunit/project.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ def __init__(self, depend_on_package_body=False, database=None):
4545
self._database = database
4646
self._vhdl_parser = VHDLParser(database=self._database)
4747
self._verilog_parser = VerilogParser(database=self._database)
48-
self._libraries = OrderedDict()
48+
self._libraries: OrderedDict[str, Library] = OrderedDict()
4949
# Mapping between library lower case name and real library name
5050
self._lower_library_names_dict = {}
51-
self._source_files_in_order = []
51+
self._source_files_in_order: list[SourceFile] = []
5252
self._manual_dependencies = []
5353
self._depend_on_package_body = depend_on_package_body
5454
self._builtin_libraries = set(["ieee", "std"])
5555

56-
def _validate_new_library_name(self, library_name):
56+
def _validate_new_library_name(self, library_name: str) -> None:
5757
"""
5858
Check that the library_name is valid or raise RuntimeError
5959
"""
@@ -74,15 +74,15 @@ def _validate_new_library_name(self, library_name):
7474
f"Library name {self._lower_library_names_dict[lower_name]!r} previously defined"
7575
)
7676

77-
def add_builtin_library(self, logical_name):
77+
def add_builtin_library(self, logical_name: str) -> None:
7878
"""
7979
Add a builtin library name that does not give missing dependency warnings
8080
"""
8181
self._builtin_libraries.add(logical_name)
8282

8383
def add_library(
8484
self,
85-
logical_name,
85+
logical_name: str,
8686
directory: Union[str, Path],
8787
vhdl_standard: VHDLStandard = VHDL.STD_2008,
8888
is_external=False,
@@ -118,7 +118,7 @@ def add_source_file( # pylint: disable=too-many-arguments
118118
defines=None,
119119
vhdl_standard: Optional[VHDLStandard] = None,
120120
no_parse=False,
121-
):
121+
) -> SourceFile:
122122
"""
123123
Add a file_name as a source file in library_name with file_type
124124
@@ -515,7 +515,7 @@ def _get_files_to_recompile(self, files, dependency_graph, incremental):
515515
result_list.append(source_file)
516516
return result_list
517517

518-
def get_dependencies_in_compile_order(self, target_files=None, implementation_dependencies=False):
518+
def get_dependencies_in_compile_order(self, target_files=None, implementation_dependencies=False) -> list[SourceFile]:
519519
"""
520520
Get a list of dependencies of target files including the
521521
target files.
@@ -591,7 +591,7 @@ def comparison_key(source_file):
591591

592592
return sorted(files, key=comparison_key)
593593

594-
def get_source_files_in_order(self):
594+
def get_source_files_in_order(self) -> list[SourceFile]:
595595
"""
596596
Get a list of source files in the order they were added to the project
597597
"""

vunit/sim_if/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@
1313
from os import environ, listdir, pathsep
1414
import subprocess
1515
from pathlib import Path
16-
from typing import List
16+
from typing import Any, List, Union
1717
from ..ostools import Process, simplify_path
1818
from ..exceptions import CompileError
1919
from ..color_printer import NO_COLOR_PRINTER
2020

21+
OptionType = Union[str, list[str], bool]
22+
2123

2224
class Option(object):
2325
"""
@@ -416,7 +418,7 @@ def validate(self, value):
416418
raise ValueError(f"Option {self.name!r} must be one of {self._legal_values!s}. Got {value!r}")
417419

418420

419-
def is_string_not_iterable(value):
421+
def is_string_not_iterable(value: Any) -> bool:
420422
"""
421423
Returns True if value is a string and not another iterable
422424
"""

vunit/sim_if/factory.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@
99
"""
1010

1111
import os
12+
from typing import Union
1213
from .activehdl import ActiveHDLInterface
1314
from .ghdl import GHDLInterface
1415
from .incisive import IncisiveInterface
1516
from .modelsim import ModelSimInterface
1617
from .nvc import NVCInterface
1718
from .rivierapro import RivieraProInterface
18-
from . import BooleanOption, ListOfStringOption, VHDLAssertLevelOption
19+
from . import BooleanOption, ListOfStringOption, Option, VHDLAssertLevelOption
1920

2021

2122
class SimulatorFactory(object):
@@ -37,7 +38,7 @@ def supported_simulators():
3738
NVCInterface,
3839
]
3940

40-
def _extract_compile_options(self):
41+
def _extract_compile_options(self) -> dict[str, Option]:
4142
"""
4243
Return all supported compile options
4344
"""
@@ -51,7 +52,7 @@ def _extract_compile_options(self):
5152
result[opt.name] = opt
5253
return result
5354

54-
def _extract_sim_options(self):
55+
def _extract_sim_options(self) -> dict[str, Option]:
5556
"""
5657
Return all supported sim options
5758
"""
@@ -75,7 +76,7 @@ def _extract_sim_options(self):
7576

7677
return result
7778

78-
def check_sim_option(self, name, value):
79+
def check_sim_option(self, name: str, value: Union[str, list[str], bool]):
7980
"""
8081
Check that sim_option has legal name and value
8182
"""
@@ -94,7 +95,7 @@ def check_compile_option_name(self, name):
9495
if name not in known_options:
9596
raise ValueError(f"Unknown compile_option {name!r}, expected one of {known_options!r}")
9697

97-
def check_compile_option(self, name, value):
98+
def check_compile_option(self, name: str, value: Union[str, list[str], bool]) -> None:
9899
"""
99100
Check that the compile option is valid
100101
"""

vunit/source_file.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
Functionality to represent and operate on VHDL and Verilog source files
99
"""
1010
from pathlib import Path
11-
from typing import Union
11+
from typing import Literal, Union
1212
import logging
1313
from copy import copy
1414
import traceback
15+
from vunit.sim_if import OptionType
1516
from vunit.sim_if.factory import SIMULATOR_FACTORY
1617
from vunit.hashing import hash_string
1718
from vunit.vhdl_parser import VHDLReference
@@ -35,7 +36,7 @@ def __init__(self, name, library, file_type):
3536
self.file_type = file_type
3637
self.design_units = []
3738
self._content_hash = None
38-
self._compile_options = {}
39+
self._compile_options: dict[str, OptionType] = {}
3940

4041
# The file name before preprocessing
4142
self.original_name = name
@@ -70,14 +71,14 @@ def __hash__(self):
7071
def __repr__(self):
7172
return f"SourceFile({self.name!s}, {self.library.name!s})"
7273

73-
def set_compile_option(self, name, value):
74+
def set_compile_option(self, name: str, value: OptionType):
7475
"""
7576
Set compile option
7677
"""
7778
SIMULATOR_FACTORY.check_compile_option(name, value)
7879
self._compile_options[name] = copy(value)
7980

80-
def add_compile_option(self, name, value):
81+
def add_compile_option(self, name: str, value: OptionType):
8182
"""
8283
Add compile option
8384
"""
@@ -86,7 +87,7 @@ def add_compile_option(self, name, value):
8687
if name not in self._compile_options:
8788
self._compile_options[name] = copy(value)
8889
else:
89-
self._compile_options[name] += value
90+
self._compile_options[name] += value # type: ignore
9091

9192
@property
9293
def compile_options(self):
@@ -118,6 +119,9 @@ def content_hash(self):
118119
"""
119120
return hash_string(self._content_hash + self._compile_options_hash())
120121

122+
def add_to_library(self, library: Library):
123+
raise NotImplemented
124+
121125

122126
class VerilogSourceFile(SourceFile):
123127
"""
@@ -347,7 +351,7 @@ def add_to_library(self, library):
347351
FILE_TYPES = ("vhdl",) + VERILOG_FILE_TYPES
348352

349353

350-
def file_type_of(file_name):
354+
def file_type_of(file_name: Union[str, Path]) -> Literal["vhdl", "verilog", "systemverilog"]:
351355
"""
352356
Return the file type of file_name based on the file ending
353357
"""

vunit/test/bench.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import bisect
1515
import collections
1616
from collections import OrderedDict
17+
from typing import Any, Iterable, Union
1718
from ..ostools import file_exists
1819
from ..cached import cached
1920
from ..vhdl_parser import remove_comments as remove_vhdl_comments
@@ -37,7 +38,7 @@ def __init__(self, design_unit, database=None):
3738
self._database = database
3839

3940
self._individual_tests = False
40-
self._configs = {}
41+
self._configs: OrderedDict[Any, Configuration] = OrderedDict()
4142
self._test_cases = []
4243
self._implicit_test = None
4344

@@ -142,7 +143,7 @@ def get_test_case(self, name):
142143
return test_case
143144
raise KeyError(name)
144145

145-
def get_configuration_dicts(self): # pylint: disable=arguments-differ
146+
def get_configuration_dicts(self) -> list[OrderedDict[str, Configuration]]: # pylint: disable=arguments-differ
146147
"""
147148
Get all configurations within the test bench
148149
@@ -166,7 +167,7 @@ def _get_configurations_to_run(self):
166167
del configs[DEFAULT_NAME]
167168
return configs.values()
168169

169-
def scan_tests_from_file(self, file_name):
170+
def scan_tests_from_file(self, file_name: Union[str, Path]) -> None:
170171
"""
171172
Scan file for test cases and attributes
172173
"""
@@ -337,7 +338,7 @@ def __init__(self, test, design_unit, enable_configuration, default_config):
337338
assert test.is_explicit
338339
self.design_unit = design_unit
339340
self._enable_configuration = enable_configuration
340-
self._configs = OrderedDict({default_config.name: default_config})
341+
self._configs: OrderedDict[Any, Configuration] = OrderedDict({default_config.name: default_config})
341342

342343
@property
343344
def name(self):
@@ -358,13 +359,13 @@ def _check_enabled(self):
358359
if not self._enable_configuration:
359360
raise RuntimeError("Individual test configuration is not possible with run_all_in_same_sim")
360361

361-
def get_configuration_dicts(self): # pylint: disable=arguments-differ
362+
def get_configuration_dicts(self) -> list[OrderedDict[Any, Configuration]]: # pylint: disable=arguments-differ
362363
"""
363364
Get all configurations of this test
364365
"""
365366
return [self._configs]
366367

367-
def _get_configurations_to_run(self):
368+
def _get_configurations_to_run(self) -> Iterable[Configuration]:
368369
"""
369370
Get all simulation runs for this test bench
370371
"""

0 commit comments

Comments
 (0)