Skip to content

Commit

Permalink
Add set_script_filename method. (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
bbassett-tibco committed May 24, 2024
1 parent 2355324 commit c1564b4
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion spotfire/data_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ def __init__(self, analytic_type: str, inputs: typing.List[AnalyticInput], outpu
self.outputs = outputs if isinstance(outputs, list) else []
self.script = script
self.debug_enabled = False
self.script_filename = '<data_function>'
self.globals = {'__builtins__': __builtins__}
self.log = io.StringIO()
self.compiled_script = None
Expand All @@ -262,6 +263,13 @@ def enable_debug(self) -> None:
"""Turn on the printing of debugging messages."""
self.debug_enabled = True

def set_script_filename(self, filename: str) -> None:
"""Set the filename of the script when this spec object is used for script debugging.
:param filename: the filename of the script
"""
self.script_filename = filename

def debug(self, message: str) -> None:
"""Output a debugging message to the log if debug is enabled.
Expand Down Expand Up @@ -328,7 +336,7 @@ def _compile_script(self, result: AnalyticResult) -> None:
""""Parse and compile the script"""
# noinspection PyBroadException
try:
self.compiled_script = compile(self.script, '<data_function>', 'exec')
self.compiled_script = compile(self.script, self.script_filename, 'exec')
except BaseException:
self.debug("script can't be parsed:")
self.debug("--- script ---")
Expand Down

0 comments on commit c1564b4

Please sign in to comment.