8000 Bump clr-loader dependency to 0.2.3 and adjust interface · spsforks/pythonnet-pythonnet@3f12469 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3f12469

Browse files
committed
Bump clr-loader dependency to 0.2.3 and adjust interface
- Supports loading without explicitly specifying the runtime config now - Exposes information on the loaded runtime
1 parent bdf671e commit 3f12469

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ license = {text = "MIT"}
1010
readme = "README.rst"
1111

1212
dependencies = [
13-
"clr_loader>=0.1.7"
13+
"clr_loader>=0.2.2,<0.3.0"
1414
]
1515

1616
classifiers = [

pythonnet/__init__.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import sys
22
from pathlib import Path
3-
from typing import Dict, Optional, Union
3+
from typing import Dict, Optional, Union, Any
44
import clr_loader
55

66
__all__ = ["set_runtime", "set_runtime_from_env", "load"]
77

88
_RUNTIME: Optional[clr_loader.Runtime] = None
9-
_LOADER_ASSEMBLY: Optional[clr_loader.wrappers.Assembly] = None
9+
_LOADER_ASSEMBLY: Optional[clr_loader.Assembly] = None
1010
_LOADED: bool = False
1111

1212

@@ -27,6 +27,13 @@ def set_runtime(runtime: Union[clr_loader.Runtime, str], **params: str) -> None:
2727
_RUNTIME = runtime
2828

2929

30+
def get_runtime_info() -> Optional[clr_loader.RuntimeInfo]:
31+
if _RUNTIME is None:
32+
return None
33+
else:
34+
return _RUNTIME.info()
35+
36+
3037
def _get_params_from_env(prefix: str) -> Dict[str, str]:
3138
from os import environ
3239

@@ -43,7 +50,7 @@ def _get_params_from_env(prefix: str) -> Dict[str, str]:
4350

4451

4552
def _create_runtime_from_spec(
46-
spec: str, params: Optional[Dict[str, str]] = None
53+
spec: str, params: Optional[Dict[str, Any]] = None
4754
) -> clr_loader.Runtime:
4855
if spec == "default":
4956
if sys.platform == "win32":
@@ -109,9 +116,9 @@ def load(
109116

110117
dll_path = Path(__file__).parent / "runtime" / "Python.Runtime.dll"
111118

112-
_LOADER_ASSEMBLY = _RUNTIME.get_assembly(str(dll_path))
119+
_LOADER_ASSEMBLY = assembly = _RUNTIME.get_assembly(str(dll_path))
120+
func = assembly.get_function("Python.Runtime.Loader.Initialize")
113121

114-
func = _LOADER_ASSEMBLY["Python.Runtime.Loader.Initialize"]
115122
if func(b"") != 0:
116123
raise RuntimeError("Failed to initialize Python.Runtime.dll")
117124

@@ -125,12 +132,12 @@ def unload() -> None:
125132

126133
global _RUNTIME, _LOADER_ASSEMBLY
127134
if _LOADER_ASSEMBLY is not None:
128-
func = _LOADER_ASSEMBLY["Python.Runtime.Loader.Shutdown"]
135+
func = _LOADER_ASSEMBLY.get_function("Python.Runtime.Loader.Shutdown")
129136
if func(b"full_shutdown") != 0:
130137
raise RuntimeError("Failed to call Python.NET shutdown")
131138

132139
_LOADER_ASSEMBLY = None
133140

134141
if _RUNTIME is not None:
135-
# TODO: Add explicit `close` to clr_loader
142+
_RUNTIME.shutdown()
136143
_RUNTIME = None

tests/conftest.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,12 @@ def pytest_configure(config):
5353
runtime_params = {}
5454

5555
if runtime_opt == "coreclr":
56-
fw = "net6.0"
57-
runtime_params["runtime_config"] = str(
58-
bin_path / "Python.Test.runtimeconfig.json"
59-
)
56+
# This is optional now:
57+
#
58+
# fw = "net6.0"
59+
# runtime_params["runtime_config"] = str(
60+
# bin_path / "Python.Test.runtimeconfig.json"
61+
# )
6062
collect_ignore.append("domain_tests/test_domain_reload.py")
6163
else:
6264
domain_tests_dir = cwd / "domain_tests"

0 commit comments

Comments
 (0)
0