From 1a89fa88aaffaaebdb73ea3ef8688aaaed08a631 Mon Sep 17 00:00:00 2001 From: Joseph Yu Date: Sun, 22 Mar 2020 21:12:12 +0000 Subject: [PATCH 1/3] Initial implementation --- src/rez/cli/pip.py | 29 +---------------------------- src/rez/pip.py | 34 ++++++++++++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 30 deletions(-) diff --git a/src/rez/cli/pip.py b/src/rez/cli/pip.py index 5e4de1adb..911ee1987 100644 --- a/src/rez/cli/pip.py +++ b/src/rez/cli/pip.py @@ -61,7 +61,7 @@ def command(opts, parser, extra_arg_groups=None): category=DeprecationWarning ) - installed_variants, skipped_variants = pip_install_package( + pip_install_package( opts.PACKAGE, pip_version=opts.pip_ver, python_version=opts.py_ver, @@ -69,33 +69,6 @@ def command(opts, parser, extra_arg_groups=None): prefix=opts.prefix, extra_args=opts.extra) - # print summary - # - - def print_variant(v): - pkg = v.parent - txt = "%s: %s" % (pkg.qualified_name, pkg.uri) - if v.subpath: - txt += " (%s)" % v.subpath - print(" " + txt) - - print() - if installed_variants: - print("%d packages were installed:" % len(installed_variants)) - for variant in installed_variants: - print_variant(variant) - else: - print("NO packages were installed.") - - if skipped_variants: - print() - print("%d packages were already installed:" % len(skipped_variants)) - for variant in skipped_variants: - print_variant(variant) - - print() - - # Copyright 2013-2016 Allan Johns. # # This library is free software: you can redistribute it and/or diff --git a/src/rez/pip.py b/src/rez/pip.py index 799fe6599..0e9ea6a99 100644 --- a/src/rez/pip.py +++ b/src/rez/pip.py @@ -278,6 +278,25 @@ def pip_install_package(source_name, pip_version=None, python_version=None, distributions = list(distribution_path.get_distributions()) dist_names = [x.name for x in distributions] + def extend_variants(pkg_maker): + template = '{action} [{package.qualified_name}] {package.uri}{suffix}' + actions_variants = [ + ( + print_info, 'Installed', + installed_variants, pkg_maker.installed_variants or [], + ), + ( + print_debug, 'Skipped', + skipped_variants, pkg_maker.skipped_variants or [], + ), + ] + for print_, action, variants, pkg_variants in actions_variants: + for variant in pkg_variants: + variants.append(variant) + package = variant.parent + suffix = (' (%s)' % variant.subpath) if variant.subpath else '' + print_(template.format(**locals())) + # get list of package and dependencies for distribution in distributions: # convert pip requirements into rez requirements @@ -377,12 +396,23 @@ def make_root(variant, path): pkg.from_pip = True pkg.is_pure_python = metadata["is_pure_python"] - installed_variants.extend(pkg.installed_variants or []) - skipped_variants.extend(pkg.skipped_variants or []) + extend_variants(pkg) # cleanup shutil.rmtree(targetpath) + # print summary + # + if installed_variants: + print_info("%d packages were installed.", len(installed_variants)) + else: + print_warning("NO packages were installed.") + if skipped_variants: + print_warning( + "%d packages were already installed.", + len(skipped_variants), + ) + return installed_variants, skipped_variants From a4f2db7cf63bd738e7ad32f6628877f9e91a530b Mon Sep 17 00:00:00 2001 From: Joseph Yu Date: Sun, 22 Mar 2020 21:36:13 +0000 Subject: [PATCH 2/3] Set core rez logger to NOT debug --- src/rez/cli/pip.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/rez/cli/pip.py b/src/rez/cli/pip.py index 911ee1987..f851a9301 100644 --- a/src/rez/cli/pip.py +++ b/src/rez/cli/pip.py @@ -3,6 +3,7 @@ """ from __future__ import print_function from argparse import REMAINDER +import logging def setup_parser(parser, completions=False): @@ -40,6 +41,8 @@ def setup_parser(parser, completions=False): def command(opts, parser, extra_arg_groups=None): from rez.config import config config.debug_package_release = opts.verbose # Used by rez.pip._verbose + if not opts.verbose: # To stop other loggers from printing debugs + logging.getLogger('rez').setLevel(logging.INFO) from rez.pip import pip_install_package, run_pip_command import warnings From ff1d2f83ddf5c6df3334e6ef591c8ee23265f56d Mon Sep 17 00:00:00 2001 From: Joseph Yu Date: Sun, 22 Mar 2020 22:48:43 +0000 Subject: [PATCH 3/3] Fixed silented debug_package_release --- src/rez/cli/pip.py | 7 +++++-- src/rez/pip.py | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/rez/cli/pip.py b/src/rez/cli/pip.py index f851a9301..040b6bc6b 100644 --- a/src/rez/cli/pip.py +++ b/src/rez/cli/pip.py @@ -40,8 +40,11 @@ def setup_parser(parser, completions=False): def command(opts, parser, extra_arg_groups=None): from rez.config import config - config.debug_package_release = opts.verbose # Used by rez.pip._verbose - if not opts.verbose: # To stop other loggers from printing debugs + + # debug_package_release is used by rez.pip._verbose + config.debug_package_release = config.debug_package_release or opts.verbose + if not config.debug_package_release: + # Prevent other rez.* loggers from printing debugs logging.getLogger('rez').setLevel(logging.INFO) from rez.pip import pip_install_package, run_pip_command diff --git a/src/rez/pip.py b/src/rez/pip.py index 0e9ea6a99..e40e16e1a 100644 --- a/src/rez/pip.py +++ b/src/rez/pip.py @@ -278,7 +278,7 @@ def pip_install_package(source_name, pip_version=None, python_version=None, distributions = list(distribution_path.get_distributions()) dist_names = [x.name for x in distributions] - def extend_variants(pkg_maker): + def log_append_pkg_variants(pkg_maker): template = '{action} [{package.qualified_name}] {package.uri}{suffix}' actions_variants = [ ( @@ -396,7 +396,7 @@ def make_root(variant, path): pkg.from_pip = True pkg.is_pure_python = metadata["is_pure_python"] - extend_variants(pkg) + log_append_pkg_variants(pkg) # cleanup shutil.rmtree(targetpath)