| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 4da1954 commit b92d929
28 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -12,33 +12,9 @@ jobs: | |||
| 12 | 12 | fail-fast: false | |
| 13 | 13 | matrix: | |
| 14 | 14 | os: [windows, ubuntu, macos] | |
| 15 | - pyver_minor: [6, 7, 8, 9] | ||
| 15 | + python: ["3.6", "3.7", "3.8", "3.9"] | ||
| 16 | 16 | platform: [x64] | |
| 17 | 17 | shutdown_mode: [Normal, Soft] | |
| 18 | - include: | ||
| 19 | - - os: ubuntu | ||
| 20 | - pyver_minor: 6 | ||
| 21 | - dll_suffix: m | ||
| 22 | - - os: ubuntu | ||
| 23 | - pyver_minor: 7 | ||
| 24 | - dll_suffix: m | ||
| 25 | - | ||
| 26 | - - os: macos | ||
| 27 | - dll_prefix: lib | ||
| 28 | - dll_pyver_major: '3.' | ||
| 29 | - dll_suffix: m | ||
| 30 | - - os: ubuntu | ||
| 31 | - dll_prefix: lib | ||
| 32 | - dll_pyver_major: '3.' | ||
| 33 | - - os: windows | ||
| 34 | - dll_pyver_major: '3' | ||
| 35 | - | ||
| 36 | - - os: ubuntu | ||
| 37 | - dll_ext: .so | ||
| 38 | - - os: windows | ||
| 39 | - dll_ext: .dll | ||
| 40 | - - os: macos | ||
| 41 | - dll_ext: .dylib | ||
| 42 | 18 | ||
| 43 | 19 | env: | |
| 44 | 20 | PYTHONNET_SHUTDOWN_MODE: ${{ matrix.SHUTDOWN_MODE }} | |
@@ -56,10 +32,10 @@ jobs: | |||
| 56 | 32 | - name: Setup .NET | |
| 57 | 33 | uses: actions/setup-dotnet@v1 | |
| 58 | 34 | ||
| 59 | - - name: Set up Python 3.${{ matrix.pyver_minor }} | ||
| 35 | + - name: Set up Python ${{ matrix.python }} | ||
| 60 | 36 | uses: actions/setup-python@v2 | |
| 61 | 37 | with: | |
| 62 | - python-version: 3.${{ matrix.pyver_minor }} | ||
| 38 | + python-version: ${{ matrix.python }} | ||
| 63 | 39 | architecture: ${{ matrix.platform }} | |
| 64 | 40 | ||
| 65 | 41 | - name: Install dependencies | |
@@ -68,31 +44,26 @@ jobs: | |||
| 68 | 44 | ||
| 69 | 45 | - name: Build and Install | |
| 70 | 46 | run: | | |
| 71 | - python setup.py configure | ||
| 72 | 47 | pip install -v . | |
| 73 | 48 | ||
| 74 | - # TODO this should be gone once clr module sets PythonDLL or preloads it | ||
| 75 | - - name: Python Tests | ||
| 76 | - run: pytest | ||
| 77 | - if: ${{ matrix.os != 'macos' }} | ||
| 78 | - env: | ||
| 79 | - PYTHONNET_PYDLL: ${{ matrix.DLL_PREFIX }}python${{matrix.DLL_PYVER_MAJOR}}${{matrix.PYVER_MINOR}}${{matrix.DLL_SUFFIX}}${{matrix.DLL_EXT}} | ||
| 49 | + - name: Set Python DLL path (non Windows) | ||
| 50 | + if: ${{ matrix.os != 'windows' }} | ||
| 51 | + run: | | ||
| 52 | + python -m pythonnet.find_libpython --export >> $GITHUB_ENV | ||
| 80 | 53 | ||
| 54 | + - name: Set Python DLL path (Windows) | ||
| 55 | + if: ${{ matrix.os == 'windows' }} | ||
| 56 | + run: | | ||
| 57 | + python -m pythonnet.find_libpython --export | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append | ||
| 58 | + | ||
| 81 | 59 | - name: Python Tests | |
| 82 | 60 | run: pytest | |
| 83 | - if: ${{ matrix.os == 'macos' }} | ||
| 84 | 61 | ||
| 85 | 62 | - name: Embedding tests | |
| 86 | 63 | run: dotnet test --runtime any-${{ matrix.platform }} src/embed_tests/ | |
| 87 | - if: ${{ matrix.os != 'macos' }} # Not working right now, doesn't find libpython | ||
| 88 | - env: | ||
| 89 | - PYTHONNET_PYDLL: ${{ matrix.DLL_PREFIX }}python${{matrix.DLL_PYVER_MAJOR}}${{matrix.PYVER_MINOR}}${{matrix.DLL_SUFFIX}}${{matrix.DLL_EXT}} | ||
| 90 | 64 | ||
| 91 | 65 | - name: Python tests run from .NET | |
| 92 | 66 | run: dotnet test --runtime any-${{ matrix.platform }} src/python_tests_runner/ | |
| 93 | - if: ${{ matrix.os == 'windows' }} # Not working for others right now | ||
| 94 | - env: | ||
| 95 | - PYTHONNET_PYDLL: ${{ matrix.DLL_PREFIX }}python${{matrix.DLL_PYVER_MAJOR}}${{matrix.PYVER_MINOR}}${{matrix.DLL_SUFFIX}}${{matrix.DLL_EXT}} | ||
| 96 | 67 | ||
| 97 | 68 | # TODO: Run perf tests | |
| 98 | 69 | # TODO: Run mono tests on Windows? | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,8 +1,5 @@ | |||
| 1 | 1 | /src/runtime/interopNative.cs | |
| 2 | 2 | ||
| 3 | - # Configuration data | ||
| 4 | - configured.props | ||
| 5 | - | ||
| 6 | 3 | # General binaries and Build results | |
| 7 | 4 | *.dll | |
| 8 | 5 | *.exe | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,5 +18,4 @@ | |||
| 18 | 18 | <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | |
| 19 | 19 | </PackageReference> | |
| 20 | 20 | </ItemGroup> | |
| 21 | - <Import Project="$(MSBuildThisFileDirectory)configured.props" Condition="Exists('$(MSBuildThisFileDirectory)configured.props')" /> | ||
| 22 | 21 | </Project> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -30,9 +30,9 @@ environment: | |||
| 30 | 30 | init: | |
| 31 | 31 | # Update Environment Variables based on matrix/platform | |
| 32 | 32 | - set PY_VER=%PYTHON_VERSION:.=% | |
| 33 | - - set PYTHONNET_PYDLL=python%PY_VER%.dll | ||
| 34 | 33 | - set PYTHON=C:\PYTHON%PY_VER% | |
| 35 | 34 | - if %PLATFORM%==x64 (set PYTHON=%PYTHON%-x64) | |
| 35 | + - set PYTHONNET_PYDLL=%PYTHON%\python%PY_VER%.dll | ||
| 36 | 36 | ||
| 37 | 37 | # Put desired Python version first in PATH | |
| 38 | 38 | - set PATH=%PYTHON%;%PYTHON%\Scripts;%PATH% | |
@@ -42,7 +42,6 @@ install: | |||
| 42 | 42 | - pip install --upgrade -r requirements.txt --quiet | |
| 43 | 43 | ||
| 44 | 44 | build_script: | |
| 45 | - - python setup.py configure | ||
| 46 | 45 | # Create clean `sdist`. Only used for releases | |
| 47 | 46 | - python setup.py --quiet sdist | |
| 48 | 47 | - python setup.py bdist_wheel | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,40 +2,5 @@ | |||
| 2 | 2 | Legacy Python.NET loader for backwards compatibility | |
| 3 | 3 | """ | |
| 4 | 4 | ||
| 5 | - def _get_netfx_path(): | ||
| 6 | - import os, sys | ||
| 7 | - | ||
| 8 | - if sys.maxsize > 2 ** 32: | ||
| 9 | - arch = "amd64" | ||
| 10 | - else: | ||
| 11 | - arch = "x86" | ||
| 12 | - | ||
| 13 | - return os.path.join(os.path.dirname(__file__), "pythonnet", "netfx", arch, "clr.pyd") | ||
| 14 | - | ||
| 15 | - | ||
| 16 | - def _get_mono_path(): | ||
| 17 | - import os, glob | ||
| 18 | - | ||
| 19 | - paths = glob.glob(os.path.join(os.path.dirname(__file__), "pythonnet", "mono", "clr.*so")) | ||
| 20 | - return paths[0] | ||
| 21 | - | ||
| 22 | - | ||
| 23 | - def _load_clr(): | ||
| 24 | - import sys | ||
| 25 | - from importlib import util | ||
| 26 | - | ||
| 27 | - if sys.platform == "win32": | ||
| 28 | - path = _get_netfx_path() | ||
| 29 | - else: | ||
| 30 | - path = _get_mono_path() | ||
| 31 | - | ||
| 32 | - del sys.modules[__name__] | ||
| 33 | - | ||
| 34 | - spec = util.spec_from_file_location("clr", path) | ||
| 35 | - clr = util.module_from_spec(spec) | ||
| 36 | - spec.loader.exec_module(clr) | ||
| 37 | - | ||
| 38 | - sys.modules[__name__] = clr | ||
| 39 | - | ||
| 40 | - | ||
| 41 | - _load_clr() | ||
| 5 | + from pythonnet import load | ||
| 6 | + load() | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,8 +6,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Python.Runtime", "src\runti | |||
| 6 | 6 | EndProject | |
| 7 | 7 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Console", "src\console\Console.csproj", "{E6B01706-00BA-4144-9029-186AC42FBE9A}" | |
| 8 | 8 | EndProject | |
| 9 | - Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "clrmodule", "src\clrmodule\clrmodule.csproj", "{F9F5FA13-BC52-4C0B-BC1C-FE3C0B8FCCDD}" | ||
| 10 | - EndProject | ||
| 11 | 9 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Python.EmbeddingTest", "src\embed_tests\Python.EmbeddingTest.csproj", "{819E089B-4770-400E-93C6-4F7A35F0EA12}" | |
| 12 | 10 | EndProject | |
| 13 | 11 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Python.Test", "src\testing\Python.Test.csproj", "{14EF9518-5BB7-4F83-8686-015BD2CC788E}" | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,3 +1,71 @@ | |||
| 1 | - def get_assembly_path(): | ||
| 2 | - import os | ||
| 3 | - return os.path.dirname(__file__) + "/runtime/Python.Runtime.dll" | ||
| 1 | + import os | ||
| 2 | + import sys | ||
| 3 | + import clr_loader | ||
| 4 | + | ||
| 5 | + _RUNTIME = None | ||
| 6 | + _LOADER_ASSEMBLY = None | ||
| 7 | + _FFI = None | ||
| 8 | + _LOADED = False | ||
| 9 | + | ||
| 10 | + | ||
| 11 | + def set_runtime(runtime): | ||
| 12 | + global _RUNTIME | ||
| 13 | + if _LOADED: | ||
| 14 | + raise RuntimeError("The runtime {runtime} has already been loaded".format(_RUNTIME)) | ||
| 15 | + | ||
| 16 | + _RUNTIME = runtime | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + def set_default_runtime() -> None: | ||
| 20 | + if sys.platform == 'win32': | ||
| 21 | + set_runtime(clr_loader.get_netfx()) | ||
| 22 | + else: | ||
| 23 | + set_runtime(clr_loader.get_mono()) | ||
| 24 | + | ||
| 25 | + | ||
| 26 | + def load(): | ||
| 27 | + global _FFI, _LOADED, _LOADER_ASSEMBLY | ||
| 28 | + | ||
| 29 | + if _LOADED: | ||
| 30 | + return | ||
| 31 | + | ||
| 32 | + from .find_libpython import linked_libpython | ||
| 33 | + from os.path import join, dirname | ||
| 34 | + | ||
| 35 | + if _RUNTIME is None: | ||
| 36 | + # TODO: Warn, in the future the runtime must be set explicitly, either | ||
| 37 | + # as a config/env variable or via set_runtime | ||
| 38 | + set_default_runtime() | ||
| 39 | + | ||
| 40 | + dll_path = join(dirname(__file__), "runtime", "Python.Runtime.dll") | ||
| 41 | + libpython = linked_libpython() | ||
| 42 | + | ||
| 43 | + if libpython and _FFI is None and sys.platform != "win32": | ||
| 44 | + # Load and leak libpython handle s.t. the .NET runtime doesn't dlcloses | ||
| 45 | + # it | ||
| 46 | + import posix | ||
| 47 | + | ||
| 48 | + import cffi | ||
| 49 | + _FFI = cffi.FFI() | ||
| 50 | + _FFI.dlopen(libpython, posix.RTLD_NODELETE | posix.RTLD_LOCAL) | ||
| 51 | + | ||
| 52 | + _LOADER_ASSEMBLY = _RUNTIME.get_assembly(dll_path) | ||
| 53 | + | ||
| 54 | + func = _LOADER_ASSEMBLY["Python.Runtime.Loader.Initialize"] | ||
| 55 | + if func(f"{libpython or ''}".encode("utf8")) != 0: | ||
| 56 | + raise RuntimeError("Failed to initialize Python.Runtime.dll") | ||
| 57 | + | ||
| 58 | + import atexit | ||
| 59 | + atexit.register(unload) | ||
| 60 | + | ||
| 61 | + | ||
| 62 | + def unload(): | ||
| 63 | + global _RUNTIME | ||
| 64 | + if _LOADER_ASSEMBLY is not None: | ||
| 65 | + func = _LOADER_ASSEMBLY["Python.Runtime.Loader.Shutdown"] | ||
| 66 | + if func(b"") != 0: | ||
| 67 | + raise RuntimeError("Failed to call Python.NET shutdown") | ||
| 68 | + | ||
| 69 | + if _RUNTIME is not None: | ||
| 70 | + # TODO: Add explicit `close` to clr_loader | ||
| 71 | + _RUNTIME = None | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments