@@ -138,7 +138,6 @@ def get(package: Package, resource: Resource) -> trees.Traversable:
138
138
return trees .from_package (package ) / resource
139
139
140
140
141
- @contextmanager
142
141
def path (package : Package , resource : Resource ) -> Iterator [Path ]:
143
142
"""A context manager providing a file path object to the resource.
144
143
@@ -148,17 +147,22 @@ def path(package: Package, resource: Resource) -> Iterator[Path]:
148
147
raised if the file was deleted prior to the context manager
149
148
exiting).
150
149
"""
151
- norm_resource = _normalize_path (resource )
152
150
reader = _get_resource_reader (_get_package (package ))
153
- if reader is not None :
154
- with suppress (FileNotFoundError ):
155
- yield Path (reader .resource_path (norm_resource ))
156
- return
157
- opener_reader = reader .open_resource (norm_resource )
158
- with trees ._tempfile (opener_reader .read ) as res :
159
- yield res
160
- return
161
- with trees .as_file (get (package , resource )) as res :
151
+ return (
152
+ _path_from_reader (reader , resource )
153
+ if reader else
154
+ trees .as_file (get (package , resource ))
155
+ )
156
+
157
+
158
+ @contextmanager
159
+ def _path_from_reader (reader , resource ):
160
+ norm_resource = _normalize_path (resource )
161
+ with suppress (FileNotFoundError ):
162
+ yield Path (reader .resource_path (norm_resource ))
163
+ return
164
+ opener_reader = reader .open_resource (norm_resource )
165
+ with trees ._tempfile (opener_reader .read ) as res :
162
166
yield res
163
167
164
168
0 commit comments