I want to design a python decorator
that takes a function which is decorated and passes it down to another function. Here is code explanation of what I am trying to do:
def run_decorator(run_batch):
# inner function can access the outer local
# functions like in this case "func"
def check(command_to_run):
@functools.wraps(command_to_run)
def wrapper(*args, **kwargs):
batch_json_path = kwargs['batch_json_path']
batch_name = kwargs['batch_name']
folder_path = kwargs['folder_path']
if batch_json_path is not None:
if batch_present(batch_json_path, batch_name):
run_batch(batch_json_path, command_to_run, batch_name)
return wrapper
return check
def run_batch(batch_abs_path, command_to_run, batch_name=None):
with open(batch_abs_path) as json_file:
variant = ...
tag_data = ...
command_to_run(variant, batch_name, tag_data)
@run_decorator(run_batch=run_batch)
def load_tag_for_variant(variant, batch_name, tag_data):
Is such behavior possible to achieve? Any suggestions would be greatly appreciated.