From 172a7760870b2842cc8dfea436bfb5c2cbfe7710 Mon Sep 17 00:00:00 2001 From: parsa Date: Mon, 20 Feb 2023 11:35:49 +0330 Subject: [PATCH 1/4] clean routes --- pip_review/__main__.py | 42 +++++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/pip_review/__main__.py b/pip_review/__main__.py index 32615cdc2..9d6dc6296 100755 --- a/pip_review/__main__.py +++ b/pip_review/__main__.py @@ -91,8 +91,8 @@ def parse_args(): '--preview', '-p', action='store_true', default=False, help='Preview update target list before execution') parser.add_argument( - '--preview-only', '-P', action='store_true', default=False, - help='Preview only') + '--preview-auto', '-P', action='store_true', default=False, + help='Preview the list of the updateable packages and updates them all.') return parser.parse_known_args() @@ -235,7 +235,8 @@ def get_outdated_packages(forwarded): return packages -# Nicer headings for the columns in the oudated package table. +# Single source of truth about columns. The remainder of the code +# makes no assumptions about names, order or number of columns. COLUMNS = { 'Package': 'name', 'Version': 'version', @@ -270,31 +271,46 @@ def format_table(columns): body = rows[1:] return '\n'.join([head, ruler] + body + [ruler]) +# Clean separation of concerns, no repetition! + def main(): args, forwarded = parse_args() list_args = filter_forwards(forwarded, INSTALL_ONLY) install_args = filter_forwards(forwarded, LIST_ONLY) - logger = setup_logging(args.verbose) - if args.raw and args.interactive: - raise SystemExit('--raw and --interactive cannot be used together') +### case: --verbose + + logger = setup_logging(args.verbose) outdated = get_outdated_packages(list_args) if not outdated and not args.raw: logger.info('Everything up-to-date') - return - if args.preview or args.preview_only: + +### case: --preview + + if args.preview: logger.info(format_table(extract_table(outdated))) - if args.preview_only: - return + +### case: --preview-auto + + if args.preview_only: + logger.info(format_table(extract_table(outdated))) + +### case: --auto +### case: --continue-on-fail +### case: --freeze-outdated-packages + if args.auto: update_packages(outdated, install_args, args.continue_on_fail, args.freeze_outdated_packages) - return + +### case: --raw + if args.raw: for pkg in outdated: logger.info('{0}=={1}'.format(pkg['name'], pkg['latest_version'])) - return + +### case: --interactive selected = [] for pkg in outdated: @@ -314,4 +330,4 @@ def main(): main() except KeyboardInterrupt: sys.stdout.write('\nAborted\n') - sys.exit(0) + sys.exit(0) \ No newline at end of file From c039fd633a4cf9f9199e4fa6ae2fa6d7122d13a6 Mon Sep 17 00:00:00 2001 From: parsa Date: Mon, 20 Feb 2023 16:33:53 +0330 Subject: [PATCH 2/4] improvements on arguements default argument / edit on interactive / edit on others --- pip_review/__main__.py | 112 +++++++++++++++++++++++++++-------------- 1 file changed, 75 insertions(+), 37 deletions(-) diff --git a/pip_review/__main__.py b/pip_review/__main__.py index 9d6dc6296..8f8ba6f71 100755 --- a/pip_review/__main__.py +++ b/pip_review/__main__.py @@ -69,30 +69,62 @@ def parse_args(): description=description, epilog=EPILOG+version_epilog(), ) + +# ---------------------------- + parser.add_argument( '--verbose', '-v', action='store_true', default=False, help='Show more output') + + ''' example: + ezdxf==1.0.2 is available (you have 0.8.0) + pip==23.0.1 is available (you have 22.0.4) + setuptools==67.3.2 is available (you have 58.1.0) + ''' + parser.add_argument( - '--raw', '-r', action='store_true', default=False, + '--raw', '-r', action='store_true', default=True, help='Print raw lines (suitable for passing to pip install)') + + ''' example: + ezdxf==1.0.2 + pip==23.0.1 + setuptools==67.3.2 + ''' + parser.add_argument( '--interactive', '-i', action='store_true', default=False, help='Ask interactively to install updates') + parser.add_argument( '--auto', '-a', action='store_true', default=False, help='Automatically install every update found') + parser.add_argument( '--continue-on-fail', '-C', action='store_true', default=False, help='Continue with other installs when one fails') + parser.add_argument( '--freeze-outdated-packages', action='store_true', default=False, help='Freeze all outdated packages to "requirements.txt" before upgrading them') + parser.add_argument( '--preview', '-p', action='store_true', default=False, help='Preview update target list before execution') + + ''' exmple: + Package Version Latest Type + ------------------------------- + ezdxf 0.8.0 1.0.2 wheel + pip 22.0.4 23.0.1 wheel + setuptools 58.1.0 67.3.2 wheel + ------------------------------- + ''' + parser.add_argument( - '--preview-auto', '-P', action='store_true', default=False, - help='Preview the list of the updateable packages and updates them all.') + '--preview-only', '-P', action='store_true', default=False, + help='Preview only') + return parser.parse_known_args() @@ -235,8 +267,7 @@ def get_outdated_packages(forwarded): return packages -# Single source of truth about columns. The remainder of the code -# makes no assumptions about names, order or number of columns. +# Nicer headings for the columns in the oudated package table. COLUMNS = { 'Package': 'name', 'Version': 'version', @@ -271,59 +302,66 @@ def format_table(columns): body = rows[1:] return '\n'.join([head, ruler] + body + [ruler]) -# Clean separation of concerns, no repetition! - def main(): args, forwarded = parse_args() list_args = filter_forwards(forwarded, INSTALL_ONLY) install_args = filter_forwards(forwarded, LIST_ONLY) - -### case: --verbose - logger = setup_logging(args.verbose) - outdated = get_outdated_packages(list_args) - if not outdated and not args.raw: - logger.info('Everything up-to-date') - -### case: --preview - - if args.preview: - logger.info(format_table(extract_table(outdated))) -### case: --preview-auto - - if args.preview_only: - logger.info(format_table(extract_table(outdated))) +# --verbose + if args.verbose: + for pkg in outdated: + logger.info('{0}=={1} is available (you have {2})'.format( + pkg['name'], pkg['latest_version'], pkg['version'] + )) -### case: --auto -### case: --continue-on-fail -### case: --freeze-outdated-packages +# --raw +# --interactive - if args.auto: - update_packages(outdated, install_args, args.continue_on_fail, args.freeze_outdated_packages) + if args.raw and args.interactive: + raise SystemExit('--raw and --interactive cannot be used together') -### case: --raw + if not outdated and not args.raw: + logger.info('Everything up-to-date') + return +# --raw if args.raw: for pkg in outdated: logger.info('{0}=={1}'.format(pkg['name'], pkg['latest_version'])) + return + +# --interactive + if args.interactive: + selected = [] -### case: --interactive + for pkg in outdated: + logger.info('{0}=={1} is available (you have {2})'.format( + pkg['name'], pkg['latest_version'], pkg['version'] + )) - selected = [] - for pkg in outdated: - logger.info('{0}=={1} is available (you have {2})'.format( - pkg['name'], pkg['latest_version'], pkg['version'] - )) - if args.interactive: answer = ask_to_install() + if answer in ['y', 'a']: selected.append(pkg) - if selected: - update_packages(selected, install_args, args.continue_on_fail, args.freeze_outdated_packages) + if selected: + update_packages(selected, install_args, args.continue_on_fail, args.freeze_outdated_packages) + +# --auto + if args.auto: + update_packages(outdated, install_args, args.continue_on_fail, args.freeze_outdated_packages) + return + +# --preview + if args.preview: + logger.info(format_table(extract_table(outdated))) + +# --preview-only + if args.preview_only: + return if __name__ == '__main__': try: From 75e40ba5909491cafa29f5fb5aaf5afd418aed93 Mon Sep 17 00:00:00 2001 From: parsa Date: Mon, 20 Feb 2023 16:53:17 +0330 Subject: [PATCH 3/4] preview-only arguement replaced by visual arguement --- pip_review/__main__.py | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/pip_review/__main__.py b/pip_review/__main__.py index 8f8ba6f71..94f9cb7f1 100755 --- a/pip_review/__main__.py +++ b/pip_review/__main__.py @@ -83,7 +83,7 @@ def parse_args(): ''' parser.add_argument( - '--raw', '-r', action='store_true', default=True, + '--raw', '-r', action='store_true', default=False, help='Print raw lines (suitable for passing to pip install)') ''' example: @@ -122,8 +122,8 @@ def parse_args(): ''' parser.add_argument( - '--preview-only', '-P', action='store_true', default=False, - help='Preview only') + '--visual', '-s', action='store_true', default=False, + help='Interactively select the packages for update, see a visual report and do the updates') return parser.parse_known_args() @@ -360,7 +360,35 @@ def main(): logger.info(format_table(extract_table(outdated))) # --preview-only - if args.preview_only: + if args.visual: + selected = [] + + for pkg in outdated: + logger.info('{0}=={1} is available (you have {2})'.format( + pkg['name'], pkg['latest_version'], pkg['version'] + )) + + answer = ask_to_install() + + if answer in ['y', 'a']: + selected.append(pkg) + + if not selected: + logger.info('No packages selected for update / upgrade') + return + + if selected: + logger.info('Selected packages for update / upgrade are') + logger.info(format_table(extract_table(selected))) + + answer = ask_to_install() + + if answer in ['y', 'a']: + update_packages(selected, install_args, args.continue_on_fail, args.freeze_outdated_packages) + + else: + logger.info('You chose to quit the update process') + return if __name__ == '__main__': From d0c77923b33a1af94af4c09694da06dff8976191 Mon Sep 17 00:00:00 2001 From: parsa Date: Mon, 20 Feb 2023 16:56:33 +0330 Subject: [PATCH 4/4] readme updated --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index bae3153e2..ae53802bc 100644 --- a/README.rst +++ b/README.rst @@ -57,7 +57,7 @@ Example, preview for update target list by ``pip list --outdated`` format, with $ pip-review --auto --preview ... -Example, only preview for update target list: +Example, preview a table of the update target list, which is a combination of the interactive and preview formats: .. code:: console