Skip to content

Commit

Permalink
Addressed some feedback
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Andersen <ben@isohedron.com.au>
  • Loading branch information
isohedronpipeline committed Mar 8, 2024
1 parent 5ea2576 commit 2251de8
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
15 changes: 11 additions & 4 deletions src/rez/cli/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ def setup_parser(parser, completions=False):
"--no-pkg-cache", action="store_true",
help="Disable package caching")
parser.add_argument(
"--pkg-cache-sync", action="store_true",
help="Disable asynchronous package caching. "
"Process will block until packages are cached.")
"--pkg-cache-mode", choices=["sync", "async"],
help="Optionally disable for force enable asynchronous package caching. "
"If 'sync', the process will block until packages are cached.")
parser.add_argument(
"--pre-command", type=str, help=SUPPRESS)
PKG_action = parser.add_argument(
Expand Down Expand Up @@ -202,6 +202,13 @@ def command(opts, parser, extra_arg_groups=None):
rule = Rule.parse_rule(rule_str)
package_filter.add_inclusion(rule)

if opts.pkg_cache_sync == "async":
package_cache_async = True
elif opts.pkg_cache_sync == "sync":
package_cache_async = False
else:
package_cache_async = None

# perform the resolve
context = ResolvedContext(
package_requests=request,
Expand All @@ -217,7 +224,7 @@ def command(opts, parser, extra_arg_groups=None):
suppress_passive=opts.no_passive,
print_stats=opts.stats,
package_caching=(not opts.no_pkg_cache),
package_cache_async=(not opts.pkg_cache_sync),
package_cache_async=package_cache_async,
)

success = (context.status == ResolverStatus.solved)
Expand Down
12 changes: 11 additions & 1 deletion src/rez/package_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,16 @@ def remove_variant(self, variant):

return self.VARIANT_REMOVED

def add_variants_async(self, variants):
"""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
are then added to the cache in a separate process.
This method is left for backwards compatibility.
"""
return self.add_variants(variants, package_cache_async=True)

def add_variants(self, variants, package_cache_async=True):
"""Update the package cache by adding some or all of the given variants.
Expand Down Expand Up @@ -467,7 +477,7 @@ def add_variants(self, variants, package_cache_async=True):
**kwargs
)
if not package_cache_async:
process.wait()
process.communicate()

except Exception as e:
print_warning(
Expand Down
1 change: 0 additions & 1 deletion src/rez/resolved_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ def __init__(self, package_requests, verbosity=0, timestamp=None,
package_caching = config.package_cache_during_build
else:
package_caching = True

self.package_caching = package_caching

if package_cache_async is None:
Expand Down
6 changes: 5 additions & 1 deletion src/rez/tests/test_package_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ def test_caching_on_resolve(self):
"pyfoo-3.1.0"
])

# Prove that the resolved context used async mode.
self.assertTrue(c.package_cache_async)

variant = c.get_resolved_package("timestamped")

# Retry 50 times with 0.1 sec interval, 5 secs is more than enough for
Expand All @@ -154,7 +157,8 @@ def test_caching_on_resolve(self):
resolve_not_always_cached = True
time.sleep(0.1)

self.assertNotEqual(cached_root, None)
self.assertNotEqual(cached_root, None,
msg="Packages were expected to be cached, but were not.")

# Test that the package is not immediately cached, since it is asynchronous
# WARNING: This is dangerous since it does open the test to a race condition and
Expand Down

0 comments on commit 2251de8

Please sign in to comment.