Skip to content

Commit

Permalink
fix automatic class on windows based OS
Browse files Browse the repository at this point in the history
  • Loading branch information
BDonnot committed Jul 10, 2024
1 parent 9d023d2 commit f1caa87
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion grid2op/Space/GridObjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -2894,9 +2894,19 @@ def _aux_init_grid_from_cls(cls, gridobj, name_res):
module_nm = f"{env_nm}.{module_nm}"
super_module_nm = super_supermodule

if f"{module_nm}.{name_res}_file" in sys.modules:
cls_res = getattr(sys.modules[f"{module_nm}.{name_res}_file"], name_res)
return cls_res

super_module = importlib.import_module(module_nm, super_module_nm) # env/path/_grid2op_classes/
module_all_classes = importlib.import_module(f"{module_nm}", super_module) # module specific to the tmpdir created
module = importlib.import_module(f"{module_nm}.{name_res}_file", module_all_classes) # module containing the definition of the class
try:
module = importlib.import_module(f".{name_res}_file", package=module_nm) # module containing the definition of the class
except ModuleNotFoundError:
# in case we need to build the cache again if the module is not found the first time
importlib.invalidate_caches()
importlib.reload(super_module)
module = importlib.import_module(f".{name_res}_file", package=module_nm)
cls_res = getattr(module, name_res)
# do not forget to create the cls_dict once and for all
if cls_res._CLS_DICT is None:
Expand Down

0 comments on commit f1caa87

Please sign in to comment.