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

Commitdb52dde

Browse files
committed
Improve error message if the runtime fails to load
1 parent3f12469 commitdb52dde

File tree

1 file changed

+28
-11
lines changed

1 file changed

+28
-11
lines changed

‎pythonnet/__init__.py

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ def set_runtime(runtime: Union[clr_loader.Runtime, str], **params: str) -> None:
2828

2929

3030
defget_runtime_info()->Optional[clr_loader.RuntimeInfo]:
31+
"""Retrieve information on the configured runtime"""
32+
3133
if_RUNTIMEisNone:
3234
returnNone
3335
else:
@@ -52,22 +54,39 @@ def _get_params_from_env(prefix: str) -> Dict[str, str]:
5254
def_create_runtime_from_spec(
5355
spec:str,params:Optional[Dict[str,Any]]=None
5456
)->clr_loader.Runtime:
57+
was_default=False
5558
ifspec=="default":
59+
was_default=True
5660
ifsys.platform=="win32":
5761
spec="netfx"
5862
else:
5963
spec="mono"
6064

6165
params=paramsor_get_params_from_env(spec)
6266

63-
ifspec=="netfx":
64-
returnclr_loader.get_netfx(**params)
65-
elifspec=="mono":
66-
returnclr_loader.get_mono(**params)
67-
elifspec=="coreclr":
68-
returnclr_loader.get_coreclr(**params)
69-
else:
70-
raiseRuntimeError(f"Invalid runtime name: '{spec}'")
67+
try:
68+
ifspec=="netfx":
69+
returnclr_loader.get_netfx(**params)
70+
elifspec=="mono":
71+
returnclr_loader.get_mono(**params)
72+
elifspec=="coreclr":
73+
returnclr_loader.get_coreclr(**params)
74+
else:
75+
raiseRuntimeError(f"Invalid runtime name: '{spec}'")
76+
exceptExceptionasexc:
77+
ifwas_default:
78+
raiseRuntimeError(
79+
f"""Failed to create a default .NET runtime, which would
80+
have been "{spec}" on this system. Either install a
81+
compatible runtime or configure it explicitly via
82+
`set_runtime` or the `PYTHONNET_*` environment variables
83+
(see set_runtime_from_env)."""
84+
)fromexc
85+
else:
86+
raiseRuntimeError(
87+
f"""Failed to create a .NET runtime ({spec}) using the
88+
parameters{params}."""
89+
)fromexc
7190

7291

7392
defset_runtime_from_env()->None:
@@ -92,9 +111,7 @@ def set_runtime_from_env() -> None:
92111
set_runtime(runtime)
93112

94113

95-
defload(
96-
runtime:Union[clr_loader.Runtime,str,None]=None,**params:str
97-
)->None:
114+
defload(runtime:Union[clr_loader.Runtime,str,None]=None,**params:str)->None:
98115
"""Load Python.NET in the specified runtime
99116
100117
The same parameters as for `set_runtime` can be used. By default,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp