Skip to content

Commit

Permalink
github actions: linux: add detection of python .so file and folder.
Browse files Browse the repository at this point in the history
  • Loading branch information
retsios committed Feb 12, 2025
1 parent 0710ce3 commit 76e4753
Showing 1 changed file with 48 additions and 23 deletions.
71 changes: 48 additions & 23 deletions patch_pythonapi_linux.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,54 @@
from sysconfig import get_paths
from platform import python_version
import os
from sysconfig import get_paths, get_config_var
import ctypes
from ctypes.util import find_library

class Dl_info(ctypes.Structure):
_fields_ = [
("dli_fname", ctypes.c_char_p),
("dli_fbase", ctypes.c_void_p),
("dli_sname", ctypes.c_char_p),
("dli_saddr", ctypes.c_void_p),
]

info = get_paths()
include_path = info['include']
version = python_version()
version = '.'.join(version.split('.')[0:2])
f = open('pythonapi.pro')
lines = f.readlines()
f.close()
f = None
lines = [line.rstrip() for line in lines]
i = 0
f = open('pythonapi.pro', 'w')
while i < len(lines):
line = lines[i]
if line.strip() == 'PYMINORVERSION=8':
f.write(line + '\n')
i = i + 1

LDLIBRARY = get_config_var("LDLIBRARY")
if LDLIBRARY.endswith('.a'):
LDLIBRARY = LDLIBRARY.rstrip('.a') + '.so'
libpython = ctypes.CDLL(LDLIBRARY)
libdl = ctypes.CDLL(find_library("dl"))
dlinfo = Dl_info()
retcode = libdl.dladdr(
ctypes.cast(libpython.Py_GetVersion, ctypes.c_void_p),
ctypes.pointer(dlinfo),
)
if retcode != 0:
fullpath = os.path.realpath(dlinfo.dli_fname.decode())
fullpath = fullpath.split('.so')[0]
fullpath = fullpath.split('/')
lib = '/'.join(fullpath[0:-1])
name = fullpath[-1].lstrip('lib')
f = open('pythonapi.pro')
lines = f.readlines()
f.close()
f = None
lines = [line.rstrip() for line in lines]
i = 0
f = open('pythonapi.pro', 'w')
while i < len(lines):
line = lines[i]
while line.strip() != 'OUTPUTPATHPYTHON=$$clean_path($$PWD/../output/$$PREFIX_COMPILER/$$CONF/ilwispy/ilwis)':
if line.strip() == 'PYMINORVERSION=8':
f.write(line + '\n')
i = i + 1
line = lines[i]
f.write(' PYTHON_INCLUDE_FILES=' + include_path + '\n')
f.write(' LIBS += -L$$/usr/libs -lpython' + version + '\n')
f.write(line + '\n')
i = i + 1
f.flush()
f.close()
while line.strip() != 'OUTPUTPATHPYTHON=$$clean_path($$PWD/../output/$$PREFIX_COMPILER/$$CONF/ilwispy/ilwis)':
i = i + 1
line = lines[i]
f.write(' PYTHON_INCLUDE_FILES=' + include_path + '\n')
f.write(' LIBS += -L' + lib + ' -l' + name + '\n')
f.write(line + '\n')
i = i + 1
f.flush()
f.close()

0 comments on commit 76e4753

Please sign in to comment.