33from typing import Dict , Optional , Union
44import clr_loader
55
6- __all__ = ["set_runtime" , "set_default_runtime " , "load" ]
6+ __all__ = ["set_runtime" , "set_runtime_from_env " , "load" ]
77
88_RUNTIME : Optional [clr_loader .Runtime ] = None
99_LOADER_ASSEMBLY : Optional [clr_loader .wrappers .Assembly ] = None
@@ -30,7 +30,7 @@ def set_runtime(runtime: Union[clr_loader.Runtime, str], **params: str) -> None:
3030def _get_params_from_env (prefix : str ) -> Dict [str , str ]:
3131 from os import environ
3232
33- full_prefix = f"PYTHONNET_{ prefix .upper ()} "
33+ full_prefix = f"PYTHONNET_{ prefix .upper ()} _ "
3434 len_ = len (full_prefix )
3535
3636 env_vars = {
@@ -63,8 +63,8 @@ def _create_runtime_from_spec(
6363 raise RuntimeError (f"Invalid runtime name: '{ spec } '" )
6464
6565
66- def set_default_runtime () -> None :
67- """Set up the default runtime
66+ def set_runtime_from_env () -> None :
67+ """Set up the runtime using the environment
6868
6969 This will use the environment variable PYTHONNET_RUNTIME to decide the
7070 runtime to use, which may be one of netfx, coreclr or mono. The parameters
@@ -80,16 +80,13 @@ def set_default_runtime() -> None:
8080 """
8181 from os import environ
8282
83- print ("Set default RUNTIME" )
84- raise RuntimeError ("Shouldn't be called here" )
85-
8683 spec = environ .get ("PYTHONNET_RUNTIME" , "default" )
8784 runtime = _create_runtime_from_spec (spec )
8885 set_runtime (runtime )
8986
9087
9188def load (
92- runtime : Union [clr_loader .Runtime , str ] = "default" , ** params : Dict [ str , str ]
89+ runtime : Union [clr_loader .Runtime , str , None ] = None , ** params : str
9390) -> None :
9491 """Load Python.NET in the specified runtime
9592
@@ -102,7 +99,10 @@ def load(
10299 return
103100
104101 if _RUNTIME is None :
105- set_runtime (runtime , ** params )
102+ if runtime is None :
103+ set_runtime_from_env ()
104+ else :
105+ set_runtime (runtime , ** params )
106106
107107 if _RUNTIME is None :
108108 raise RuntimeError ("No valid runtime selected" )
0 commit comments