Skip to content

Commit

Permalink
refactor: Modify the graphql exporter.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdacoello committed Nov 25, 2024
1 parent 2f1a984 commit ab93531
Show file tree
Hide file tree
Showing 10 changed files with 1,115 additions and 268 deletions.
386 changes: 337 additions & 49 deletions docs/graphql.md

Large diffs are not rendered by default.

51 changes: 50 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ importlib-metadata = "^7.0"
click = "^8.1.7"
rich-click = "^1.8.3"
pydantic = "^2.8.2"
graphene = "^3.4.1"
pandas = "^2.2.3"

[tool.poetry.group.dev.dependencies]
mypy = "*"
Expand Down
11 changes: 8 additions & 3 deletions src/vss_tools/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,20 @@
# https://www.mozilla.org/en-US/MPL/2.0/
#
# SPDX-License-Identifier: MPL-2.0
from typing import Any, Callable, Set
from __future__ import annotations

from typing import TYPE_CHECKING, Any, Callable, Set

from vss_tools import log

if TYPE_CHECKING:
from vss_tools.model import VSSUnit

# Global objects to be extended by other code parts
dynamic_datatypes: Set[str] = set()
dynamic_quantities: list[str] = []
# This one contains the unit name as well as the list of allowed-datatypes
dynamic_units: dict[str, list] = {}
# Map of unit name and VSSUnit
dynamic_units: dict[str, VSSUnit] = {}


class DatatypesException(Exception):
Expand Down
53 changes: 1 addition & 52 deletions src/vss_tools/exporters/go.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import vss_tools.cli_options as clo
from vss_tools import log
from vss_tools.datatypes import Datatypes, is_array
from vss_tools.exporters.utils import get_instance_mapping
from vss_tools.main import get_trees
from vss_tools.model import VSSDataBranch, VSSDataDatatype, VSSDataStruct
from vss_tools.tree import VSSNode
Expand All @@ -43,58 +44,6 @@
}


class NoInstanceRootException(Exception):
pass


def get_instance_root(root: VSSNode, depth: int = 1) -> tuple[VSSNode, int]:
"""
Getting the root node of a given instance node.
Going the tree upwards
"""
if root.parent is None:
raise NoInstanceRootException()
if isinstance(root.parent.data, VSSDataBranch):
if root.parent.data.is_instance:
return get_instance_root(root.parent, depth + 1)
else:
return root.parent, depth
else:
raise NoInstanceRootException()


def add_children_map_entries(root: VSSNode, fqn: str, replace: str, map: dict[str, str]) -> None:
"""
Adding rename map entries for children of a given node
"""
child: VSSNode
for child in root.children:
child_fqn = child.get_fqn()
new_name = child_fqn.replace(fqn, replace)
map[child_fqn] = new_name
add_children_map_entries(child, fqn, replace, map)


def get_instance_mapping(root: VSSNode | None) -> dict[str, str]:
"""
Constructing a rename map of fqn->new_name.
The new name has instances stripped and appending "I<N>" instead
where N is the depth of the instance
"""
if root is None:
return {}
instance_map: dict[str, str] = {}
for node in PreOrderIter(root):
if isinstance(node.data, VSSDataBranch):
if node.data.is_instance:
instance_root, depth = get_instance_root(node)
new_name = instance_root.get_fqn() + "." + "I" + str(depth)
fqn = node.get_fqn()
instance_map[fqn] = new_name
add_children_map_entries(node, fqn, instance_root.get_fqn(), instance_map)
return instance_map


def get_datatype(node: VSSNode) -> str | None:
"""
Gets the datatype string of a node.
Expand Down
Loading

0 comments on commit ab93531

Please sign in to comment.