Skip to content

Commit

Permalink
add more scene types, remove import restriction (#237)
Browse files Browse the repository at this point in the history
  • Loading branch information
viseshrp authored Jan 28, 2025
1 parent 0796dd5 commit 0cd227a
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 95 deletions.
145 changes: 56 additions & 89 deletions src/ansys/dynamicreporting/core/serverless/__init__.py
Original file line number Diff line number Diff line change
@@ -1,96 +1,63 @@
# serverless

# Import ADR directly (does not depend on setup)
# Import ADR directly
from .adr import ADR

# Expose ADR immediately
__all__ = ["ADR"]


# Lazy import mechanism for dependent classes
class _LazyLoader:
"""
Lazy loader for dependent classes to defer imports until accessed.
This enforces ADR.setup() to be called before triggering the imports.
"""

def __init__(self):
self._initialized = False

def _initialize(self):
"""Perform the actual imports when accessed for the first time."""
# Ensure ADR has been set up
ADR.ensure_setup()

# Define the modules to be imported
item_classes = (
"Item",
"HTML",
"Animation",
"Dataset",
"File",
"Image",
"Scene",
"Session",
"String",
"Table",
"Tree",
)
template_classes = (
"Template",
"BasicLayout",
"BoxLayout",
"CarouselLayout",
"DataFilterLayout",
"FooterLayout",
"HeaderLayout",
"ItemsComparisonGenerator",
"IteratorGenerator",
"IteratorLayout",
"PanelLayout",
"PPTXLayout",
"PPTXSlideLayout",
"ReportLinkLayout",
"SliderLayout",
"SQLQueryGenerator",
"StatisticalGenerator",
"TabLayout",
"TableMergeGenerator",
"TableMergeRCFilterGenerator",
"TableMergeValueFilterGenerator",
"TableReduceGenerator",
"TableSortFilterGenerator",
"TagPropertyLayout",
"TOCLayout",
"TreeMergeGenerator",
"UserDefinedLayout",
)

# Dynamically import classes from item and template using importlib
import importlib

item_module = importlib.import_module(".item", package=__package__)
template_module = importlib.import_module(".template", package=__package__)

# Dynamically add these to the module namespace and __all__
for cls_name in item_classes + template_classes:
cls = getattr(item_module, cls_name, None) or getattr(template_module, cls_name, None)
if cls:
globals()[cls_name] = cls
__all__.append(cls_name)

self._initialized = True

def __getattr__(self, name):
if not self._initialized:
self._initialize()
return globals()[name]


# Create a lazy loader instance
_lazy_loader = _LazyLoader()


# Define a custom module-level __getattr__ to defer imports
def __getattr__(name):
return getattr(_lazy_loader, name)
_item_classes = [
"Session",
"Dataset",
"Item",
"String",
"HTML",
"Table",
"Tree",
"Image",
"Animation",
"Scene",
"File",
]
_template_classes = [
"Template",
"BasicLayout",
"PanelLayout",
"BoxLayout",
"TabLayout",
"CarouselLayout",
"SliderLayout",
"FooterLayout",
"HeaderLayout",
"IteratorLayout",
"TagPropertyLayout",
"TOCLayout",
"ReportLinkLayout",
"PPTXLayout",
"PPTXSlideLayout",
"DataFilterLayout",
"UserDefinedLayout",
"TableMergeGenerator",
"TableReduceGenerator",
"TableMergeRCFilterGenerator",
"TableMergeValueFilterGenerator",
"TableSortFilterGenerator",
"TreeMergeGenerator",
"SQLQueryGenerator",
"ItemsComparisonGenerator",
"StatisticalGenerator",
"IteratorGenerator",
]

# Dynamically import classes from item and template using importlib
import importlib

item_module = importlib.import_module(".item", package=__package__)
template_module = importlib.import_module(".template", package=__package__)

# Dynamically add these to the module namespace and __all__
for cls_name in _item_classes + _template_classes:
cls = getattr(item_module, cls_name, None) or getattr(template_module, cls_name, None)
if cls:
globals()[cls_name] = cls
__all__.append(cls_name)
2 changes: 1 addition & 1 deletion src/ansys/dynamicreporting/core/serverless/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class AnimContent(FileValidator):


class SceneContent(FileValidator):
ALLOWED_EXT = ("stl", "ply", "csf", "avz", "scdoc", "scdocx", "glb")
ALLOWED_EXT = ("stl", "ply", "csf", "avz", "scdoc", "scdocx", "dsco", "glb", "obj")


class FileContent(FileValidator):
Expand Down
20 changes: 15 additions & 5 deletions tests/smoketest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,36 @@
from ansys.dynamicreporting.core import Item, Report, Service, __version__

# ADR serverless core
from ansys.dynamicreporting.core.serverless import ADR
from ansys.dynamicreporting.core.serverless.item import HTML, Animation, Dataset, File, Image
from ansys.dynamicreporting.core.serverless.item import Item as ServerlessItem
from ansys.dynamicreporting.core.serverless.item import Scene, Session, String, Table, Tree
from ansys.dynamicreporting.core.serverless.template import (
from ansys.dynamicreporting.core.serverless import (
ADR,
HTML,
Animation,
BasicLayout,
BoxLayout,
CarouselLayout,
DataFilterLayout,
Dataset,
File,
FooterLayout,
HeaderLayout,
Image,
)
from ansys.dynamicreporting.core.serverless import (
ItemsComparisonGenerator,
IteratorGenerator,
IteratorLayout,
PanelLayout,
PPTXLayout,
PPTXSlideLayout,
ReportLinkLayout,
Scene,
Session,
SliderLayout,
SQLQueryGenerator,
StatisticalGenerator,
String,
TabLayout,
Table,
TableMergeGenerator,
TableMergeRCFilterGenerator,
TableMergeValueFilterGenerator,
Expand All @@ -33,8 +41,10 @@
TagPropertyLayout,
Template,
TOCLayout,
Tree,
TreeMergeGenerator,
UserDefinedLayout,
)
from ansys.dynamicreporting.core.serverless import Item as ServerlessItem

print(__version__)

0 comments on commit 0cd227a

Please sign in to comment.