Skip to content

Commit

Permalink
Implement bash translator
Browse files Browse the repository at this point in the history
  • Loading branch information
kdm9 committed Jul 3, 2022
1 parent 98013f0 commit 66a3c5c
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions papermill/translators.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging
import math
import re
import shlex
import sys

from .exceptions import PapermillException
Expand Down Expand Up @@ -541,6 +542,33 @@ def assign(cls, name, str_val):
return '${} = {}'.format(name, str_val)


class BashTranslator(Translator):
@classmethod
def translate_none(cls, val):
return ''

@classmethod
def translate_bool(cls, val):
return 'true' if val else 'false'

@classmethod
def translate_escaped_str(cls, str_val):
return shlex.quote(str(str_val))

@classmethod
def translate_list(cls, val):
escaped = ' '.join([cls.translate(v) for v in val])
return '({})'.format(escaped)

@classmethod
def comment(cls, cmt_str):
return '# {}'.format(cmt_str).strip()

@classmethod
def assign(cls, name, str_val):
return '{}={}'.format(name, str_val)


# Instantiate a PapermillIO instance and register Handlers.
papermill_translators = PapermillTranslators()
papermill_translators.register("python", PythonTranslator)
Expand All @@ -554,6 +582,7 @@ def assign(cls, name, str_val):
papermill_translators.register("pysparkkernel", PythonTranslator)
papermill_translators.register("sparkkernel", ScalaTranslator)
papermill_translators.register("sparkrkernel", RTranslator)
papermill_translators.register("bash", BashTranslator)


def translate_parameters(kernel_name, language, parameters, comment='Parameters'):
Expand Down

0 comments on commit 66a3c5c

Please sign in to comment.