-
Notifications
You must be signed in to change notification settings - Fork 752
New loading based on clr_loader #1373
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b92d929
Replace clr module by loading through clr_loader
filmor fdb7144
Add Changelog entry
filmor f01a78c
Fix domain reload tests and activate them on macOS
filmor 0d7e43a
Run tests on .NET Core
filmor 67032ea
Vendor System.Drawing.Point for testing on .NET Core
filmor 8bc458b
Use approximate comparison for single max/min value comparison
filmor d46fa1e
Adjust the import tests to use only commonly available deps
filmor f0011a5
Fix PythonTestRunner to work with new pytest setup
filmor c1a01b7
Drop references to the obsolete call
filmor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
[build-system] | ||
requires = ["setuptools>=42", "wheel", "pycparser"] | ||
build-backend = "setuptools.build_meta" | ||
|
||
[tool.pytest.ini_options] | ||
xfail_strict = true | ||
testpaths = [ | ||
"tests", | ||
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,71 @@ | ||
def get_assembly_path(): | ||
import os | ||
return os.path.dirname(__file__) + "/runtime/Python.Runtime.dll" | ||
import os | ||
import sys | ||
import clr_loader | ||
|
||
_RUNTIME = None | ||
_LOADER_ASSEMBLY = None | ||
_FFI = None | ||
_LOADED = False | ||
|
||
|
||
def set_runtime(runtime): | ||
global _RUNTIME | ||
if _LOADED: | ||
raise RuntimeError("The runtime {runtime} has already been loaded".format(_RUNTIME)) | ||
|
||
_RUNTIME = runtime | ||
|
||
|
||
def set_default_runtime() -> None: | ||
if sys.platform == 'win32': | ||
set_runtime(clr_loader.get_netfx()) | ||
else: | ||
set_runtime(clr_loader.get_mono()) | ||
|
||
|
||
def load(): | ||
global _FFI, _LOADED, _LOADER_ASSEMBLY | ||
|
||
if _LOADED: | ||
return | ||
|
||
from .find_libpython import linked_libpython | ||
from os.path import join, dirname | ||
|
||
if _RUNTIME is None: | ||
# TODO: Warn, in the future the runtime must be set explicitly, either | ||
# as a config/env variable or via set_runtime | ||
set_default_runtime() | ||
|
||
dll_path = join(dirname(__file__), "runtime", "Python.Runtime.dll") | ||
libpython = linked_libpython() | ||
|
||
if libpython and _FFI is None and sys.platform != "win32": | ||
# Load and leak libpython handle s.t. the .NET runtime doesn't dlcloses | ||
# it | ||
import posix | ||
|
||
import cffi | ||
_FFI = cffi.FFI() | ||
_FFI.dlopen(libpython, posix.RTLD_NODELETE | posix.RTLD_LOCAL) | ||
|
||
_LOADER_ASSEMBLY = _RUNTIME.get_assembly(dll_path) | ||
|
||
func = _LOADER_ASSEMBLY["Python.Runtime.Loader.Initialize"] | ||
if func(f"{libpython or ''}".encode("utf8")) != 0: | ||
raise RuntimeError("Failed to initialize Python.Runtime.dll") | ||
|
||
import atexit | ||
atexit.register(unload) | ||
|
||
|
||
def unload(): | ||
global _RUNTIME | ||
if _LOADER_ASSEMBLY is not None: | ||
func = _LOADER_ASSEMBLY["Python.Runtime.Loader.Shutdown"] | ||
if func(b"") != 0: | ||
raise RuntimeError("Failed to call Python.NET shutdown") | ||
|
||
if _RUNTIME is not None: | ||
# TODO: Add explicit `close` to clr_loader | ||
_RUNTIME = None |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.