# Path: peru/async_helpers.py
# async def gather_coalescing_exceptions(coros, display, *, verbose):
#     '''The tricky thing about running multiple coroutines in parallel is what
#     we're supposed to do when one of them raises an exception. The approach
#     we're using here is to catch exceptions and keep waiting for other tasks to
#     finish. At the end, we reraise a GatheredExceptions error, if any
#     exceptions were caught.
# 
#     Another minor detail: We also want to make sure to start coroutines in the
#     order given, so that they end up appearing to the user alphabetically in
#     the fancy display. Note that asyncio.gather() puts coroutines in a set
#     internally, so we schedule coroutines *before* we give them to gather().
#     '''
# 
#     exceptions = []
#     reprs = []
# 
#     async def catching_wrapper(coro):
#         try:
#             return (await coro)
#         except Exception as e:
#             exceptions.append(e)
#             if isinstance(e, PrintableError) and not verbose:
#                 reprs.append(e.message)
#             else:
#                 reprs.append(traceback.format_exc())
#             return None
# 
#     # Suppress a deprecation warning in Python 3.5, while continuing to support
#     # 3.3 and early 3.4 releases.
#     if hasattr(asyncio, 'ensure_future'):
#         schedule = getattr(asyncio, 'ensure_future')
#     else:
#         schedule = getattr(asyncio, 'async')
# 
#     futures = [schedule(catching_wrapper(coro)) for coro in coros]
# 
#     results = await asyncio.gather(*futures)
# 
#     if exceptions:
#         raise GatheredExceptions(exceptions, reprs)
#     else:
#         return results
# 
# def run_task(coro):
#     return EVENT_LOOP.run_until_complete(coro)
# 
# Path: peru/runtime.py
# async def Runtime(args, env):
#     'This is the async constructor for the _Runtime class.'
#     r = _Runtime(args, env)
#     await r._init_cache()
#     return r


import collections
import json
import os
import sys
import tempfile
import docopt
from .async_helpers import gather_coalescing_exceptions, run_task
from . import compat
from .error import PrintableError
from . import imports
from . import parser
from .runtime import Runtime
@peru_command('reup', '''\
Usage:
    peru reup [<modules>...] [-fhqv] [-j N] [--no-cache] [--no-overrides]
              [--no-sync]

Updates each module in your peru.yaml file with the latest revision
information from its source. For git, hg, and svn modules, this is the
`rev` field, and for a curl module it's the `sha1` field. Peru will
either add the field for you, or update it if it's already there. To
update specific modules instead of everything, pass their names as
positional arguments. Peru does a sync after the reup is done, though
you can prevent that with --no-sync.

Options:
    -f --force      for `peru sync`
    -h --help       what is even happening here?
    --no-cache      for `peru sync`
    --no-overrides  for `peru sync`
    --no-sync       skip the sync at the end
    -j N --jobs N   max number of parallel fetches
    -q --quiet      don't print anything
    -v --verbose    print everything
''')
async def do_reup(params):
    names = params.args['<modules>']
    if not names:
        modules = params.scope.modules.values()
    else:
        modules = params.scope.get_modules_for_reup(names)
    futures = [module.reup(params.runtime) for module in modules]

# Path: peru/async_helpers.py
# async def gather_coalescing_exceptions(coros, display, *, verbose):
#     '''The tricky thing about running multiple coroutines in parallel is what
#     we're supposed to do when one of them raises an exception. The approach
#     we're using here is to catch exceptions and keep waiting for other tasks to
#     finish. At the end, we reraise a GatheredExceptions error, if any
#     exceptions were caught.
# 
#     Another minor detail: We also want to make sure to start coroutines in the
#     order given, so that they end up appearing to the user alphabetically in
#     the fancy display. Note that asyncio.gather() puts coroutines in a set
#     internally, so we schedule coroutines *before* we give them to gather().
#     '''
# 
#     exceptions = []
#     reprs = []
# 
#     async def catching_wrapper(coro):
#         try:
#             return (await coro)
#         except Exception as e:
#             exceptions.append(e)
#             if isinstance(e, PrintableError) and not verbose:
#                 reprs.append(e.message)
#             else:
#                 reprs.append(traceback.format_exc())
#             return None
# 
#     # Suppress a deprecation warning in Python 3.5, while continuing to support
#     # 3.3 and early 3.4 releases.
#     if hasattr(asyncio, 'ensure_future'):
#         schedule = getattr(asyncio, 'ensure_future')
#     else:
#         schedule = getattr(asyncio, 'async')
# 
#     futures = [schedule(catching_wrapper(coro)) for coro in coros]
# 
#     results = await asyncio.gather(*futures)
# 
#     if exceptions:
#         raise GatheredExceptions(exceptions, reprs)
#     else:
#         return results
# 
# def run_task(coro):
#     return EVENT_LOOP.run_until_complete(coro)
# 
# Path: peru/runtime.py
# async def Runtime(args, env):
#     'This is the async constructor for the _Runtime class.'
#     r = _Runtime(args, env)
#     await r._init_cache()
#     return r


# Path: peru/main.py
import collections
import json
import os
import sys
import tempfile
import docopt
from .async_helpers import gather_coalescing_exceptions, run_task
from . import compat
from .error import PrintableError
from . import imports
from . import parser
from .runtime import Runtime

@peru_command('reup', '''\
Usage:
    peru reup [<modules>...] [-fhqv] [-j N] [--no-cache] [--no-overrides]
              [--no-sync]

Updates each module in your peru.yaml file with the latest revision
information from its source. For git, hg, and svn modules, this is the
`rev` field, and for a curl module it's the `sha1` field. Peru will
either add the field for you, or update it if it's already there. To
update specific modules instead of everything, pass their names as
positional arguments. Peru does a sync after the reup is done, though
you can prevent that with --no-sync.

Options:
    -f --force      for `peru sync`
    -h --help       what is even happening here?
    --no-cache      for `peru sync`
    --no-overrides  for `peru sync`
    --no-sync       skip the sync at the end
    -j N --jobs N   max number of parallel fetches
    -q --quiet      don't print anything
    -v --verbose    print everything
''')
async def do_reup(params):
    names = params.args['<modules>']
    if not names:
        modules = params.scope.modules.values()
    else:
        modules = params.scope.get_modules_for_reup(names)
    futures = [module.reup(params.runtime) for module in modules]

    await gather_coalescing_exceptions(