From 012e6ce6ed5cab7bb5a421334c9d0c8c53b6a19d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20K=C3=B6ster?= Date: Thu, 9 Jul 2026 12:06:10 +0200 Subject: [PATCH 1/4] constrained package non prod install caching failures to async caching MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Manuel Köster --- src/rez/package_cache.py | 15 ++++++++------- src/rez/resolved_context.py | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/rez/package_cache.py b/src/rez/package_cache.py index 0f8335756b..e3024fc8e3 100644 --- a/src/rez/package_cache.py +++ b/src/rez/package_cache.py @@ -501,15 +501,16 @@ def add_variants(self, variants: Iterable[Variant], package_cache_async: bool = """Add the given variants to the package payload cache. """ - # A prod install is necessary because add_variants works by - # starting a rez-pkg-cache proc, and this can only be done reliably in - # a prod install. On non-windows we could fork instead, but there would - # remain no good solution on windows. + # A prod install is necessary for async caching because add_variants + # works by starting a rez-pkg-cache proc, and this can only be done + # reliably in a prod install. On non-windows we could fork instead, but + # there would remain no good solution on windows. # - if not system.is_production_rez_install: + if package_cache_async and not system.is_production_rez_install: raise PackageCacheError( - "PackageCache.add_variants is only supported in a " - "production rez installation." + "Asynchronous package caching is only supported in a " + "production rez installation. Use synchronous caching " + "(package_cache_async = False) in non-production installs." ) variants_ = [] diff --git a/src/rez/resolved_context.py b/src/rez/resolved_context.py index 3b45ac50d1..1e739b58c7 100644 --- a/src/rez/resolved_context.py +++ b/src/rez/resolved_context.py @@ -1935,7 +1935,7 @@ def _update_package_cache(self) -> None: return # see PackageCache.add_variants - if not system.is_production_rez_install: + if self.package_cache_async and not system.is_production_rez_install: return pkgcache = self._get_package_cache() From cfaec2baa9c5126ea9f1a171fe1774a7f20d8da0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20K=C3=B6ster?= Date: Thu, 9 Jul 2026 12:07:53 +0200 Subject: [PATCH 2/4] added tests for non prod install package caching MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Manuel Köster --- src/rez/tests/test_package_cache.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/rez/tests/test_package_cache.py b/src/rez/tests/test_package_cache.py index eefe69c1c0..db175b96e5 100644 --- a/src/rez/tests/test_package_cache.py +++ b/src/rez/tests/test_package_cache.py @@ -15,6 +15,7 @@ from rez.tests.util import TestBase, TempdirMixin, restore_os_environ, \ install_dependent +from rez.system import system from rez.packages import get_package from rez.package_cache import PackageCache from rez.resolved_context import ResolvedContext @@ -340,3 +341,28 @@ def test_add_variant_skipped_variant_too_large(self): patch.object(pkgcache, 'variant_meets_space_requirements', return_value=False): _, status = pkgcache.add_variant(variant) self.assertEqual(status, PackageCache.VARIANT_SKIPPED) + + def test_add_variants_async_fails_without_prod_install(self): + """async add_variants raises when not a production install.""" + pkgcache = self._pkgcache() + + package = get_package("versioned", "3.0") + variant = next(package.iter_variants()) + + with patch.object(type(system), "is_production_rez_install", False): + with self.assertRaises(PackageCacheError): + pkgcache.add_variants([variant], package_cache_async=True) + + def test_add_variants_sync(self): + """sync add_variants succeeds caching variants when not a production install.""" + pkgcache = self._pkgcache() + + package = get_package("versioned", "3.0") + variant = next(package.iter_variants()) + + with patch.object(type(system), "is_production_rez_install", False): + pkgcache.add_variants([variant], package_cache_async=False) + + cached_root = pkgcache.get_cached_root(variant) + self.assertIsNotNone(cached_root) + self.assertTrue(os.path.isdir(cached_root)) From e94cb6c3779043a41d527e1994261f639b2f15e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20K=C3=B6ster?= Date: Thu, 9 Jul 2026 22:15:33 +0200 Subject: [PATCH 3/4] fix test isolation: clean up cached variant in test_add_variants_sync MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit test_add_variants_sync cached versioned-3.0 but never cleaned up, causing the subsequent test_cache_variant to find it already cached and fail with VARIANT_FOUND instead of VARIANT_CREATED. Signed-off-by: Manuel Köster --- src/rez/tests/test_package_cache.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/rez/tests/test_package_cache.py b/src/rez/tests/test_package_cache.py index db175b96e5..293d46ae38 100644 --- a/src/rez/tests/test_package_cache.py +++ b/src/rez/tests/test_package_cache.py @@ -366,3 +366,5 @@ def test_add_variants_sync(self): cached_root = pkgcache.get_cached_root(variant) self.assertIsNotNone(cached_root) self.assertTrue(os.path.isdir(cached_root)) + + pkgcache.remove_variant(variant) From a0225dba0c9e769d635e6bbe0534e61c37c123d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20K=C3=B6ster?= Date: Fri, 17 Jul 2026 21:26:58 +0200 Subject: [PATCH 4/4] added more tests for non prod install package caching MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Manuel Köster --- src/rez/tests/test_package_cache.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/rez/tests/test_package_cache.py b/src/rez/tests/test_package_cache.py index 293d46ae38..ced6f96c28 100644 --- a/src/rez/tests/test_package_cache.py +++ b/src/rez/tests/test_package_cache.py @@ -368,3 +368,28 @@ def test_add_variants_sync(self): self.assertTrue(os.path.isdir(cached_root)) pkgcache.remove_variant(variant) + + def test_update_package_cache_async_skips_without_prod_install(self): + """_update_package_cache returns early for async caching on non-prod install.""" + c = ResolvedContext(["versioned-3.0"]) + + c.package_caching = True + c.package_cache_async = True + + with patch.object(type(system), "is_production_rez_install", False), \ + patch.object(c, "_get_package_cache") as mock_get_cache: + c._update_package_cache() + mock_get_cache.assert_not_called() + + def test_update_package_cache_sync_proceeds_without_prod_install(self): + """_update_package_cache proceeds for sync caching on non-prod install.""" + pkgcache = self._pkgcache() + c = ResolvedContext(["versioned-3.0"]) + + c.package_caching = True + c.package_cache_async = False + + with patch.object(type(system), "is_production_rez_install", False), \ + patch.object(c, "_get_package_cache", return_value=pkgcache) as mock_get_cache: + c._update_package_cache() + mock_get_cache.assert_called_once()