| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -28,6 +28,8 @@ def set_runtime(runtime: Union[clr_loader.Runtime, str], **params: str) -> None: | |||
| 28 | 28 | ||
| 29 | 29 | ||
| 30 | 30 | def get_runtime_info() -> Optional[clr_loader.RuntimeInfo]: | |
| 31 | + """Retrieve information on the configured runtime""" | ||
| 32 | + | ||
| 31 | 33 | if _RUNTIME is None: | |
| 32 | 34 | return None | |
| 33 | 35 | else: | |
@@ -52,22 +54,39 @@ def _get_params_from_env(prefix: str) -> Dict[str, str]: | |||
| 52 | 54 | def _create_runtime_from_spec( | |
| 53 | 55 | spec: str, params: Optional[Dict[str, Any]] = None | |
| 54 | 56 | ) -> clr_loader.Runtime: | |
| 57 | + was_default = False | ||
| 55 | 58 | if spec == "default": | |
| 59 | + was_default = True | ||
| 56 | 60 | if sys.platform == "win32": | |
| 57 | 61 | spec = "netfx" | |
| 58 | 62 | else: | |
| 59 | 63 | spec = "mono" | |
| 60 | 64 | ||
| 61 | 65 | params = params or _get_params_from_env(spec) | |
| 62 | 66 | ||
| 63 | - if spec == "netfx": | ||
| 64 | - return clr_loader.get_netfx(**params) | ||
| 65 | - elif spec == "mono": | ||
| 66 | - return clr_loader.get_mono(**params) | ||
| 67 | - elif spec == "coreclr": | ||
| 68 | - return clr_loader.get_coreclr(**params) | ||
| 69 | - else: | ||
| 70 | - raise RuntimeError(f"Invalid runtime name: '{spec}'") | ||
| 67 | + try: | ||
| 68 | + if spec == "netfx": | ||
| 69 | + return clr_loader.get_netfx(**params) | ||
| 70 | + elif spec == "mono": | ||
| 71 | + return clr_loader.get_mono(**params) | ||
| 72 | + elif spec == "coreclr": | ||
| 73 | + return clr_loader.get_coreclr(**params) | ||
| 74 | + else: | ||
| 75 | + raise RuntimeError(f"Invalid runtime name: '{spec}'") | ||
| 76 | + except Exception as exc: | ||
| 77 | + if was_default: | ||
| 78 | + raise RuntimeError( | ||
| 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 | + ) from exc | ||
| 85 | + else: | ||
| 86 | + raise RuntimeError( | ||
| 87 | + f"""Failed to create a .NET runtime ({spec}) using the | ||
| 88 | + parameters {params}.""" | ||
| 89 | + ) from exc | ||
| 71 | 90 | ||
| 72 | 91 | ||
| 73 | 92 | def set_runtime_from_env() -> None: | |
@@ -92,9 +111,7 @@ def set_runtime_from_env() -> None: | |||
| 92 | 111 | set_runtime(runtime) | |
| 93 | 112 | ||
| 94 | 113 | ||
| 95 | - def load( | ||
| 96 | - runtime: Union[clr_loader.Runtime, str, None] = None, **params: str | ||
| 97 | - ) -> None: | ||
| 114 | + def load(runtime: Union[clr_loader.Runtime, str, None] = None, **params: str) -> None: | ||
| 98 | 115 | """Load Python.NET in the specified runtime | |
| 99 | 116 | ||
| 100 | 117 | The same parameters as for `set_runtime` can be used. By default, | |
| Back | FazBrowse Home | New Git URL |
0 commit comments