pip_upgrader/cli.py
def main():
    """ Main CLI entrypoint. """
    options = get_options()
    Windows.enable(auto_colors=True, reset_atexit=True)

    try:
        # maybe check if virtualenv is not activated
        check_for_virtualenv(options)

        # 1. detect requirements files
        filenames = RequirementsDetector(options.get('<requirements_file>')).get_filenames()
        if filenames:
            print(Color('{{autoyellow}}Found valid requirements file(s):{{/autoyellow}} '
                        '{{autocyan}}\n{}{{/autocyan}}'.format('\n'.join(filenames))))
        else:  # pragma: nocover
            print(Color('{autoyellow}No requirements files found in current directory. CD into your project '
                        'or manually specify requirements files as arguments.{/autoyellow}'))
            return
        # 2. detect all packages inside requirements
        packages = PackagesDetector(filenames).get_packages()

        # 3. query pypi API, see which package has a newer version vs the one in requirements (or current env)
        packages_status_map = PackagesStatusDetector(
            packages, options.get('--use-default-index')).detect_available_upgrades(options)

        # 4. [optionally], show interactive screen when user can choose which packages to upgrade
        selected_packages = PackageInteractiveSelector(packages_status_map, options).get_packages()

        # 5. having the list of packages, do the actual upgrade and replace the version inside all filenames
        upgraded_packages = PackagesUpgrader(selected_packages, filenames, options).do_upgrade()

        print(Color('{{autogreen}}Successfully upgraded (and updated requirements) for the following packages: '
                    '{}{{/autogreen}}'.format(','.join([package['name'] for package in upgraded_packages]))))
        if options['--dry-run']:
            print(Color('{automagenta}Actually, no, because this was a simulation using --dry-run{/automagenta}'))

    except KeyboardInterrupt:  # pragma: nocover
        print(Color('\n{autored}Upgrade interrupted.{/autored}'))
def main():
    """ Main CLI entrypoint. """
    options = get_options()
    Windows.enable(auto_colors=True, reset_atexit=True)

    try:
        # maybe check if virtualenv is not activated
        check_for_virtualenv(options)

        # 1. detect requirements files
        filenames = RequirementsDetector(options.get('<requirements_file>')).get_filenames()
        if filenames:
            print(Color('{{autoyellow}}Found valid requirements file(s):{{/autoyellow}} '
                        '{{autocyan}}\n{}{{/autocyan}}'.format('\n'.join(filenames))))
        else:  # pragma: nocover
            print(Color('{autoyellow}No requirements files found in current directory. CD into your project '
                        'or manually specify requirements files as arguments.{/autoyellow}'))
            return
        # 2. detect all packages inside requirements
        packages = PackagesDetector(filenames).get_packages()

        # 3. query pypi API, see which package has a newer version vs the one in requirements (or current env)
        packages_status_map = PackagesStatusDetector(
            packages, options.get('--use-default-index')).detect_available_upgrades(options)

        # 4. [optionally], show interactive screen when user can choose which packages to upgrade
        selected_packages = PackageInteractiveSelector(packages_status_map, options).get_packages()

        # 5. having the list of packages, do the actual upgrade and replace the version inside all filenames
        upgraded_packages = PackagesUpgrader(selected_packages, filenames, options).do_upgrade()

        print(Color('{{autogreen}}Successfully upgraded (and updated requirements) for the following packages: '
                    '{}{{/autogreen}}'.format(','.join([package['name'] for package in upgraded_packages]))))
        if options['--dry-run']:
            print(Color('{automagenta}Actually, no, because this was a simulation using --dry-run{/automagenta}'))

    except KeyboardInterrupt:  # pragma: nocover
        print(Color('\n{autored}Upgrade interrupted.{/autored}'))
def main ( ) : options = get_options ( ) Windows . enable ( auto_colors = True , reset_atexit = True ) try : # maybe check if virtualenv is not activated check_for_virtualenv ( options ) # 1. detect requirements files filenames = RequirementsDetector ( options . get ( '<requirements_file>' ) ) . get_filenames ( ) if filenames : print ( Color ( '{{autoyellow}}Found valid requirements file(s):{{/autoyellow}} ' '{{autocyan}}\n{}{{/autocyan}}' . format ( '\n' . join ( filenames ) ) ) ) else : # pragma: nocover print ( Color ( '{autoyellow}No requirements files found in current directory. CD into your project ' 'or manually specify requirements files as arguments.{/autoyellow}' ) ) return # 2. detect all packages inside requirements packages = PackagesDetector ( filenames ) . get_packages ( ) # 3. query pypi API, see which package has a newer version vs the one in requirements (or current env) packages_status_map = PackagesStatusDetector ( packages , options . get ( '--use-default-index' ) ) . detect_available_upgrades ( options ) # 4. [optionally], show interactive screen when user can choose which packages to upgrade selected_packages = PackageInteractiveSelector ( packages_status_map , options ) . get_packages ( ) # 5. having the list of packages, do the actual upgrade and replace the version inside all filenames upgraded_packages = PackagesUpgrader ( selected_packages , filenames , options ) . do_upgrade ( ) print ( Color ( '{{autogreen}}Successfully upgraded (and updated requirements) for the following packages: ' '{}{{/autogreen}}' . format ( ',' . join ( [ package [ 'name' ] for package in upgraded_packages ] ) ) ) ) if options [ '--dry-run' ] : print ( Color ( '{automagenta}Actually, no, because this was a simulation using --dry-run{/automagenta}' ) ) except KeyboardInterrupt : # pragma: nocover print ( Color ( '\n{autored}Upgrade interrupted.{/autored}' ) )
Main CLI entrypoint.
Main CLI entrypoint .