pythonnet 3.2.0rc1__cp311.cp312.cp313.cp314.cp315-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- clr.py +6 -0
- pythonnet/__init__.py +168 -0
- pythonnet/_pyinstaller/__init__.py +4 -0
- pythonnet/_pyinstaller/hook-clr.py +9 -0
- pythonnet/runtime/Python.Runtime.deps.json +173 -0
- pythonnet/runtime/Python.Runtime.dll +0 -0
- pythonnet/runtime/Python.Runtime.xml +3850 -0
- pythonnet-3.2.0rc1.dist-info/METADATA +185 -0
- pythonnet-3.2.0rc1.dist-info/RECORD +14 -0
- pythonnet-3.2.0rc1.dist-info/WHEEL +9 -0
- pythonnet-3.2.0rc1.dist-info/entry_points.txt +2 -0
- pythonnet-3.2.0rc1.dist-info/licenses/AUTHORS.md +92 -0
- pythonnet-3.2.0rc1.dist-info/licenses/LICENSE +21 -0
- pythonnet-3.2.0rc1.dist-info/top_level.txt +2 -0
clr.py
ADDED
pythonnet/__init__.py
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
"""Python.NET runtime loading and configuration"""
|
|
2
|
+
|
|
3
|
+
import sys
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import Dict, Optional, Union, Any
|
|
6
|
+
import clr_loader
|
|
7
|
+
|
|
8
|
+
__all__ = ["set_runtime", "set_runtime_from_env", "load", "unload", "get_runtime_info"]
|
|
9
|
+
|
|
10
|
+
_RUNTIME: Optional[clr_loader.Runtime] = None
|
|
11
|
+
_LOADER_ASSEMBLY: Optional[clr_loader.Assembly] = None
|
|
12
|
+
_LOADED: bool = False
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def set_runtime(runtime: Union[clr_loader.Runtime, str], **params: str) -> None:
|
|
16
|
+
"""Set up a clr_loader runtime without loading it
|
|
17
|
+
|
|
18
|
+
:param runtime:
|
|
19
|
+
Either an already initialised `clr_loader` runtime, or one of netfx,
|
|
20
|
+
coreclr, mono, or default. If a string parameter is given, the runtime
|
|
21
|
+
will be created.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
global _RUNTIME
|
|
25
|
+
if _LOADED:
|
|
26
|
+
raise RuntimeError(f"The runtime {_RUNTIME} has already been loaded")
|
|
27
|
+
|
|
28
|
+
if isinstance(runtime, str):
|
|
29
|
+
runtime = _create_runtime_from_spec(runtime, params)
|
|
30
|
+
|
|
31
|
+
_RUNTIME = runtime
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def get_runtime_info() -> Optional[clr_loader.RuntimeInfo]:
|
|
35
|
+
"""Retrieve information on the configured runtime"""
|
|
36
|
+
|
|
37
|
+
if _RUNTIME is None:
|
|
38
|
+
return None
|
|
39
|
+
else:
|
|
40
|
+
return _RUNTIME.info()
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _get_params_from_env(prefix: str) -> Dict[str, str]:
|
|
44
|
+
from os import environ
|
|
45
|
+
|
|
46
|
+
full_prefix = f"PYTHONNET_{prefix.upper()}_"
|
|
47
|
+
len_ = len(full_prefix)
|
|
48
|
+
|
|
49
|
+
env_vars = {
|
|
50
|
+
(k[len_:].lower()): v
|
|
51
|
+
for k, v in environ.items()
|
|
52
|
+
if k.upper().startswith(full_prefix)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return env_vars
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def _create_runtime_from_spec(
|
|
59
|
+
spec: str, params: Optional[Dict[str, Any]] = None
|
|
60
|
+
) -> clr_loader.Runtime:
|
|
61
|
+
was_default = False
|
|
62
|
+
if spec == "default":
|
|
63
|
+
was_default = True
|
|
64
|
+
if sys.platform == "win32":
|
|
65
|
+
spec = "netfx"
|
|
66
|
+
else:
|
|
67
|
+
spec = "mono"
|
|
68
|
+
|
|
69
|
+
params = params or _get_params_from_env(spec)
|
|
70
|
+
|
|
71
|
+
try:
|
|
72
|
+
if spec == "netfx":
|
|
73
|
+
return clr_loader.get_netfx(**params)
|
|
74
|
+
elif spec == "mono":
|
|
75
|
+
return clr_loader.get_mono(**params)
|
|
76
|
+
elif spec == "coreclr":
|
|
77
|
+
return clr_loader.get_coreclr(**params)
|
|
78
|
+
else:
|
|
79
|
+
raise RuntimeError(f"Invalid runtime name: '{spec}'")
|
|
80
|
+
except Exception as exc:
|
|
81
|
+
if was_default:
|
|
82
|
+
raise RuntimeError(
|
|
83
|
+
f"""Failed to create a default .NET runtime, which would
|
|
84
|
+
have been "{spec}" on this system. Either install a
|
|
85
|
+
compatible runtime or configure it explicitly via
|
|
86
|
+
`set_runtime` or the `PYTHONNET_*` environment variables
|
|
87
|
+
(see set_runtime_from_env)."""
|
|
88
|
+
) from exc
|
|
89
|
+
else:
|
|
90
|
+
raise RuntimeError(
|
|
91
|
+
f"""Failed to create a .NET runtime ({spec}) using the
|
|
92
|
+
parameters {params}."""
|
|
93
|
+
) from exc
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def set_runtime_from_env() -> None:
|
|
97
|
+
"""Set up the runtime using the environment
|
|
98
|
+
|
|
99
|
+
This will use the environment variable PYTHONNET_RUNTIME to decide the
|
|
100
|
+
runtime to use, which may be one of netfx, coreclr or mono. The parameters
|
|
101
|
+
of the respective clr_loader.get_<runtime> functions can also be given as
|
|
102
|
+
environment variables, named `PYTHONNET_<RUNTIME>_<PARAM_NAME>`. In
|
|
103
|
+
particular, to use `PYTHONNET_RUNTIME=coreclr`, the variable
|
|
104
|
+
`PYTHONNET_CORECLR_RUNTIME_CONFIG` has to be set to a valid
|
|
105
|
+
`.runtimeconfig.json`.
|
|
106
|
+
|
|
107
|
+
If no environment variable is specified, a globally installed Mono is used
|
|
108
|
+
for all environments but Windows, on Windows the legacy .NET Framework is
|
|
109
|
+
used.
|
|
110
|
+
"""
|
|
111
|
+
from os import environ
|
|
112
|
+
|
|
113
|
+
spec = environ.get("PYTHONNET_RUNTIME", "default")
|
|
114
|
+
runtime = _create_runtime_from_spec(spec)
|
|
115
|
+
set_runtime(runtime)
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def load(runtime: Union[clr_loader.Runtime, str, None] = None, **params: str) -> None:
|
|
119
|
+
"""Load Python.NET in the specified runtime
|
|
120
|
+
|
|
121
|
+
The same parameters as for `set_runtime` can be used. By default,
|
|
122
|
+
`set_default_runtime` is called if no environment has been set yet and no
|
|
123
|
+
parameters are passed.
|
|
124
|
+
|
|
125
|
+
After a successful call, further invocations will return immediately."""
|
|
126
|
+
global _LOADED, _LOADER_ASSEMBLY
|
|
127
|
+
|
|
128
|
+
if _LOADED:
|
|
129
|
+
return
|
|
130
|
+
|
|
131
|
+
if _RUNTIME is None:
|
|
132
|
+
if runtime is None:
|
|
133
|
+
set_runtime_from_env()
|
|
134
|
+
else:
|
|
135
|
+
set_runtime(runtime, **params)
|
|
136
|
+
|
|
137
|
+
if _RUNTIME is None:
|
|
138
|
+
raise RuntimeError("No valid runtime selected")
|
|
139
|
+
|
|
140
|
+
dll_path = Path(__file__).parent / "runtime" / "Python.Runtime.dll"
|
|
141
|
+
|
|
142
|
+
_LOADER_ASSEMBLY = assembly = _RUNTIME.get_assembly(str(dll_path))
|
|
143
|
+
func = assembly.get_function("Python.Runtime.Loader.Initialize")
|
|
144
|
+
|
|
145
|
+
if func(b"") != 0:
|
|
146
|
+
raise RuntimeError("Failed to initialize Python.Runtime.dll")
|
|
147
|
+
|
|
148
|
+
_LOADED = True
|
|
149
|
+
|
|
150
|
+
import atexit
|
|
151
|
+
|
|
152
|
+
atexit.register(unload)
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def unload() -> None:
|
|
156
|
+
"""Explicitly unload a loaded runtime and shut down Python.NET"""
|
|
157
|
+
|
|
158
|
+
global _RUNTIME, _LOADER_ASSEMBLY
|
|
159
|
+
if _LOADER_ASSEMBLY is not None:
|
|
160
|
+
func = _LOADER_ASSEMBLY.get_function("Python.Runtime.Loader.Shutdown")
|
|
161
|
+
if func(b"full_shutdown") != 0:
|
|
162
|
+
raise RuntimeError("Failed to call Python.NET shutdown")
|
|
163
|
+
|
|
164
|
+
_LOADER_ASSEMBLY = None
|
|
165
|
+
|
|
166
|
+
if _RUNTIME is not None:
|
|
167
|
+
_RUNTIME.shutdown()
|
|
168
|
+
_RUNTIME = None
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
from PyInstaller.utils.hooks import collect_data_files, collect_dynamic_libs
|
|
2
|
+
|
|
3
|
+
try:
|
|
4
|
+
binaries = collect_dynamic_libs("pythonnet")
|
|
5
|
+
datas = collect_data_files("pythonnet")
|
|
6
|
+
except Exception:
|
|
7
|
+
# name conflict with https://pypi.org/project/clr/, do not crash if just clr is present
|
|
8
|
+
binaries = []
|
|
9
|
+
datas = []
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
{
|
|
2
|
+
"runtimeTarget": {
|
|
3
|
+
"name": ".NETStandard,Version=v2.0/",
|
|
4
|
+
"signature": ""
|
|
5
|
+
},
|
|
6
|
+
"compilationOptions": {},
|
|
7
|
+
"targets": {
|
|
8
|
+
".NETStandard,Version=v2.0": {},
|
|
9
|
+
".NETStandard,Version=v2.0/": {
|
|
10
|
+
"Python.Runtime/3.2.0-rc1": {
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"Microsoft.CSharp": "4.7.0",
|
|
13
|
+
"Microsoft.SourceLink.GitHub": "10.0.401",
|
|
14
|
+
"System.Reflection.Emit": "4.7.0"
|
|
15
|
+
},
|
|
16
|
+
"runtime": {
|
|
17
|
+
"Python.Runtime.dll": {}
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"Microsoft.CSharp/4.7.0": {
|
|
21
|
+
"runtime": {
|
|
22
|
+
"lib/netstandard2.0/Microsoft.CSharp.dll": {
|
|
23
|
+
"assemblyVersion": "4.0.5.0",
|
|
24
|
+
"fileVersion": "4.700.19.56404"
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"Microsoft.SourceLink.GitHub/10.0.401": {
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"System.IO.Hashing": "10.0.12"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"System.Buffers/4.6.1": {
|
|
34
|
+
"runtime": {
|
|
35
|
+
"lib/netstandard2.0/System.Buffers.dll": {
|
|
36
|
+
"assemblyVersion": "4.0.2.0",
|
|
37
|
+
"fileVersion": "4.600.125.16908"
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"System.IO.Hashing/10.0.12": {
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"System.Buffers": "4.6.1",
|
|
44
|
+
"System.Memory": "4.6.3"
|
|
45
|
+
},
|
|
46
|
+
"runtime": {
|
|
47
|
+
"lib/netstandard2.0/System.IO.Hashing.dll": {
|
|
48
|
+
"assemblyVersion": "10.0.0.12",
|
|
49
|
+
"fileVersion": "10.0.1226.42308"
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
"System.Memory/4.6.3": {
|
|
54
|
+
"dependencies": {
|
|
55
|
+
"System.Buffers": "4.6.1",
|
|
56
|
+
"System.Numerics.Vectors": "4.6.1",
|
|
57
|
+
"System.Runtime.CompilerServices.Unsafe": "6.1.2"
|
|
58
|
+
},
|
|
59
|
+
"runtime": {
|
|
60
|
+
"lib/netstandard2.0/System.Memory.dll": {
|
|
61
|
+
"assemblyVersion": "4.0.2.0",
|
|
62
|
+
"fileVersion": "4.600.325.20307"
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
"System.Numerics.Vectors/4.6.1": {
|
|
67
|
+
"runtime": {
|
|
68
|
+
"lib/netstandard2.0/System.Numerics.Vectors.dll": {
|
|
69
|
+
"assemblyVersion": "4.1.3.0",
|
|
70
|
+
"fileVersion": "4.600.125.16908"
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
"System.Reflection.Emit/4.7.0": {
|
|
75
|
+
"dependencies": {
|
|
76
|
+
"System.Reflection.Emit.ILGeneration": "4.7.0"
|
|
77
|
+
},
|
|
78
|
+
"runtime": {
|
|
79
|
+
"lib/netstandard2.0/System.Reflection.Emit.dll": {
|
|
80
|
+
"assemblyVersion": "4.0.0.0",
|
|
81
|
+
"fileVersion": "4.700.19.56404"
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
"System.Reflection.Emit.ILGeneration/4.7.0": {
|
|
86
|
+
"runtime": {
|
|
87
|
+
"lib/netstandard2.0/System.Reflection.Emit.ILGeneration.dll": {
|
|
88
|
+
"assemblyVersion": "4.0.0.0",
|
|
89
|
+
"fileVersion": "4.700.19.56404"
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
"System.Runtime.CompilerServices.Unsafe/6.1.2": {
|
|
94
|
+
"runtime": {
|
|
95
|
+
"lib/netstandard2.0/System.Runtime.CompilerServices.Unsafe.dll": {
|
|
96
|
+
"assemblyVersion": "6.0.0.0",
|
|
97
|
+
"fileVersion": "6.100.225.20307"
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
"libraries": {
|
|
104
|
+
"Python.Runtime/3.2.0-rc1": {
|
|
105
|
+
"type": "project",
|
|
106
|
+
"serviceable": false,
|
|
107
|
+
"sha512": ""
|
|
108
|
+
},
|
|
109
|
+
"Microsoft.CSharp/4.7.0": {
|
|
110
|
+
"type": "package",
|
|
111
|
+
"serviceable": true,
|
|
112
|
+
"sha512": "sha512-pTj+D3uJWyN3My70i2Hqo+OXixq3Os2D1nJ2x92FFo6sk8fYS1m1WLNTs0Dc1uPaViH0YvEEwvzddQ7y4rhXmA==",
|
|
113
|
+
"path": "microsoft.csharp/4.7.0",
|
|
114
|
+
"hashPath": "microsoft.csharp.4.7.0.nupkg.sha512"
|
|
115
|
+
},
|
|
116
|
+
"Microsoft.SourceLink.GitHub/10.0.401": {
|
|
117
|
+
"type": "package",
|
|
118
|
+
"serviceable": true,
|
|
119
|
+
"sha512": "sha512-LGmlwgP1Cx37JEWzyjS0o1/+xs/s/e3E2TBSuogI5ePA/9L0pfIfeYX0k5in7Bfcw8Nn2y2sG9jXxydTjiR2Fg==",
|
|
120
|
+
"path": "microsoft.sourcelink.github/10.0.401",
|
|
121
|
+
"hashPath": "microsoft.sourcelink.github.10.0.401.nupkg.sha512"
|
|
122
|
+
},
|
|
123
|
+
"System.Buffers/4.6.1": {
|
|
124
|
+
"type": "package",
|
|
125
|
+
"serviceable": true,
|
|
126
|
+
"sha512": "sha512-N8GXpmiLMtljq7gwvyS+1QvKT/W2J8sNAvx+HVg4NGmsG/H+2k/y9QI23auLJRterrzCiDH+IWAw4V/GPwsMlw==",
|
|
127
|
+
"path": "system.buffers/4.6.1",
|
|
128
|
+
"hashPath": "system.buffers.4.6.1.nupkg.sha512"
|
|
129
|
+
},
|
|
130
|
+
"System.IO.Hashing/10.0.12": {
|
|
131
|
+
"type": "package",
|
|
132
|
+
"serviceable": true,
|
|
133
|
+
"sha512": "sha512-jDix4bBMYnpZdSPcnY+KDV6ik3SRMzpMKby/bZl/XUwIiflwRNAFZ0oOl61R/pSaveIJ8t1gs2BUlrGsPs/bcg==",
|
|
134
|
+
"path": "system.io.hashing/10.0.12",
|
|
135
|
+
"hashPath": "system.io.hashing.10.0.12.nupkg.sha512"
|
|
136
|
+
},
|
|
137
|
+
"System.Memory/4.6.3": {
|
|
138
|
+
"type": "package",
|
|
139
|
+
"serviceable": true,
|
|
140
|
+
"sha512": "sha512-qdcDOgnFZY40+Q9876JUHnlHu7bosOHX8XISRoH94fwk6hgaeQGSgfZd8srWRZNt5bV9ZW2TljcegDNxsf+96A==",
|
|
141
|
+
"path": "system.memory/4.6.3",
|
|
142
|
+
"hashPath": "system.memory.4.6.3.nupkg.sha512"
|
|
143
|
+
},
|
|
144
|
+
"System.Numerics.Vectors/4.6.1": {
|
|
145
|
+
"type": "package",
|
|
146
|
+
"serviceable": true,
|
|
147
|
+
"sha512": "sha512-sQxefTnhagrhoq2ReR0D/6K0zJcr9Hrd6kikeXsA1I8kOCboTavcUC4r7TSfpKFeE163uMuxZcyfO1mGO3EN8Q==",
|
|
148
|
+
"path": "system.numerics.vectors/4.6.1",
|
|
149
|
+
"hashPath": "system.numerics.vectors.4.6.1.nupkg.sha512"
|
|
150
|
+
},
|
|
151
|
+
"System.Reflection.Emit/4.7.0": {
|
|
152
|
+
"type": "package",
|
|
153
|
+
"serviceable": true,
|
|
154
|
+
"sha512": "sha512-VR4kk8XLKebQ4MZuKuIni/7oh+QGFmZW3qORd1GvBq/8026OpW501SzT/oypwiQl4TvT8ErnReh/NzY9u+C6wQ==",
|
|
155
|
+
"path": "system.reflection.emit/4.7.0",
|
|
156
|
+
"hashPath": "system.reflection.emit.4.7.0.nupkg.sha512"
|
|
157
|
+
},
|
|
158
|
+
"System.Reflection.Emit.ILGeneration/4.7.0": {
|
|
159
|
+
"type": "package",
|
|
160
|
+
"serviceable": true,
|
|
161
|
+
"sha512": "sha512-AucBYo3DSI0IDxdUjKksBcQJXPHyoPyrCXYURW1WDsLI4M65Ar/goSHjdnHOAY9MiYDNKqDlIgaYm+zL2hA1KA==",
|
|
162
|
+
"path": "system.reflection.emit.ilgeneration/4.7.0",
|
|
163
|
+
"hashPath": "system.reflection.emit.ilgeneration.4.7.0.nupkg.sha512"
|
|
164
|
+
},
|
|
165
|
+
"System.Runtime.CompilerServices.Unsafe/6.1.2": {
|
|
166
|
+
"type": "package",
|
|
167
|
+
"serviceable": true,
|
|
168
|
+
"sha512": "sha512-2hBr6zdbIBTDE3EhK7NSVNdX58uTK6iHW/P/Axmm9sl1xoGSLqDvMtpecn226TNwHByFokYwJmt/aQQNlO5CRw==",
|
|
169
|
+
"path": "system.runtime.compilerservices.unsafe/6.1.2",
|
|
170
|
+
"hashPath": "system.runtime.compilerservices.unsafe.6.1.2.nupkg.sha512"
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
Binary file
|