Skip to content

Commit 54a54ce

Browse files
committed
Move libpython discovery around and update CI
1 parent d29a52e commit 54a54ce

File tree

6 files changed

+22
-52
lines changed

6 files changed

+22
-52
lines changed

.github/workflows/main.yml

Lines changed: 6 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,9 @@ jobs:
1212
fail-fast: false
1313
matrix:
1414
os: [windows, ubuntu, macos]
15-
pyver_minor: [6, 7, 8, 9]
15+
python: ["3.6", "3.7", "3.8", "3.9"]
1616
platform: [x64]
1717
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
4218

4319
env:
4420
PYTHONNET_SHUTDOWN_MODE: ${{ matrix.SHUTDOWN_MODE }}
@@ -56,10 +32,10 @@ jobs:
5632
- name: Setup .NET
5733
uses: actions/setup-dotnet@v1
5834

59-
- name: Set up Python 3.${{ matrix.pyver_minor }}
35+
- name: Set up Python ${{ matrix.python }}
6036
uses: actions/setup-python@v2
6137
with:
62-
python-version: 3.${{ matrix.pyver_minor }}
38+
python-version: ${{ matrix.python }}
6339
architecture: ${{ matrix.platform }}
6440

6541
- name: Install dependencies
@@ -68,31 +44,20 @@ jobs:
6844
6945
- name: Build and Install
7046
run: |
71-
python setup.py configure
7247
pip install -v .
7348
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
50+
run: |
51+
python -m pythonnet.find_libpython --export >> $GITHUB_ENV
8052
8153
- name: Python Tests
8254
run: pytest
83-
if: ${{ matrix.os == 'macos' }}
8455

8556
- name: Embedding tests
8657
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}}
9058

9159
- name: Python tests run from .NET
9260
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}}
9661

9762
# TODO: Run perf tests
9863
# TODO: Run mono tests on Windows?

pythonnet/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def load():
2626
if _LOADED:
2727
return
2828

29-
from .util import find_libpython
29+
from .find_libpython import find_libpython
3030
from os.path import join, dirname, basename
3131

3232
if _RUNTIME is None:
@@ -38,15 +38,14 @@ def load():
3838
libpython = basename(find_libpython())
3939
# TODO: Add dirname of libpython to (DY)LD_LIBRARY_PATH or PATH
4040

41-
if _FFI is None and libpython != "__Internal" and sys.platform != "win32":
41+
if _FFI is None and sys.platform != "win32":
4242
# Load and leak libpython handle s.t. the .NET runtime doesn't dlcloses it
4343
import posix
4444

4545
import cffi
4646
_FFI = cffi.FFI()
4747
_FFI.dlopen(libpython, posix.RTLD_NODELETE | posix.RTLD_LOCAL)
4848

49-
print("Loading from", dll_path)
5049
_LOADER_ASSEMBLY = _RUNTIME.get_assembly(dll_path)
5150

5251
func = _LOADER_ASSEMBLY["Python.Runtime.Loader.Initialize"]

pythonnet/util/find_libpython.py renamed to pythonnet/find_libpython/__init__.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ def print_all(items):
341341
print(x)
342342

343343

344-
def cli_find_libpython(cli_op, verbose):
344+
def cli_find_libpython(cli_op, verbose, export):
345345
import logging
346346
# Importing `logging` module here so that using `logging.debug`
347347
# instead of `logger.debug` outside of this function becomes an
@@ -362,7 +362,10 @@ def cli_find_libpython(cli_op, verbose):
362362
path = find_libpython()
363363
if path is None:
364364
return 1
365-
print(path, end="")
365+
if export:
366+
print(f"PYTHONNET_PYDLL={path}")
367+
else:
368+
print(path, end="")
366369

367370

368371
def main(args=None):
@@ -386,10 +389,11 @@ def main(args=None):
386389
"--candidate-paths",
387390
action="store_const", dest="cli_op", const="candidate-paths",
388391
help="Print list of candidate paths of libpython.")
392+
group.add_argument(
393+
"--export",
394+
action="store_true",
395+
help="Print as an environment export expression"
396+
)
389397

390398
ns = parser.parse_args(args)
391399
parser.exit(cli_find_libpython(**vars(ns)))
392-
393-
394-
if __name__ == "__main__":
395-
main()

pythonnet/find_libpython/__main__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from . import main
2+
main()

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def install_for_development(self):
141141
license="MIT",
142142
author="The Contributors of the Python.NET Project",
143143
author_email="pythonnet@python.org",
144-
packages=["pythonnet", "pythonnet.util"],
144+
packages=["pythonnet", "pythonnet.find_libpython"],
145145
install_requires=["pycparser", "clr_loader"],
146146
long_description=long_description,
147147
# data_files=[("{install_platlib}", ["{build_lib}/pythonnet"])],

src/domain_tests/test_domain_reload.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def _run_test(testname):
1212
if platform.system() != 'Windows':
1313
args = ['mono'] + args
1414

15-
from pythonnet.util import find_libpython
15+
from pythonnet.find_libpython import find_libpython
1616
libpython = find_libpython()
1717

1818
proc = subprocess.Popen(args, env={"PYTHONNET_PYDLL": libpython})

0 commit comments

Comments
 (0)