Skip to content

Commit

Permalink
util
Browse files Browse the repository at this point in the history
  • Loading branch information
neelasha23 committed Jan 21, 2024
1 parent ca09ea4 commit c934a4a
Showing 1 changed file with 18 additions and 33 deletions.
51 changes: 18 additions & 33 deletions src/sql/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,29 +579,6 @@ def enclose_table_with_double_quotations(table, conn):


def expand_args_cmd(args, user_ns):
for attribute in vars(args):
value = getattr(args, attribute)
if value:
if isinstance(value, list):
for item in value:
if (
isinstance(item, str)
and item.startswith("{{")
and item.endswith("}}")
and item != "with_"
):
setattr(args, attribute, Template(item).render(user_ns))
else:
if (
isinstance(value, str)
and value.startswith("{{")
and value.endswith("}}")
and value != "with_"
):
setattr(args, attribute, Template(value).render(user_ns))


def expand_args(args, user_ns, arguments_to_expand):
"""
Function to substitute command line arguments
with variables defined by user in the IPython
Expand All @@ -614,19 +591,27 @@ def expand_args(args, user_ns, arguments_to_expand):
user_ns : dict,
User namespace of IPython kernel
arguments_to_expand : list
List of arguments to expand
"""

for attribute in arguments_to_expand:
for attribute in vars(args):
value = getattr(args, attribute)
if value:
if isinstance(value, list):
setattr(
args,
attribute,
[Template(item).render(user_ns) for item in value],
)
substituted_value = []
for item in value:
if (
isinstance(item, str)
and item.startswith("{{")
and item.endswith("}}")
):
substituted_value.append(Template(item).render(user_ns))
else:
substituted_value.append(item)
setattr(args, attribute, substituted_value)
else:
setattr(args, attribute, Template(value).render(user_ns))
if (
isinstance(value, str)
and value.startswith("{{")
and value.endswith("}}")
):
setattr(args, attribute, Template(value).render(user_ns))

0 comments on commit c934a4a

Please sign in to comment.