From 6d247f9e899bd8667a51b451a1149fa440fa9704 Mon Sep 17 00:00:00 2001 From: Achilles Rasquinha Date: Tue, 22 Jan 2019 20:07:24 -0600 Subject: [PATCH] feat: Add interactive mode --- .../Bug.md} | 0 .../{templates => }/PULL_REQUEST_TEMPLATE.md | 0 docker/pipupgrade | 2 +- src/pipupgrade/cli/parser.py | 5 ++- src/pipupgrade/commands/__init__.py | 35 +++++++++++++------ 5 files changed, 30 insertions(+), 12 deletions(-) rename .github/{templates/ISSUE_TEMPLATE.md => ISSUE_TEMPLATE/Bug.md} (100%) rename .github/{templates => }/PULL_REQUEST_TEMPLATE.md (100%) diff --git a/.github/templates/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE/Bug.md similarity index 100% rename from .github/templates/ISSUE_TEMPLATE.md rename to .github/ISSUE_TEMPLATE/Bug.md diff --git a/.github/templates/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md similarity index 100% rename from .github/templates/PULL_REQUEST_TEMPLATE.md rename to .github/PULL_REQUEST_TEMPLATE.md diff --git a/docker/pipupgrade b/docker/pipupgrade index 73194c4..5aeeb7c 100755 --- a/docker/pipupgrade +++ b/docker/pipupgrade @@ -1 +1 @@ -docker run --rm -it pipupgrade "$@" \ No newline at end of file +docker run --rm -it achillesrasquinha/pipupgrade "$@" \ No newline at end of file diff --git a/src/pipupgrade/cli/parser.py b/src/pipupgrade/cli/parser.py index 4726642..8a266d0 100644 --- a/src/pipupgrade/cli/parser.py +++ b/src/pipupgrade/cli/parser.py @@ -35,6 +35,10 @@ def get_parser(): action = "append", help = "Path to requirements.txt file." ) + parser.add_argument("-i", "--interactive", + action = "store_true", + help = "Interactive Mode" + ) parser.add_argument("-u", "--user", action = "store_true", help = "Install to the Python user install directory for environment \ @@ -48,7 +52,6 @@ def get_parser(): action = "store_true", help = "Display verbose output." ) - parser.add_argument("-v", "--version", action = "version", version = __version__, diff --git a/src/pipupgrade/commands/__init__.py b/src/pipupgrade/commands/__init__.py index 17d1584..5278dc2 100644 --- a/src/pipupgrade/commands/__init__.py +++ b/src/pipupgrade/commands/__init__.py @@ -95,7 +95,7 @@ def _update_requirements(path, package): write(path, content) @cli.command -def command(requirements = [ ], latest = False, self = False, user = False, check = False, yes = False, no_color = True, verbose = False): +def command(requirements = [ ], latest = False, self = False, user = False, check = False, interactive = False, yes = False, no_color = True, verbose = False): cli.echo(cli_format("Checking...", cli.YELLOW)) registry = dict() @@ -151,17 +151,32 @@ def command(requirements = [ ], latest = False, self = False, user = False, chec string = table.render() cli.echo("\nSource: %s\n" % stitle) - cli.echo(string) - cli.echo() + + if not interactive: + cli.echo(string) + cli.echo() if not check: - npackages = len(dinfo) - (len([p for p in dinfo if p.diff_type == "major"]) if not latest else 0) - spackages = pluralize("package", npackages) # Packages "string" + packages = [p for p in dinfo if p.diff_type != "major" or latest] + npackages = len(packages) - query = "Do you wish to update %s %s?" % (npackages, spackages) - if npackages and (yes or cli.confirm(query)): - for i, package in enumerate(dinfo): - if package.diff_type != "major" or latest: + spackages = pluralize("package", npackages) # Packages "string" + query = "Do you wish to update %s %s?" % (npackages, spackages) + + if npackages and (yes or interactive or cli.confirm(query)): + for i, package in enumerate(packages): + update = True + + query = "%s (%s > %s)" % ( + cli_format(package.name, _SEMVER_COLOR_MAP.get(package.diff_type, cli.CLEAR)), + package.current_version, + _cli_format_semver(package.latest_version, package.diff_type) + ) + + if interactive: + update = yes or cli.confirm(query) + + if update: cli.echo(cli_format( "Updating %s of %s %s: %s" % ( i + 1, @@ -171,7 +186,7 @@ def command(requirements = [ ], latest = False, self = False, user = False, chec ) , cli.BOLD)) - _pip.install(package.name, user = user, quiet = not verbose, no_cache = True, upgrade = True) + _pip.install(package.name, user = user, quiet = not verbose, no_cache_dir = True, upgrade = True) if package.source != "__INSTALLED__": _update_requirements(package.source, package)