Skip to content

Commit

Permalink
Support EmPy version 4
Browse files Browse the repository at this point in the history
  • Loading branch information
hjoliver committed Jul 19, 2024
1 parent 52d523d commit 811a048
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion conda-environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ dependencies:
- tomli >=2 # [py<3.11]

# optional dependencies
#- empy >=3.3,<3.4
#- empy >=4.1
#- pandas >=1.0,<2
#- pympler
#- matplotlib-base
Expand Down
19 changes: 17 additions & 2 deletions cylc/flow/parsec/empysupport.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import em
import os
import typing as t
import inspect

from cylc.flow.parsec.exceptions import EmPyError
from cylc.flow.parsec.fileparse import get_cylc_env_vars
Expand Down Expand Up @@ -52,15 +53,29 @@ def empyprocess(
os.chdir(dir_)
ftempl = StringIO('\n'.join(flines))
xtempl = StringIO()
interpreter = em.Interpreter(output=em.UncloseableFile(xtempl))
# Detect EmPy version by interpreter.file() args.
# TODO: Use importlib.metadata version() once we drop Python 3.7
if 'name' in inspect.signature(em.Interpreter.file).parameters:
# Empy 3
interpreter = em.Interpreter(
output=em.UncloseableFile(xtempl)
)
else:
# Empy 4
# dispatcher = False: raise errors to caller
interpreter = em.Interpreter(
output=em.UncloseableFile(xtempl),
dispatcher=False
)

# Add `CYLC_` environment variables to the global namespace.
interpreter.updateGlobals(
get_cylc_env_vars()
)

try:
interpreter.file(ftempl, '<template>', template_vars)
# These args work for EmPy versions 3 and 4.
interpreter.file(ftempl, locals=template_vars)
except Exception as exc:
lineno = interpreter.contexts[-1].identify()[1]
raise EmPyError(
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ include = cylc*

[options.extras_require]
empy =
EmPy==3.3.*
EmPy>=4.1
graph =
pillow
main_loop-log_data_store =
Expand Down

0 comments on commit 811a048

Please sign in to comment.