- Notifications
You must be signed in to change notification settings - Fork750
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
9 commits Select commitHold shift + click to select a range
b92d929
Replace clr module by loading through clr_loader
filmorfdb7144
Add Changelog entry
filmorf01a78c
Fix domain reload tests and activate them on macOS
filmor0d7e43a
Run tests on .NET Core
filmor67032ea
Vendor System.Drawing.Point for testing on .NET Core
filmor8bc458b
Use approximate comparison for single max/min value comparison
filmord46fa1e
Adjust the import tests to use only commonly available deps
filmorf0011a5
Fix PythonTestRunner to work with new pytest setup
filmorc1a01b7
Drop references to the obsolete call
filmorFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
65 changes: 22 additions & 43 deletions.github/workflows/main.yml
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
3 changes: 0 additions & 3 deletions.gitignore
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,8 +1,5 @@ | ||
/src/runtime/interopNative.cs | ||
# General binaries and Build results | ||
*.dll | ||
*.exe | ||
2 changes: 2 additions & 0 deletionsCHANGELOG.md
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
1 change: 0 additions & 1 deletionDirectory.Build.props
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
3 changes: 1 addition & 2 deletionsappveyor.yml
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
39 changes: 2 additions & 37 deletionsclr.py
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 |
---|---|---|
@@ -2,40 +2,5 @@ | ||
Legacy Python.NET loader for backwards compatibility | ||
""" | ||
from pythonnet import load | ||
load() |
6 changes: 6 additions & 0 deletionspyproject.toml
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", | ||
] |
3 changes: 0 additions & 3 deletionspythonnet.sln
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
74 changes: 71 additions & 3 deletionspythonnet/__init__.py
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 @@ | ||
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 | ||
filmor marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
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.
Uh oh!
There was an error while loading.Please reload this page.
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.