Skip to content

Commit 922b816

Browse files
committed
Improved osmesa module load when enabled
Remove the symlink, use swig module load to detect osmesa context requested and load the correct module that way, should fix #111
1 parent 5245090 commit 922b816

File tree

6 files changed

+166
-151
lines changed

6 files changed

+166
-151
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,9 @@ endif
256256

257257
.PHONY: swig
258258
swig : $(INC) src/LavaVuPython.i | paths
259+
#NOTE: bug in swig requires pip install swig==4.2 until fixed
259260
swig -v -Wextra -python -py3 -ignoremissing -O -c++ -DSWIG_DO_NOT_WRAP -outdir $(PREFIX) src/LavaVuPython.i
260-
cd $(PREFIX)/osmesa; ln -sf ../LavaVuPython.py; touch __init__.py
261+
cd $(PREFIX)/osmesa; touch __init__.py
261262

262263
$(SWIGLIB) : $(LIBRARY) $(SWIGOBJ)
263264
-rm -f $(PREFIX)/_LavaVuPython.*

lavavu/LavaVuPython.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
# the SWIG interface file instead.
66

77
from sys import version_info as _swig_python_version_info
8-
# Import the low-level C/C++ module
9-
if __package__ or "." in __name__:
10-
from . import _LavaVuPython
8+
9+
import os
10+
if 'osmesa' in os.environ.get('LV_CONTEXT', ''):
11+
from osmesa import _LavaVuPython
1112
else:
1213
import _LavaVuPython
1314

15+
1416
try:
1517
import builtins as __builtin__
1618
except ImportError:

lavavu/lavavu.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,19 +102,14 @@
102102
context = 'moderngl'
103103
except Exception as e:
104104
context = 'osmesa'
105-
106-
if context == 'osmesa':
107-
#OSMesa fallback, CPU only, multicore
108-
from osmesa import LavaVuPython
105+
os.environ['LV_CONTEXT'] = context
109106

110107
#Default module if none already loaded
111108
try:
112109
LavaVuPython
113110
except:
114111
import LavaVuPython
115112

116-
os.environ['LV_CONTEXT'] = context
117-
118113
version = LavaVuPython.version
119114
server_ports = []
120115

lavavu/osmesa/LavaVuPython.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/LavaVuPython.i

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
11
/*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*
22
* LavaVu python interface
33
**~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*/
4-
%module LavaVuPython
4+
#%module LavaVuPython
5+
#%module(package="mypackage") LavaVuPython
6+
#%module(package="LavaVuPython", moduleimport="import $module") foo
7+
#%module(moduleimport="from osmesa import _LavaVuPython") foo
8+
9+
%define MODULEIMPORT
10+
"
11+
import os
12+
if 'osmesa' in os.environ.get('LV_CONTEXT', ''):
13+
from osmesa import $module
14+
else:
15+
import $module
16+
"
17+
%enddef
18+
19+
%module(moduleimport=MODULEIMPORT) LavaVuPython
520

621
%{
722
#define SWIG_FILE_WITH_INIT

0 commit comments

Comments
 (0)