Skip to content

Commit ce3afa6

Browse files
committed
Fix broken prefix and debug leftover
Additionally, fixes a type hint and makes sure that the new default behaviour is to use the environment variable if given.
1 parent e241a9d commit ce3afa6

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

pythonnet/__init__.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from typing import Dict, Optional, Union
44
import 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:
3030
def _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

9188
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
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

Comments
 (0)