3
3
from typing import Dict , Optional , Union
4
4
import clr_loader
5
5
6
- __all__ = ["set_runtime" , "set_default_runtime " , "load" ]
6
+ __all__ = ["set_runtime" , "set_runtime_from_env " , "load" ]
7
7
8
8
_RUNTIME : Optional [clr_loader .Runtime ] = None
9
9
_LOADER_ASSEMBLY : Optional [clr_loader .wrappers .Assembly ] = None
@@ -30,7 +30,7 @@ def set_runtime(runtime: Union[clr_loader.Runtime, str], **params: str) -> None:
30
30
def _get_params_from_env (prefix : str ) -> Dict [str , str ]:
31
31
from os import environ
32
32
33
- full_prefix = f"PYTHONNET_{ prefix .upper ()} "
33
+ full_prefix = f"PYTHONNET_{ prefix .upper ()} _ "
34
34
len_ = len (full_prefix )
35
35
36
36
env_vars = {
@@ -63,8 +63,8 @@ def _create_runtime_from_spec(
63
63
raise RuntimeError (f"Invalid runtime name: '{ spec } '" )
64
64
65
65
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
68
68
69
69
This will use the environment variable PYTHONNET_RUNTIME to decide the
70
70
runtime to use, which may be one of netfx, coreclr or mono. The parameters
@@ -80,16 +80,13 @@ def set_default_runtime() -> None:
80
80
"""
81
81
from os import environ
82
82
83
- print ("Set default RUNTIME" )
84
- raise RuntimeError ("Shouldn't be called here" )
85
-
86
83
spec = environ .get ("PYTHONNET_RUNTIME" , "default" )
87
84
runtime = _create_runtime_from_spec (spec )
88
85
set_runtime (runtime )
89
86
90
87
91
88
def load (
92
- runtime : Union [clr_loader .Runtime , str ] = "default" , ** params : Dict [ str , str ]
89
+ runtime : Union [clr_loader .Runtime , str , None ] = None , ** params : str
93
90
) -> None :
94
91
"""Load Python.NET in the specified runtime
95
92
@@ -102,7 +99,10 @@ def load(
102
99
return
103
100
104
101
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 )
106
106
107
107
if _RUNTIME is None :
108
108
raise RuntimeError ("No valid runtime selected" )
0 commit comments