Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
nnarayen committed Jan 28, 2025
1 parent e3ea6a2 commit 6ac40eb
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
16 changes: 8 additions & 8 deletions truss-chains/truss_chains/framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,28 +219,28 @@ def _example_chainlet_code() -> str:
# called on erroneous code branches (which will not be triggered if
# `example_chainlet` is free of errors).
try:
from truss_chains import example_chainlet
from truss_chains.reference_code import reference_chainlet
# If `example_chainlet` fails validation and `_example_chainlet_code` is
# called as a result of that, we have a circular import ("partially initialized
# module 'truss_chains.example_chainlet' ...").
except AttributeError:
logging.error("`example_chainlet` is broken.", exc_info=True, stack_info=True)
logging.error("`reference_chainlet` is broken.", exc_info=True, stack_info=True)
return "<EXAMPLE CODE MISSING/BROKEN>"

example_name = example_chainlet.HelloWorld.name
return _get_cls_source(example_chainlet.__file__, example_name)
example_name = reference_chainlet.HelloWorld.name
return _get_cls_source(reference_chainlet.__file__, example_name)


@functools.cache
def _example_model_code() -> str:
try:
from truss_chains import example_model
from truss_chains.reference_code import reference_model
except AttributeError:
logging.error("`example_model` is broken.", exc_info=True, stack_info=True)
logging.error("`reference_model` is broken.", exc_info=True, stack_info=True)
return "<EXAMPLE CODE MISSING/BROKEN>"

example_name = example_model.HelloWorld.name
return _get_cls_source(example_model.__file__, example_name)
example_name = reference_model.HelloWorld.name
return _get_cls_source(reference_model.__file__, example_name)


def _get_cls_source(src_path: str, target_class_name: str) -> str:
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions truss/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -827,12 +827,12 @@ def init_chain(directory: Optional[Path]) -> None:

def _load_example_chainlet_code() -> str:
try:
from truss_chains import example_chainlet
from truss_chains.reference_code import reference_chainlet
# if the example is faulty, a validation error would be raised
except Exception as e:
raise Exception("Failed to load starter code. Please notify support.") from e

source = Path(example_chainlet.__file__).read_text()
source = Path(reference_chainlet.__file__).read_text()
return source


Expand Down

0 comments on commit 6ac40eb

Please sign in to comment.