# Path: datapackage_pipelines/wrapper/wrapper.py
# def process(modify_datapackage=None,
#             process_row=None, debug=False):
#     with ingest(debug=debug) as ctx:
#         if modify_datapackage is not None:
#             ctx.datapackage = modify_datapackage(ctx.datapackage, ctx.parameters, ctx.stats)
# 
#         if process_row is not None:
#             ctx.resource_iterator = \
#                 generic_process_resources(ctx.resource_iterator,
#                                           ctx.parameters,
#                                           ctx.stats,
#                                           process_row)


from datapackage_pipelines.wrapper import process
# Add new column with constant value to first resource
# Column name and value are taken from the processor's parameters


def modify_datapackage(datapackage, parameters, _):
    datapackage['resources'][0]['schema']['fields'].append({
      'name': parameters['column-name'],
      'type': 'string'
    })
    return datapackage


def process_row(row, _1, _2, resource_index, parameters, _):
    if resource_index == 0:
        row[parameters['column-name']] = parameters['value']
    return row



# Path: datapackage_pipelines/wrapper/wrapper.py
# def process(modify_datapackage=None,
#             process_row=None, debug=False):
#     with ingest(debug=debug) as ctx:
#         if modify_datapackage is not None:
#             ctx.datapackage = modify_datapackage(ctx.datapackage, ctx.parameters, ctx.stats)
# 
#         if process_row is not None:
#             ctx.resource_iterator = \
#                 generic_process_resources(ctx.resource_iterator,
#                                           ctx.parameters,
#                                           ctx.stats,
#                                           process_row)


# Path: samples/add_constant.py
from datapackage_pipelines.wrapper import process

# Add new column with constant value to first resource
# Column name and value are taken from the processor's parameters


def modify_datapackage(datapackage, parameters, _):
    datapackage['resources'][0]['schema']['fields'].append({
      'name': parameters['column-name'],
      'type': 'string'
    })
    return datapackage


def process_row(row, _1, _2, resource_index, parameters, _):
    if resource_index == 0:
        row[parameters['column-name']] = parameters['value']
    return row



process(modify_datapackage=modify_datapackage,