Beispiel #1
0
def ask_to_update(req, spec_ver, latest_ver):
    """Prompts to update the current package.

    Returns True if should update, False if should skip, and raises
    SaveAndStopUpdating or StopUpdating exceptions if the user selected quit.

    :param req:         Instance of pip.req.req_install.InstallRequirement.
    :param spec_ver:    Tuple of current versions from the requirements file.
    :param latest_ver:  Latest version from pypi.
    """

    choices = ['y', 'n', 'q']

    msg = 'Update {package} from {old} to {new}? ({choices})'.format(
        package=req.name,
        old=old_version(spec_ver),
        new=latest_ver,
        choices=', '.join(choices),
    )
    while True:
        value = click.prompt(msg, default='y')
        value = value.lower()
        if value in choices:
            break
        _echo('Please enter either {0}.'.format(', '.join(choices)))

    if value == 'y':
        return True
    if value == 'n':
        return False

    # when value == 'q'
    raise StopUpdating()
def ask_to_update(req, spec_ver, latest_ver):
    """Prompts to update the current package.

    Returns True if should update, False if should skip, and raises
    SaveAndStopUpdating or StopUpdating exceptions if the user selected quit.

    :param req:         Instance of pip.req.req_install.InstallRequirement.
    :param spec_ver:    Tuple of current versions from the requirements file.
    :param latest_ver:  Latest version from pypi.
    """

    choices = ['y', 'n', 'q']

    msg = 'Update {package} from {old} to {new}? ({choices})'.format(
        package=req.name,
        old=old_version(spec_ver),
        new=latest_ver,
        choices=', '.join(choices),
    )
    while True:
        value = click.prompt(msg, default='y')
        value = value.lower()
        if value in choices:
            break
        _echo('Please enter either {0}.'.format(', '.join(choices)))

    if value == 'y':
        return True
    if value == 'n':
        return False

    # when value == 'q'
    raise StopUpdating()
Beispiel #3
0
 def check_io():
     output = ""
     while True:
         line = process.stdout.readline().decode("utf-8")
         if line:
             output += line
             if echo:
                 _echo(line[:-1])
         else:
             break
     return output
Beispiel #4
0
def pur(**options):
    """Command line entry point."""

    if not options['requirement']:
        options['requirement'] = 'requirements.txt'

    format_list_arg(options, 'skip')
    format_list_arg(options, 'only')
    format_list_arg(options, 'minor')
    format_list_arg(options, 'patch')
    format_list_arg(options, 'pre')

    options['echo'] = True

    global PUR_GLOBAL_UPDATED
    PUR_GLOBAL_UPDATED = 0

    update_requirements(
        input_file=options['requirement'],
        output_file=options['output'],
        force=options['force'],
        interactive=options['interactive'],
        skip=options['skip'],
        only=options['only'],
        minor=options['minor'],
        patch=options['patch'],
        pre=options['pre'],
        dry_run=options['dry_run'],
        no_recursive=options['no_recursive'],
        echo=options['echo'],
        index_urls=options['index_url'],
        verify=options['verify'],
    )

    if not options['dry_run']:
        _echo('All requirements up-to-date.')

    if options['nonzero_exit_code']:
        if PUR_GLOBAL_UPDATED > 0:
            raise ExitCodeException(11)
        raise ExitCodeException(10)
Beispiel #5
0
def pur(**options):
    """Command line entry point."""

    if not options['requirement']:
        options['requirement'] = 'requirements.txt'
    try:
        options['skip'] = set(x.strip().lower()
                              for x in options['skip'].split(','))
    except AttributeError:
        options['skip'] = set()
    try:
        options['only'] = set(x.strip().lower()
                              for x in options['only'].split(','))
    except AttributeError:
        options['only'] = set()

    options['echo'] = True

    global PUR_GLOBAL_UPDATED
    PUR_GLOBAL_UPDATED = 0

    update_requirements(
        input_file=options['requirement'],
        output_file=options['output'],
        force=options['force'],
        interactive=options['interactive'],
        skip=options['skip'],
        only=options['only'],
        dry_run=options['dry_run'],
        no_recursive=options['no_recursive'],
        echo=options['echo'],
    )

    if not options['dry_run']:
        _echo('All requirements up-to-date.')

    if options['nonzero_exit_code']:
        if PUR_GLOBAL_UPDATED > 0:
            raise ExitCodeException(11)
        raise ExitCodeException(10)
def pur(**options):
    """Command line entry point."""

    if not options['requirement']:
        options['requirement'] = 'requirements.txt'

    format_list_arg(options, 'skip')
    format_list_arg(options, 'only')
    format_list_arg(options, 'minor')
    format_list_arg(options, 'patch')
    format_list_arg(options, 'pre')

    options['echo'] = True

    global PUR_GLOBAL_UPDATED
    PUR_GLOBAL_UPDATED = 0

    update_requirements(
        input_file=options['requirement'],
        output_file=options['output'],
        force=options['force'],
        interactive=options['interactive'],
        skip=options['skip'],
        only=options['only'],
        minor=options['minor'],
        patch=options['patch'],
        pre=options['pre'],
        dry_run=options['dry_run'],
        no_recursive=options['no_recursive'],
        echo=options['echo'],
    )

    if not options['dry_run']:
        _echo('All requirements up-to-date.')

    if options['nonzero_exit_code']:
        if PUR_GLOBAL_UPDATED > 0:
            raise ExitCodeException(11)
        raise ExitCodeException(10)
Beispiel #7
0
def _internal_update_requirements(obuffer,
                                  updates,
                                  input_file=None,
                                  output_file=None,
                                  force=False,
                                  interactive=False,
                                  skip=[],
                                  only=[],
                                  minor=[],
                                  patch=[],
                                  pre=[],
                                  dry_run=False,
                                  no_recursive=False,
                                  index_urls=[],
                                  echo=False):
    global PUR_GLOBAL_UPDATED

    updated = 0

    try:
        requirements = _get_requirements_and_latest(input_file,
                                                    force=force,
                                                    minor=minor,
                                                    patch=patch,
                                                    pre=pre,
                                                    index_urls=index_urls)

        stop = False
        for line, req, spec_ver, latest_ver in requirements:

            if not stop and can_check_version(req, skip, only):

                try:
                    if should_update(req,
                                     spec_ver,
                                     latest_ver,
                                     force=force,
                                     interactive=interactive):

                        if not spec_ver[0]:
                            new_line = '{0}=={1}'.format(line, latest_ver)
                        else:
                            new_line = update_requirement_line(
                                req, line, spec_ver, latest_ver)
                        obuffer.write(new_line)

                        if new_line != line:
                            msg = 'Updated {package}: {old} -> {new}'.format(
                                package=req.name,
                                old=old_version(spec_ver),
                                new=latest_ver,
                            )
                            updated += 1
                            was_updated = True
                        else:
                            msg = 'New version for {package} found ({new}), ' \
                                  'but current spec prohibits updating: ' \
                                  '{line}'.format(package=req.name,
                                                  new=latest_ver,
                                                  line=line)
                            was_updated = False

                        updates[req.name].append({
                            'package':
                            req.name,
                            'current':
                            old_version(spec_ver),
                            'latest':
                            latest_ver,
                            'updated':
                            was_updated,
                            'message':
                            msg,
                        })
                        if echo and not dry_run:
                            _echo(msg)

                    else:
                        obuffer.write(line)
                except StopUpdating:
                    stop = True
                    obuffer.write(line)

            elif not output_file or not requirements_line(line, req):
                obuffer.write(line)

            if not output_file or not requirements_line(line, req):
                obuffer.write('\n')

    except InstallationError as e:
        raise click.ClickException(str(e))

    if dry_run and echo:
        _echo('==> ' + (output_file or input_file) + ' <==')
        _echo(obuffer.getvalue())

    PUR_GLOBAL_UPDATED += updated
def _internal_update_requirements(obuffer, updates, input_file=None,
                                  output_file=None, force=False,
                                  interactive=False, skip=[], only=[],
                                  minor=[], patch=[], pre=[],
                                  dry_run=False, no_recursive=False,
                                  echo=False):
    global PUR_GLOBAL_UPDATED

    updated = 0

    try:
        requirements = _get_requirements_and_latest(input_file, force=force,
                                                    minor=minor, patch=patch,
                                                    pre=pre)

        stop = False
        for line, req, spec_ver, latest_ver in requirements:

            if not stop and can_check_version(req, skip, only):

                try:
                    if should_update(req, spec_ver, latest_ver, force=force,
                                     interactive=interactive):

                        if not spec_ver[0]:
                            new_line = '{0}=={1}'.format(line, latest_ver)
                        else:
                            new_line = update_requirement_line(req, line,
                                                               spec_ver,
                                                               latest_ver)
                        obuffer.write(new_line)

                        if new_line != line:
                            msg = 'Updated {package}: {old} -> {new}'.format(
                                package=req.name,
                                old=old_version(spec_ver),
                                new=latest_ver,
                            )
                            updated += 1
                            was_updated = True
                        else:
                            msg = 'New version for {package} found ({new}), ' \
                                  'but current spec prohibits updating: ' \
                                  '{line}'.format(package=req.name,
                                                  new=latest_ver,
                                                  line=line)
                            was_updated = False

                        updates[req.name].append({
                            'package': req.name,
                            'current': old_version(spec_ver),
                            'latest': latest_ver,
                            'updated': was_updated,
                            'message': msg,
                        })
                        if echo and not dry_run:
                            _echo(msg)

                    else:
                        obuffer.write(line)
                except StopUpdating:
                    stop = True
                    obuffer.write(line)

            elif not output_file or not requirements_line(line, req):
                obuffer.write(line)

            if not output_file or not requirements_line(line, req):
                obuffer.write('\n')

    except InstallationError as e:
        raise click.ClickException(str(e))

    if dry_run and echo:
        _echo('==> ' + (output_file or input_file) + ' <==')
        _echo(obuffer.getvalue())

    PUR_GLOBAL_UPDATED += updated