Fix entry point resource dirs

This commit is contained in:
object-Object 2023-09-07 22:21:20 -04:00
parent 169b223c9d
commit 231fb30999

View file

@ -262,28 +262,32 @@ class PathResourceDir(BaseResourceDir):
return value return value
class EntryPointResourceDir(BaseResourceDir): class PluginResourceDir(BaseResourceDir):
modid: str modid: str
# entry points are probably from other mods/packages # if we're specifying a modid, it's probably from some other mod/package
external: bool = True external: bool = True
reexport: bool = False reexport: bool = False
@contextmanager @contextmanager
def load(self, pm: PluginManager): def load(self, pm: PluginManager):
with ExitStack() as stack, init_context(RelativePathContext(root=Path())): context = RelativePathContext(root=Path())
# NOT "yield from" with ExitStack() as stack, init_context(context):
yield [ yield list(self._load_all(pm, stack)) # NOT "yield from"
PathResourceDir(
path=stack.enter_context(resources.as_file(module)), def _load_all(self, pm: PluginManager, stack: ExitStack):
external=self.external, for module in pm.load_resources(self.modid):
reexport=self.reexport, traversable = resources.files(module)
).set_modid(self.modid) path = stack.enter_context(resources.as_file(traversable))
for module in pm.load_resources(self.modid)
] yield PathResourceDir(
path=path,
external=self.external,
reexport=self.reexport,
).set_modid(self.modid)
ResourceDir = PathResourceDir | EntryPointResourceDir ResourceDir = PathResourceDir | PluginResourceDir
@dataclass_transform() @dataclass_transform()