# Path: datapackage_pipelines/wrapper/wrapper.py
# def ingest(debug=False):
#     params, datapackage, resource_iterator = _ingest(debug=debug)
#     return ProcessorContext(params, datapackage, resource_iterator)
# 
# Path: datapackage_pipelines/utilities/flow_utils.py
# def spew_flow(flow, ctx: ProcessorContext):
#     flow = Flow(
#         update_package(**ctx.datapackage),
#         load((ctx.datapackage, ctx.resource_iterator)),
#         flow,
#     )
#     datastream = flow.datastream()
#     ctx.datapackage = datastream.dp.descriptor
#     ctx.resource_iterator = datastream.res_iter
#     ctx.stats = MergeableStats(datastream.stats, ctx.stats)
# 
# Path: datapackage_pipelines/utilities/resources.py
# PROP_STREAMING = 'dpp:streaming'
# 
# PROP_STREAMED_FROM = 'dpp:streamedFrom'


from dataflows import Flow, load
from datapackage_pipelines.wrapper import ingest
from datapackage_pipelines.utilities.flow_utils import spew_flow
from datapackage_pipelines.utilities.resources import PROP_STREAMING, PROP_STREAMED_FROM
    _from = parameters.pop('from')

    num_resources = 0

    def count_resources():
        def func(package):
            global num_resources
            num_resources = len(package.pkg.resources)
            yield package.pkg
            yield from package
        return func

    def mark_streaming(_from):
        def func(package):
            for i in range(num_resources, len(package.pkg.resources)):
                package.pkg.descriptor['resources'][i].setdefault(PROP_STREAMING, True)
                package.pkg.descriptor['resources'][i].setdefault(PROP_STREAMED_FROM,  _from)
            yield package.pkg
            yield from package
        return func

    return Flow(
        count_resources(),
        load(_from, **parameters),
        mark_streaming(_from),
    )


if __name__ == '__main__':
    with ingest() as ctx:

# Path: datapackage_pipelines/wrapper/wrapper.py
# def ingest(debug=False):
#     params, datapackage, resource_iterator = _ingest(debug=debug)
#     return ProcessorContext(params, datapackage, resource_iterator)
# 
# Path: datapackage_pipelines/utilities/flow_utils.py
# def spew_flow(flow, ctx: ProcessorContext):
#     flow = Flow(
#         update_package(**ctx.datapackage),
#         load((ctx.datapackage, ctx.resource_iterator)),
#         flow,
#     )
#     datastream = flow.datastream()
#     ctx.datapackage = datastream.dp.descriptor
#     ctx.resource_iterator = datastream.res_iter
#     ctx.stats = MergeableStats(datastream.stats, ctx.stats)
# 
# Path: datapackage_pipelines/utilities/resources.py
# PROP_STREAMING = 'dpp:streaming'
# 
# PROP_STREAMED_FROM = 'dpp:streamedFrom'


# Path: datapackage_pipelines/lib/load.py
from dataflows import Flow, load
from datapackage_pipelines.wrapper import ingest
from datapackage_pipelines.utilities.flow_utils import spew_flow
from datapackage_pipelines.utilities.resources import PROP_STREAMING, PROP_STREAMED_FROM

    _from = parameters.pop('from')

    num_resources = 0

    def count_resources():
        def func(package):
            global num_resources
            num_resources = len(package.pkg.resources)
            yield package.pkg
            yield from package
        return func

    def mark_streaming(_from):
        def func(package):
            for i in range(num_resources, len(package.pkg.resources)):
                package.pkg.descriptor['resources'][i].setdefault(PROP_STREAMING, True)
                package.pkg.descriptor['resources'][i].setdefault(PROP_STREAMED_FROM,  _from)
            yield package.pkg
            yield from package
        return func

    return Flow(
        count_resources(),
        load(_from, **parameters),
        mark_streaming(_from),
    )


if __name__ == '__main__':
    with ingest() as ctx:

        spew_flow(flow(ctx.parameters), ctx)