1515)
1616
1717from polyaxon ._flow import ParamSpec
18- from polyaxon ._polyaxonfile .specs .libs .engine import get_engine
18+ from polyaxon ._polyaxonfile .specs .libs .engine import render_template
1919from polyaxon ._polyaxonfile .specs .sections import Sections
20- from polyaxon .exceptions import PolyaxonSchemaError
2120
2221try :
2322 import numpy as np
2827class PolyaxonfileParser :
2928 """Parses the Polyaxonfile."""
3029
31- engine = get_engine ()
32-
3330 @staticmethod
3431 def _get_section_data (section_data ):
3532 if hasattr (section_data , "to_dict" ):
@@ -193,19 +190,6 @@ def parse_io(
193190 @classmethod
194191 def parse_expression ( # pylint:disable=too-many-branches
195192 cls , expression , params : Dict , check_operators : bool = False
196- ):
197- try :
198- return cls ._parse_expression (expression , params , check_operators )
199- except jinja2 .exceptions .TemplateError as e :
200- raise PolyaxonSchemaError (
201- "Encountered a problem parsing the template, "
202- "please make sure your variables are resolvable. "
203- "Error: {}" .format (repr (e ))
204- )
205-
206- @classmethod
207- def _parse_expression ( # pylint:disable=too-many-branches
208- cls , expression , params : Dict , check_operators : bool = False
209193 ):
210194 if isinstance (expression , (int , float , complex , type (None ))):
211195 return expression
@@ -227,7 +211,7 @@ def _parse_expression( # pylint:disable=too-many-branches
227211 if len (expression ) == 1 :
228212 old_key , value = list (expression .items ())[0 ]
229213 # always parse the keys, they must be base object or evaluate to base objects
230- key = cls ._parse_expression (old_key , params )
214+ key = cls .parse_expression (old_key , params )
231215 if check_operators and cls .is_operator (key ):
232216 return cls ._parse_operator ({key : value }, params )
233217 else :
@@ -236,7 +220,7 @@ def _parse_expression( # pylint:disable=too-many-branches
236220 new_expression = {}
237221 for k , v in expression .items ():
238222 new_expression .update (
239- cls ._parse_expression ({k : v }, params , check_operators )
223+ cls .parse_expression ({k : v }, params , check_operators )
240224 )
241225 return new_expression
242226
@@ -253,14 +237,7 @@ def _parse_expression( # pylint:disable=too-many-branches
253237
254238 @classmethod
255239 def _evaluate_expression (cls , expression , params , check_operators ):
256- try :
257- result = cls .engine .from_string (expression ).render (** params )
258- except (ValueError , TypeError ) as e :
259- raise PolyaxonSchemaError (
260- "Encountered a problem parsing the template, "
261- "please make sure your variables are resolvable. "
262- "Error: {}" .format (repr (e ))
263- )
240+ result = render_template (expression , params )
264241 if result == expression :
265242 try :
266243 return ast .literal_eval (result )
0 commit comments