Skip to content

Commit

Permalink
feat: podio-vis --upstream-edm and some tests (#561)
Browse files Browse the repository at this point in the history
  • Loading branch information
wdconinc authored Mar 11, 2024
1 parent 8243a5d commit 8ce5945
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 4 deletions.
1 change: 1 addition & 0 deletions python/podio/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Python module for the podio EDM toolkit and its utilities"""

from .__version__ import __version__

# Try to load podio, this is equivalent to trying to load libpodio.so and will
Expand Down
2 changes: 1 addition & 1 deletion python/podio_gen/generator_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def _write_file(self, name, content):
if not self.dryrun:
self.generated_files.append(fullname)
if self.formatter_func is not None:
content = self.formatter_func(content, fullname)
content = self.formatter_func(content, fullname) # pylint: disable=not-callable

changed = write_file_if_changed(fullname, content)
self.any_changes = changed or self.any_changes
Expand Down
1 change: 0 additions & 1 deletion python/podio_gen/podio_config_reader.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Datamodel yaml configuration file reading and validation utilities."""


import copy
import re
import yaml
Expand Down
30 changes: 30 additions & 0 deletions tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,36 @@ if(ENABLE_RNTUPLE)
install(PROGRAMS ${CMAKE_CURRENT_LIST_DIR}/podio-ttree-to-rntuple DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()

# Add a very basic test of podio-vis
if(BUILD_TESTING)
# Helper function for easily creating "tests" that simply execute podio-vis
# with different arguments. Not crashing is considered success.
#
# Args:
# name the name of the test
# depends_on the target name of the test that produces the required input file
function(CREATE_VIS_TEST name depends_on)
add_test(NAME ${name} COMMAND ./podio-vis ${ARGN})
PODIO_SET_TEST_ENV(${name})

set_tests_properties(${name} PROPERTIES
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
)
if (depends_on)
set_tests_properties(${name} PROPERTIES
DEPENDS ${depends_on}
)
endif()
endfunction()

CREATE_VIS_TEST(podio-vis-help _dummy_target_
--help)
CREATE_VIS_TEST(podio-vis-datamodel datamodel
--dot ${PROJECT_SOURCE_DIR}/tests/datalayout.yaml)
CREATE_VIS_TEST(podio-vis-datamodel-extension extension_model
--dot --upstream-edm datamodel:${PROJECT_SOURCE_DIR}/tests/datalayout.yaml ${PROJECT_SOURCE_DIR}/tests/datalayout_extension.yaml)
endif()

# Add a very basic tests here to make sure that podio-dump at least runs
if(BUILD_TESTING)
# Helper function for easily creating "tests" that simply execute podio-dump
Expand Down
15 changes: 13 additions & 2 deletions tools/podio-vis
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import sys
import argparse
import yaml
from podio_class_generator import read_upstream_edm
from podio_gen.podio_config_reader import PodioConfigReader

try:
Expand All @@ -16,10 +17,10 @@ except ImportError:
class ModelToGraphviz:
"""Class to transform a data model description into a graphical representation"""

def __init__(self, yamlfile, dot, fmt, filename, graph_conf):
def __init__(self, yamlfile, name, dot, fmt, filename, graph_conf, upstream_edm=None):
self.yamlfile = yamlfile
self.use_dot = dot
self.datamodel = PodioConfigReader.read(yamlfile, "podio")
self.datamodel = PodioConfigReader.read(yamlfile, name, upstream_edm)
self.graph = Digraph(node_attr={"shape": "box"})
self.graph.attr(rankdir="RL", size="8,5")
self.fmt = fmt
Expand Down Expand Up @@ -105,6 +106,7 @@ if __name__ == "__main__":
)

parser.add_argument("description", help="yaml file describing the datamodel")
parser.add_argument("-n", "--name", default="edm4hep", help="datamodel name")
parser.add_argument(
"-d",
"--dot",
Expand All @@ -115,14 +117,23 @@ if __name__ == "__main__":
parser.add_argument("--fmt", default="svg", help="Which format to use for saving the file")
parser.add_argument("--filename", default="gv", help="Which filename to use for the output")
parser.add_argument("--graph-conf", help="Configuration file for defining groups")
parser.add_argument(
"--upstream-edm",
default=None,
type=read_upstream_edm,
help="Make datatypes of this upstream EDM available to the current"
" EDM. Format is '<upstream-name>:<upstream.yaml>'. ",
)

args = parser.parse_args()

vis = ModelToGraphviz(
args.description,
args.name,
args.dot,
fmt=args.fmt,
filename=args.filename,
graph_conf=args.graph_conf,
upstream_edm=args.upstream_edm,
)
vis.make_viz()

0 comments on commit 8ce5945

Please sign in to comment.