From b49ef51bae32b7712906cbf177a9a6d3cc641ac3 Mon Sep 17 00:00:00 2001 From: Jose Enriquez Date: Mon, 14 Oct 2024 14:08:29 -0400 Subject: [PATCH 1/5] Add support for synchronous and asynchronous modes in package cache - Introduced a new command-line argument `--pkg-cache-mode` to specify caching mode. - Allows users to choose between 'sync' and 'async' modes, overriding the default configuration. - Updated `add_variant` function to handle the new caching mode option. - Ensures backward compatibility by maintaining default behavior when no mode is specified. Signed-off-by: Jose Enriquez --- src/rez/cli/pkg-cache.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/rez/cli/pkg-cache.py b/src/rez/cli/pkg-cache.py index 367b7a0af..b91e83f09 100644 --- a/src/rez/cli/pkg-cache.py +++ b/src/rez/cli/pkg-cache.py @@ -41,6 +41,14 @@ def setup_parser(parser, completions=False): group.add_argument( "--daemon", action="store_true", help=SUPPRESS ) + parser.add_argument( + "--pkg-cache-mode", + choices=["sync", "async"], + default=None, + help="If provided, override the rezconfig's package_cache_async key. " + "If 'sync', the process will block until packages are cached. " + "If 'async', the process will not block while packages are cached." + ) parser.add_argument( "-c", "--columns", nargs='+', choices=column_choices, default=["status", "package", "variant_uri", "cache_path"], @@ -70,7 +78,15 @@ def add_variant(pkgcache, uri, opts): print("No such variant: %s" % uri, file=sys.stderr) sys.exit(1) - destpath, status = pkgcache.add_variant(variant, force=opts.force) + if opts.pkg_cache_mode is not None: + cache_mode = True if opts.pkg_cache_mode == "sync" else False + destpath, status = pkgcache.add_variant( + variant, force=opts.force, + wait_for_copying=cache_mode + ) + # If no mode is specified, use the default behavior. + else: + destpath, status = pkgcache.add_variant(variant, force=opts.force) if status == PackageCache.VARIANT_FOUND: print_info("Already exists: %s", destpath) From 81844949744d01e38cb3fa17639dab07cbee86e2 Mon Sep 17 00:00:00 2001 From: Jose Enriquez <1145623+Pixel-Minions@users.noreply.github.com> Date: Mon, 14 Oct 2024 22:11:44 -0400 Subject: [PATCH 2/5] Update src/rez/cli/pkg-cache.py Signed-off-by: Jose Enriquez Co-authored-by: Jean-Christophe Morin <38703886+JeanChristopheMorinPerso@users.noreply.github.com> Signed-off-by: Jose Enriquez <1145623+Pixel-Minions@users.noreply.github.com> --- src/rez/cli/pkg-cache.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/rez/cli/pkg-cache.py b/src/rez/cli/pkg-cache.py index b91e83f09..d1613cd98 100644 --- a/src/rez/cli/pkg-cache.py +++ b/src/rez/cli/pkg-cache.py @@ -78,15 +78,17 @@ def add_variant(pkgcache, uri, opts): print("No such variant: %s" % uri, file=sys.stderr) sys.exit(1) - if opts.pkg_cache_mode is not None: - cache_mode = True if opts.pkg_cache_mode == "sync" else False - destpath, status = pkgcache.add_variant( - variant, force=opts.force, - wait_for_copying=cache_mode - ) - # If no mode is specified, use the default behavior. + if opts.pkg_cache_mode == "async": + cache_mode = True + elif opts.pkg_cache_mode == "sync": + cache_mode = False else: - destpath, status = pkgcache.add_variant(variant, force=opts.force) + cache_mode = not config.package_cache_async + + destpath, status = pkgcache.add_variant( + variant, force=opts.force, + wait_for_copying=cache_mode + ) if status == PackageCache.VARIANT_FOUND: print_info("Already exists: %s", destpath) From 9a67b49e338ecb5d5ec435232fa638682066bac8 Mon Sep 17 00:00:00 2001 From: Jose Enriquez <1145623+Pixel-Minions@users.noreply.github.com> Date: Tue, 15 Oct 2024 18:39:22 -0400 Subject: [PATCH 3/5] Update src/rez/cli/pkg-cache.py Signed-off-by: Jose Enriquez Co-authored-by: Jean-Christophe Morin <38703886+JeanChristopheMorinPerso@users.noreply.github.com> Signed-off-by: Jose Enriquez <1145623+Pixel-Minions@users.noreply.github.com> --- src/rez/cli/pkg-cache.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rez/cli/pkg-cache.py b/src/rez/cli/pkg-cache.py index d1613cd98..7e7e9c034 100644 --- a/src/rez/cli/pkg-cache.py +++ b/src/rez/cli/pkg-cache.py @@ -79,9 +79,9 @@ def add_variant(pkgcache, uri, opts): sys.exit(1) if opts.pkg_cache_mode == "async": - cache_mode = True - elif opts.pkg_cache_mode == "sync": cache_mode = False + elif opts.pkg_cache_mode == "sync": + cache_mode = True else: cache_mode = not config.package_cache_async From d1d8636981641325bb9cd0c4e808208bd8415770 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Morin Date: Sat, 19 Oct 2024 10:11:24 -0400 Subject: [PATCH 4/5] Rename variable for readability Signed-off-by: Jean-Christophe Morin --- src/rez/cli/pkg-cache.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/rez/cli/pkg-cache.py b/src/rez/cli/pkg-cache.py index 7e7e9c034..75cb9a73e 100644 --- a/src/rez/cli/pkg-cache.py +++ b/src/rez/cli/pkg-cache.py @@ -79,15 +79,15 @@ def add_variant(pkgcache, uri, opts): sys.exit(1) if opts.pkg_cache_mode == "async": - cache_mode = False + sync = False elif opts.pkg_cache_mode == "sync": - cache_mode = True + sync = True else: - cache_mode = not config.package_cache_async + sync = not config.package_cache_async destpath, status = pkgcache.add_variant( variant, force=opts.force, - wait_for_copying=cache_mode + wait_for_copying=sync ) if status == PackageCache.VARIANT_FOUND: From 8fcefd354dc9aa4b83449e674713f5adeaa1f073 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Morin Date: Sat, 19 Oct 2024 10:11:30 -0400 Subject: [PATCH 5/5] Add missing import Signed-off-by: Jean-Christophe Morin --- src/rez/cli/pkg-cache.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/rez/cli/pkg-cache.py b/src/rez/cli/pkg-cache.py index 75cb9a73e..c35f27ecc 100644 --- a/src/rez/cli/pkg-cache.py +++ b/src/rez/cli/pkg-cache.py @@ -67,6 +67,7 @@ def setup_parser(parser, completions=False): def add_variant(pkgcache, uri, opts): + from rez.config import config from rez.packages import get_variant_from_uri from rez.utils.logging_ import print_info, print_warning from rez.package_cache import PackageCache