New loading based on clr_loader by filmor · Pull Request #1373 · pythonnet/pythonnet · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 22 additions & 43 deletions .github/workflows/main.yml
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
/src/runtime/interopNative.cs

# Configuration data
configured.props

# General binaries and Build results
*.dll
*.exe
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ when .NET expects an integer [#1342][i1342]
- BREAKING: to call Python from .NET `Runtime.PythonDLL` property must be set to Python DLL name
or the DLL must be loaded in advance. This must be done before calling any other Python.NET functions.
- Sign Runtime DLL with a strong name
- Implement loading through `clr_loader` instead of the included `ClrModule`, enables
support for .NET Core

### Fixed

Expand Down
1 change: 0 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,4 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildThisFileDirectory)configured.props" Condition="Exists('$(MSBuildThisFileDirectory)configured.props')" />
</Project>
3 changes: 1 addition & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ environment:
init:
# Update Environment Variables based on matrix/platform
- set PY_VER=%PYTHON_VERSION:.=%
- set PYTHONNET_PYDLL=python%PY_VER%.dll
- set PYTHON=C:\PYTHON%PY_VER%
- if %PLATFORM%==x64 (set PYTHON=%PYTHON%-x64)
- set PYTHONNET_PYDLL=%PYTHON%\python%PY_VER%.dll

# Put desired Python version first in PATH
- set PATH=%PYTHON%;%PYTHON%\Scripts;%PATH%
Expand All @@ -42,7 +42,6 @@ install:
- pip install --upgrade -r requirements.txt --quiet

build_script:
- python setup.py configure
# Create clean `sdist`. Only used for releases
- python setup.py --quiet sdist
- python setup.py bdist_wheel
Expand Down
39 changes: 2 additions & 37 deletions clr.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,5 @@
Legacy Python.NET loader for backwards compatibility
"""

def _get_netfx_path():
import os, sys

if sys.maxsize > 2 ** 32:
arch = "amd64"
else:
arch = "x86"

return os.path.join(os.path.dirname(__file__), "pythonnet", "netfx", arch, "clr.pyd")


def _get_mono_path():
import os, glob

paths = glob.glob(os.path.join(os.path.dirname(__file__), "pythonnet", "mono", "clr.*so"))
return paths[0]


def _load_clr():
import sys
from importlib import util

if sys.platform == "win32":
path = _get_netfx_path()
else:
path = _get_mono_path()

del sys.modules[__name__]

spec = util.spec_from_file_location("clr", path)
clr = util.module_from_spec(spec)
spec.loader.exec_module(clr)

sys.modules[__name__] = clr


_load_clr()
from pythonnet import load
load()
6 changes: 6 additions & 0 deletions pyproject.toml
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 deletions pythonnet.sln
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Python.Runtime", "src\runti
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Console", "src\console\Console.csproj", "{E6B01706-00BA-4144-9029-186AC42FBE9A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "clrmodule", "src\clrmodule\clrmodule.csproj", "{F9F5FA13-BC52-4C0B-BC1C-FE3C0B8FCCDD}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Python.EmbeddingTest", "src\embed_tests\Python.EmbeddingTest.csproj", "{819E089B-4770-400E-93C6-4F7A35F0EA12}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Python.Test", "src\testing\Python.Test.csproj", "{14EF9518-5BB7-4F83-8686-015BD2CC788E}"
Expand Down Expand Up @@ -55,7 +53,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Python.PythonTestsRunner",
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build", "Build", "{142A6752-C2C2-4F95-B982-193418001B65}"
ProjectSection(SolutionItems) = preProject
configured.props = configured.props
Directory.Build.props = Directory.Build.props
EndProjectSection
EndProject
Expand Down
74 changes: 71 additions & 3 deletions pythonnet/__init__.py
Loading