Skip to content

Commit

Permalink
feat: Add interactive mode
Browse files Browse the repository at this point in the history
  • Loading branch information
achillesrasquinha committed Jan 23, 2019
1 parent 884ea9f commit 6d247f9
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 12 deletions.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion docker/pipupgrade
Original file line number Diff line number Diff line change
@@ -1 +1 @@
docker run --rm -it pipupgrade "$@"
docker run --rm -it achillesrasquinha/pipupgrade "$@"
5 changes: 4 additions & 1 deletion src/pipupgrade/cli/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -48,7 +52,6 @@ def get_parser():
action = "store_true",
help = "Display verbose output."
)

parser.add_argument("-v", "--version",
action = "version",
version = __version__,
Expand Down
35 changes: 25 additions & 10 deletions src/pipupgrade/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand Down

0 comments on commit 6d247f9

Please sign in to comment.