Skip to content

Commit ae524b5

Browse files
committed
use importlib in py34+ instead of imp (deprecated)
1 parent 5d59bd2 commit ae524b5

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

cocos/__init__.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,24 @@
8282
# in windows we use the pygame package to get the SDL dlls
8383
# we must get the path here because the inner pygame module will hide the real
8484
if sys.platform == 'win32':
85-
import imp
86-
try:
87-
dummy, sdl_lib_path, dummy = imp.find_module('pygame')
88-
del dummy
89-
except ImportError:
90-
sdl_lib_path = None
85+
# module imp is deprecated in 3.5, the 3.x functionality
86+
# needed appears in 3.4
87+
major, minor = sys.version_info[0:2]
88+
if major == 2 or major == 3 and minor < 4:
89+
import imp
90+
try:
91+
dummy, sdl_lib_path, dummy = imp.find_module('pygame')
92+
del dummy
93+
except ImportError:
94+
sdl_lib_path = None
95+
else:
96+
import importlib
97+
try:
98+
spec = importlib.util.find_spec("pygame")
99+
sdl_lib_path = spec.submodule_search_locations[0]
100+
except Exception:
101+
sdl_lib_path = None
102+
91103

92104
if not unittesting:
93105

0 commit comments

Comments
 (0)