From 2ae1cf443aa074c4d128258e5f640bdd69713689 Mon Sep 17 00:00:00 2001 From: The etils Authors Date: Fri, 24 Apr 2026 08:25:38 -0700 Subject: [PATCH] Code update PiperOrigin-RevId: 905043560 --- etils/epath/resource_utils.py | 10 ++++++++++ etils/epath/resource_utils_test.py | 16 +++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/etils/epath/resource_utils.py b/etils/epath/resource_utils.py index c82488da..468c23bb 100644 --- a/etils/epath/resource_utils.py +++ b/etils/epath/resource_utils.py @@ -64,6 +64,16 @@ def __eq__(self, other) -> bool: def __hash__(self) -> int: return hash((self.root, self.at)) # pytype: disable=attribute-error + def resolve(self, strict: bool = False) -> 'ResourcePath': + """Returns the absolute path.""" + if strict and not self.exists(): + raise FileNotFoundError(f'{self} not found.') + return self + + def absolute(self) -> 'ResourcePath': + """Returns the absolute path.""" + return self.resolve() + if sys.version_info < (3, 10): # Required due to: https://bugs.python.org/issue42043 def _next(self, at) -> 'ResourcePath': # pylint: disable=g-wrong-blank-lines diff --git a/etils/epath/resource_utils_test.py b/etils/epath/resource_utils_test.py index b7dc99bc..76f4f972 100644 --- a/etils/epath/resource_utils_test.py +++ b/etils/epath/resource_utils_test.py @@ -62,5 +62,19 @@ def test_resource_path(): path = epath.Path(path) assert isinstance(path, epath.resource_utils.ResourcePath) - assert path.joinpath() == path assert path.joinpath('abc', 'def.txt').name == 'def.txt' + + +def test_resource_resolve(): + path = epath.g3_path() + # This should not raise AttributeError + resolved = path.resolve() + assert resolved == path + assert resolved.resolve() == resolved + + +def test_resource_path_resolve(): + path = epath.resource_utils.ResourcePath(_make_zip_file()) + # This would have failed before the fix + resolved = path.resolve() + assert resolved == path