Skip to content

Commit

Permalink
More options.
Browse files Browse the repository at this point in the history
  • Loading branch information
Paebbels committed Feb 5, 2023
1 parent 76b3f23 commit 3245bd1
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 22 deletions.
93 changes: 78 additions & 15 deletions VHDLDomain/Directive.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ class ParameterStyle(Flag):
Sections = auto()


@export
class ArchitecturesStyle(Flag):
Never = auto()
Multiple = auto()
Always = auto()


@export
def strip(option: str):
return option.strip().lower()
Expand Down Expand Up @@ -179,7 +186,11 @@ class DescribeContext(BaseDirective):

has_content = False
required_arguments = 0
optional_arguments = 0
optional_arguments = 1

option_spec = {
"referencedby": strip,
}

def run(self) -> List[Node]:
from VHDLDomain import Design
Expand All @@ -200,12 +211,14 @@ class DescribeEntity(BaseDirective):
"""

has_content = True
required_arguments = 1
optional_arguments = 2
required_arguments = 0
optional_arguments = 4

option_spec = {
"genericlist": strip,
"portlist": strip,
"genericlist": strip,
"portlist": strip,
"architectures": strip,
"referencedby": strip,
}

def _PrepareTable(self, columns: Dict[str, int], classes: List[str]) -> Tuple[table, tgroup]:
Expand Down Expand Up @@ -389,21 +402,57 @@ def CreateInnerHierarchySection(self, entity: Entity) -> section:

return section

def ParseParameterOption(self, optionName: str) -> ParameterStyle:
def ParseParameterStyleOption(self, optionName: str) -> ParameterStyle:
try:
option = self.options[optionName]
except KeyError:
try:
option = self.defaultValues[optionName]
except KeyError:
option = "table"
return ParameterStyle.Table

if option == "never":
return ParameterStyle.Never
elif option == "table":
return ParameterStyle.Table
elif option == "sections":
return ParameterStyle.Sections
else:
raise ValueError(f"value '{option}' is not in list of choices: never, table, sections.")

def ParseArchitecturesStyleOption(self, optionName: str) -> ArchitecturesStyle:
try:
option = self.options[optionName]
except KeyError:
try:
option = self.defaultValues[optionName]
except KeyError:
return ArchitecturesStyle.Multiple

if option == "never":
return ArchitecturesStyle.Never
elif option == "multiple":
return ArchitecturesStyle.Multiple
elif option == "always":
return ArchitecturesStyle.Always
else:
raise ValueError(f"value '{option}' is not in list of choices: never, multiple, always.")

def ParseBooleanOption(self, optionName: str, default: bool) -> bool:
try:
option = self.options[optionName]
except KeyError:
try:
option = self.defaultValues[optionName]
except KeyError:
return default

if option in ("yes", "true"):
return True
elif option in ("no", "false"):
return False
else:
raise ValueError(f"Value '{option}' not supported for a boolean value (yes/true, no/false).")

def run(self) -> List[Node]:
from VHDLDomain import Design
Expand All @@ -420,8 +469,12 @@ def run(self) -> List[Node]:
self.directiveName = self.name.split(":")[1]
self.defaultValues = self.env.config.vhdl_defaults[self.directiveName]

optionGenerics = self.ParseParameterOption("genericlist")
optionPorts = self.ParseParameterOption("portlist")
optionDefinition = self.ParseBooleanOption("definition", True)
optionGenerics = self.ParseParameterStyleOption("genericlist")
optionPorts = self.ParseParameterStyleOption("portlist")
optionArchitectures = self.ParseArchitecturesStyleOption("architectures")
optionReferencedBy = self.ParseBooleanOption("referencedby", True)
optionHierarchy = self.ParseBooleanOption("hierarchy", True)

vhdlDomain: Domain = self.env.domains["vhdl"]
designs: Dict[str, Design] = vhdlDomain.data["designs"]
Expand All @@ -434,21 +487,22 @@ def run(self) -> List[Node]:
nodes.paragraph(text=entity.Documentation)
]

if True:
if optionDefinition:
content.append(self.CreateDefinitionSection(entity))

if optionGenerics is not ParameterStyle.Never:
content.append(self.CreateGenericSection(entity, optionGenerics))
if optionPorts is not ParameterStyle.Never:
content.append(self.CreatePortSection(entity, optionPorts))

if True:
if (optionArchitectures is ArchitecturesStyle.Always or
(optionArchitectures is ArchitecturesStyle.Multiple and len(entity.Architectures) > 1)):
content.append(self.CreateArchitectureSection(entity))

if True:
if optionReferencedBy:
content.append(self.CreateReferencedBySection(entity))

if True:
if optionHierarchy:
content.append(self.CreateInnerHierarchySection(entity))

entitySection = nodes.section(
Expand Down Expand Up @@ -490,7 +544,12 @@ class DescribePackage(BaseDirective):

has_content = False
required_arguments = 0
optional_arguments = 0
optional_arguments = 2

option_spec = {
"genericlist": strip,
"referencedby": strip,
}

def run(self) -> List[Node]:
from VHDLDomain import Design
Expand Down Expand Up @@ -534,7 +593,11 @@ class DescribeConfiguration(BaseDirective):

has_content = False
required_arguments = 0
optional_arguments = 0
optional_arguments = 1

option_spec = {
"referencedby": strip,
}

def run(self) -> List[Node]:
from VHDLDomain import Design
Expand Down
4 changes: 2 additions & 2 deletions doc/Dependency.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ VHDLDomain Package
+--------------------------------------------------------+-------------+------------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------+
| **Package** | **Version** | **License** | **Dependencies** |
+========================================================+=============+==========================================================================================+=================================================================================================================================+
| `pyTooling <https://GitHub.com/pyTooling/pyTooling>`__ | ≥2.11.0 | `Apache License, 2.0 <https://GitHub.com/pyTooling/pyTooling/blob/master/LICENSE.txt>`__ | *None* |
| `pyTooling <https://GitHub.com/pyTooling/pyTooling>`__ | ≥2.12.0 | `Apache License, 2.0 <https://GitHub.com/pyTooling/pyTooling/blob/master/LICENSE.txt>`__ | *None* |
+--------------------------------------------------------+-------------+------------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------+
| `Sphinx <https://GitHub.com/sphinx-doc/sphinx>`__ | ≥5.3.0 | `BSD-2-Clause <https://GitHub.com/sphinx-doc/sphinx/blob/master/LICENSE>`__ |br| | * ❓`sphinxcontrib-applehelp <>`__ |
| | | | * ❓`sphinxcontrib-devhelp <>`__ |
Expand Down Expand Up @@ -146,7 +146,7 @@ install the mandatory dependencies too.
+----------------------------------------------------------------------------+--------------+----------------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------+
| **Package** | **Version** | **License** | **Dependencies** |
+============================================================================+==============+==========================================================================================================+======================================================================================================================================================+
| `pyTooling <https://GitHub.com/pyTooling/pyTooling>`__ | ≥2.11.0 | `Apache License, 2.0 <https://GitHub.com/pyTooling/pyTooling/blob/main/LICENSE.md>`__ | *None* |
| `pyTooling <https://GitHub.com/pyTooling/pyTooling>`__ | ≥2.12.0 | `Apache License, 2.0 <https://GitHub.com/pyTooling/pyTooling/blob/main/LICENSE.md>`__ | *None* |
+----------------------------------------------------------------------------+--------------+----------------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------+
| `wheel <https://GitHub.com/pypa/wheel>`__ | ≥0.38.1 | `MIT <https://github.com/pypa/wheel/blob/main/LICENSE.txt>`__ | *Not yet evaluated.* |
+----------------------------------------------------------------------------+--------------+----------------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------+
Expand Down
21 changes: 19 additions & 2 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,13 +291,30 @@
"StopWatch": (Path.cwd() / "../examples/StopWatch").resolve(),
}
vhdl_defaults = {
"describedesign": {},
"describelibrary": {},
"describedocument": {},
"describecontext": {
"referencedby": "yes", # no, yes
},
"describeentity": {
"generics": "table", # never, table, sections
"ports": "table", # never, table, sections
"parameters": "table", # never, table, sections
"architectures": "multiple", # never, multiple, always
"referencedby": "yes", # no, yes
}
},
"describearchitecture": {},
"describepackage": {
"generics": "table", # never, table, sections
"referencedby": "yes", # no, yes
},
"describepackagebody": {},
"describeconfiguration": {
"referencedby": "yes", # no, yes
},
"describesubprogram": {
"parameters": "table", # never, table, sections
},
}

# for directory in [mod for mod in Path("../VHDLDomain").iterdir() if mod.is_dir() and mod.name != "__pycache__"]:
Expand Down
2 changes: 1 addition & 1 deletion doc/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-r ../requirements.txt

pyTooling>=2.11.0
pyTooling>=2.12.0

# Enforce latest version on ReadTheDocs
sphinx>=5.3.0, <6.0
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[build-system]
requires = [
"pyTooling >= 2.11.0",
"pyTooling >= 2.12.0",
"setuptools >= 62.3.3",
"wheel >= 0.38.1"
]
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pyTooling>=2.11.0
pyTooling>=2.12.0
pyGHDL

0 comments on commit 3245bd1

Please sign in to comment.