Skip to content

Commit 1f855d1

Browse files
author
Kevin D Smith
committed
Fix path issue on ppc
1 parent 90edc40 commit 1f855d1

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

swat/clib.py

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import glob
2727
import os
28+
import platform
2829
import struct
2930
import sys
3031
from .utils.compat import PY3, WIDE_CHARS, a2u
@@ -41,11 +42,11 @@ def _import_pyswat():
4142

4243
import importlib
4344

44-
platform = 'linux'
45+
plat = 'linux'
4546
if sys.platform.lower().startswith('win'):
46-
platform = 'win'
47+
plat = 'win'
4748
elif sys.platform.lower().startswith('darwin'):
48-
platform = 'mac'
49+
plat = 'mac'
4950

5051
if PY3:
5152
libname = '_py%s%sswat' % (sys.version_info[0], sys.version_info[1])
@@ -55,14 +56,14 @@ def _import_pyswat():
5556
libname = '_pyswat'
5657

5758
# Bail out if we aren't on Linux
58-
# if platform != 'linux':
59+
# if plat != 'linux':
5960
# raise ValueError('Currently, Linux is the only platform with support '
6061
# 'for the binary protocol. You must connect to CAS '
6162
# 'using the REST interface on this platform.')
6263

6364
# Bail out if the C extension doesn't exist
6465
if not glob.glob(os.path.join(os.path.dirname(__file__), 'lib',
65-
platform, libname + '.*')):
66+
plat, libname + '.*')):
6667
raise ValueError('The extensions for the binary protocol have not been '
6768
'installed. You can either install them using the full '
6869
'platform-dependent install file, or use the REST interface '
@@ -85,7 +86,7 @@ def _import_pyswat():
8586

8687
# Try to import the C extension
8788
try:
88-
_pyswat = importlib.import_module('.lib.%s.%s' % (platform, libname),
89+
_pyswat = importlib.import_module('.lib.%s.%s' % (plat, libname),
8990
package='swat')
9091

9192
except ImportError:
@@ -141,11 +142,24 @@ def InitializeTK(*args, **kwargs):
141142
''' Initialize the TK subsystem (importing _pyswat as needed) '''
142143
if _pyswat is None:
143144
_import_pyswat()
144-
out = _pyswat.InitializeTK(*args, **kwargs)
145-
# Override TKPATH after initialization so that other TK applications
146-
# won't be affected.
147-
if sys.platform.lower().startswith('win') and 'TKPATH' not in os.environ:
148-
os.environ['TKPATH'] = os.pathsep
145+
146+
# Patch ppc linux path
147+
set_tkpath_env = 'ppc' in platform.machine() and 'TKPATH' not in os.environ
148+
if set_tkpath_env and args:
149+
os.environ['TKPATH'] = args[0]
150+
151+
try:
152+
out = _pyswat.InitializeTK(*args, **kwargs)
153+
154+
finally:
155+
if set_tkpath_env:
156+
del os.environ['TKPATH']
157+
158+
# Override TKPATH after initialization so that other TK applications
159+
# won't be affected (Windows only).
160+
if sys.platform.lower().startswith('win') and 'TKPATH' not in os.environ:
161+
os.environ['TKPATH'] = os.pathsep
162+
149163
return out
150164

151165

0 commit comments

Comments
 (0)