Skip to content

Commit

Permalink
Merge pull request #261 from caracal-pipeline/issue260
Browse files Browse the repository at this point in the history
replace '-' and '.' with underscores for python callables
  • Loading branch information
o-smirnov authored Mar 12, 2024
2 parents dd29126 + 07e48a8 commit 16910ae
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions stimela/backends/flavours/python_flavours.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

def form_python_function_call(function: str, cab: Cab, params: Dict[str, Any]):
"""
Helper. Converts a function name and a list of parameters into a string
Helper. Converts a function name and a list of parameters into a string
representation of a Python function call that can be parsed by the interpreter.
Uses the cab schema info and policies to decide which parametets to include.
Expand All @@ -39,15 +39,15 @@ def get_python_interpreter_args(cab: Cab, subst: Dict[str, Any], virtual_env: Op
invoke the interpreter. Invokes a virtual environment as appropriate.
Args:
cab (Cab): cab definition
cab (Cab): cab definition
subst (Dict[str, Any]): substitution namespace
Raises:
CabValidationError: on errors
Returns:
List[str]: [command, arguments, ...] needed to invoke the interpreter
"""
"""
# get virtual env, if specified
if virtual_env:
virtual_env = os.path.expanduser(virtual_env)
Expand Down Expand Up @@ -92,7 +92,7 @@ def get_image_name(self, cab: Cab, backend: 'stimela.backend.StimelaBackendOptio
from stimela.backends import resolve_image_name
return resolve_image_name(backend, cab.image or CONFIG.images['default-python'])

def get_arguments(self, cab: Cab, params: Dict[str, Any], subst: Dict[str, Any],
def get_arguments(self, cab: Cab, params: Dict[str, Any], subst: Dict[str, Any],
virtual_env: Optional[str]=None, check_executable: bool = True):
# substitute command and split into module/function
with substitutions_from(subst, raise_errors=True) as context:
Expand All @@ -109,6 +109,7 @@ def get_arguments(self, cab: Cab, params: Dict[str, Any], subst: Dict[str, Any],

# convert inputs into a JSON string
pass_params = cab.filter_input_params(params)
pass_params = {key.replace("-","_").replace(".","__"): value for key, value in pass_params.items()}
params_string = base64.b64encode(
zlib.compress(json.dumps(pass_params).encode('ascii'), 2)
).decode('ascii')
Expand Down Expand Up @@ -171,7 +172,7 @@ def get_image_name(self, cab: Cab, backend: 'stimela.backend.StimelaBackendOptio
from stimela.backends import resolve_image_name
return resolve_image_name(backend, cab.image or CONFIG.images['default-python'])

def get_arguments(self, cab: Cab, params: Dict[str, Any], subst: Dict[str, Any],
def get_arguments(self, cab: Cab, params: Dict[str, Any], subst: Dict[str, Any],
virtual_env: Optional[str]=None, check_executable: bool = True):
# do substitutions on command, if necessary
if self.subst:
Expand Down Expand Up @@ -207,7 +208,7 @@ def get_arguments(self, cab: Cab, params: Dict[str, Any], subst: Dict[str, Any],
if self.output_vars:
for name in pass_outputs:
var_name = name.replace("-", "_").replace(".", "__")
post_command += f"yield_output(**{{'{name}': {var_name}}})\n"
post_command += f"yield_output(**{{'{name}': {var_name}}})\n"

# form up interpreter invocation
args = get_python_interpreter_args(cab, subst, virtual_env=virtual_env)
Expand Down

0 comments on commit 16910ae

Please sign in to comment.