11import sys
22from pathlib import Path
3- from typing import Dict , Optional , Union
3+ from typing import Dict , Optional , Union , Any
44import clr_loader
55
66__all__ = ["set_runtime" , "set_runtime_from_env" , "load" ]
77
88_RUNTIME : Optional [clr_loader .Runtime ] = None
9- _LOADER_ASSEMBLY : Optional [clr_loader .wrappers . Assembly ] = None
9+ _LOADER_ASSEMBLY : Optional [clr_loader .Assembly ] = None
1010_LOADED : bool = False
1111
1212
@@ -27,6 +27,13 @@ def set_runtime(runtime: Union[clr_loader.Runtime, str], **params: str) -> None:
2727 _RUNTIME = runtime
2828
2929
30+ def get_runtime_info () -> Optional [clr_loader .RuntimeInfo ]:
31+ if _RUNTIME is None :
32+ return None
33+ else :
34+ return _RUNTIME .info ()
35+
36+
3037def _get_params_from_env (prefix : str ) -> Dict [str , str ]:
3138 from os import environ
3239
@@ -43,7 +50,7 @@ def _get_params_from_env(prefix: str) -> Dict[str, str]:
4350
4451
4552def _create_runtime_from_spec (
46- spec : str , params : Optional [Dict [str , str ]] = None
53+ spec : str , params : Optional [Dict [str , Any ]] = None
4754) -> clr_loader .Runtime :
4855 if spec == "default" :
4956 if sys .platform == "win32" :
@@ -109,9 +116,9 @@ def load(
109116
110117 dll_path = Path (__file__ ).parent / "runtime" / "Python.Runtime.dll"
111118
112- _LOADER_ASSEMBLY = _RUNTIME .get_assembly (str (dll_path ))
119+ _LOADER_ASSEMBLY = assembly = _RUNTIME .get_assembly (str (dll_path ))
120+ func = assembly .get_function ("Python.Runtime.Loader.Initialize" )
113121
114- func = _LOADER_ASSEMBLY ["Python.Runtime.Loader.Initialize" ]
115122 if func (b"" ) != 0 :
116123 raise RuntimeError ("Failed to initialize Python.Runtime.dll" )
117124
@@ -125,12 +132,12 @@ def unload() -> None:
125132
126133 global _RUNTIME , _LOADER_ASSEMBLY
127134 if _LOADER_ASSEMBLY is not None :
128- func = _LOADER_ASSEMBLY [ "Python.Runtime.Loader.Shutdown" ]
135+ func = _LOADER_ASSEMBLY . get_function ( "Python.Runtime.Loader.Shutdown" )
129136 if func (b"full_shutdown" ) != 0 :
130137 raise RuntimeError ("Failed to call Python.NET shutdown" )
131138
132139 _LOADER_ASSEMBLY = None
133140
134141 if _RUNTIME is not None :
135- # TODO: Add explicit `close` to clr_loader
142+ _RUNTIME . shutdown ()
136143 _RUNTIME = None
0 commit comments