Skip to content

Commit 91cab8e

Browse files
committed
-
1 parent f2b0d94 commit 91cab8e

File tree

2 files changed

+3
-24
lines changed

2 files changed

+3
-24
lines changed

python_toolbox/import_tools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import sys
77
import os.path
8-
import imp
8+
import importlib
99
import zipimport
1010
import functools
1111
import pathlib

test_python_toolbox/__init__.py

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import sys
77
import pathlib
8+
import importlib
89

910
import pytest
1011

@@ -17,29 +18,7 @@ def __bootstrap():
1718
This adds `python_toolbox`'s root folder to `sys.path` if it can't
1819
currently be imported.
1920
'''
20-
import os
21-
import sys
22-
import imp
23-
24-
def exists(module_name):
25-
'''
26-
Return whether a module by the name `module_name` exists.
27-
28-
This seems to be the best way to carefully import a module.
29-
30-
Currently implemented for top-level packages only. (i.e. no dots.)
31-
32-
Doesn't support modules imported from a zip file.
33-
'''
34-
assert '.' not in module_name
35-
try:
36-
imp.find_module(module_name)
37-
except ImportError:
38-
return False
39-
else:
40-
return True
41-
42-
if not exists('python_toolbox'):
21+
if not importlib.util.find_spec('python_toolbox'):
4322
python_toolbox_candidate_path = \
4423
pathlib(__file__).parent.parent.absolute()
4524
sys.path.append(python_toolbox_candidate_path)

0 commit comments

Comments
 (0)