Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitce3afa6

Browse files
committed
Fix broken prefix and debug leftover
Additionally, fixes a type hint and makes sure that the new defaultbehaviour is to use the environment variable if given.
1 parente241a9d commitce3afa6

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

‎pythonnet/__init__.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
fromtypingimportDict,Optional,Union
44
importclr_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
fromosimportenviron
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
raiseRuntimeError(f"Invalid runtime name: '{spec}'")
6464

6565

66-
defset_default_runtime()->None:
67-
"""Set up thedefaultruntime
66+
defset_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
fromosimportenviron
8282

83-
print("Set default RUNTIME")
84-
raiseRuntimeError("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
defload(
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_RUNTIMEisNone:
105-
set_runtime(runtime,**params)
102+
ifruntimeisNone:
103+
set_runtime_from_env()
104+
else:
105+
set_runtime(runtime,**params)
106106

107107
if_RUNTIMEisNone:
108108
raiseRuntimeError("No valid runtime selected")

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp