From 0d1e29cb5324891d0f833dc9ecddeb0d55e134df Mon Sep 17 00:00:00 2001 From: ttrently <41705925+ttrently@users.noreply.github.com> Date: Wed, 22 Feb 2023 15:56:04 -0800 Subject: [PATCH] Add `package_cache_async` flag. Adds a `package_cachy_async` flag which allows users to run caching synchronously (blocking) or asynchronously from the config. Signed-off-by: ttrently <41705925+ttrently@users.noreply.github.com> --- src/rez/config.py | 1 + src/rez/package_cache.py | 10 +++++++--- src/rez/resolved_context.py | 5 ++++- src/rez/rezconfig.py | 3 +++ 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/rez/config.py b/src/rez/config.py index e8542d1ed..c727050a4 100644 --- a/src/rez/config.py +++ b/src/rez/config.py @@ -453,6 +453,7 @@ def _parse_env_var(self, value): "package_cache_during_build": Bool, "package_cache_local": Bool, "package_cache_same_device": Bool, + "package_cache_async": Bool, "color_enabled": ForceOrBool, "resolve_caching": Bool, "cache_package_files": Bool, diff --git a/src/rez/package_cache.py b/src/rez/package_cache.py index e17b2c782..5e9f00e26 100644 --- a/src/rez/package_cache.py +++ b/src/rez/package_cache.py @@ -366,7 +366,7 @@ def remove_variant(self, variant): return self.VARIANT_REMOVED - def add_variants_async(self, variants): + def add_variants_async(self, variants, _async=False): """Update the package cache by adding some or all of the given variants. This method is called when a context is created or sourced. Variants @@ -460,8 +460,12 @@ def add_variants_async(self, variants): else: out_target = devnull - subprocess.Popen( - [exe, "--daemon", self.path], + func = subprocess.Popen + if not _async: + func = subprocess.call + + func( + args, stdout=out_target, stderr=out_target, **kwargs diff --git a/src/rez/resolved_context.py b/src/rez/resolved_context.py index bbf68fef0..0b8589c50 100644 --- a/src/rez/resolved_context.py +++ b/src/rez/resolved_context.py @@ -1844,7 +1844,10 @@ def _update_package_cache(self): pkgcache = self._get_package_cache() if pkgcache: - pkgcache.add_variants_async(self.resolved_packages) + pkgcache.add_variants_async( + self.resolved_packages, + config.package_cache_async + ) @classmethod def _init_context_tracking_payload_base(cls): diff --git a/src/rez/rezconfig.py b/src/rez/rezconfig.py index ca1f14b15..38ea03b27 100644 --- a/src/rez/rezconfig.py +++ b/src/rez/rezconfig.py @@ -278,6 +278,9 @@ # Enable package caching during a package build. package_cache_during_build = False +# Enable package caching to run asynchronously during a resolve. +package_cache_async = True + # Allow caching of local packages. You would only want to set this True for # testing purposes. package_cache_local = False