Skip to content

Commit

Permalink
Merge pull request #746 from pv/py37-imp
Browse files Browse the repository at this point in the history
Use importlib instead of imp on Python 3
  • Loading branch information
pv authored Sep 29, 2018
2 parents d39172a + 21208d0 commit 04f3ef7
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions asv/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@
from ctypes.util import find_library
from hashlib import sha256
import errno
import imp
if sys.version_info[0] >= 3:
import importlib.machinery
else:
import imp
import inspect
import itertools
import json
Expand Down Expand Up @@ -591,7 +594,10 @@ def run(self, *param):
# the asv package in the benchmarking process.
path = os.path.join(
os.path.dirname(__file__), 'extern', 'asizeof.py')
asizeof = imp.load_source('asizeof', path)
if sys.version_info[0] >= 3:
asizeof = importlib.machinery.SourceFileLoader('asizeof', path).load_module()
else:
asizeof = imp.load_source('asizeof', path)

obj = self.func(*param)

Expand Down Expand Up @@ -659,14 +665,23 @@ def __init__(self, name, root):
self._name = name
self._root = root

def find_module(self, fullname, path=None):
if fullname == self._name:
return self
return None
if sys.version_info[0] >= 3:
def find_spec(self, fullname, path, target):
if fullname == self._name:
if path is not None:
raise ValueError()
finder = importlib.machinery.PathFinder()
return finder.find_spec(fullname, [self._root], target)
return None
else:
def find_module(self, fullname, path=None):
if fullname == self._name:
return self
return None

def load_module(self, fullname):
file, pathname, desc = imp.find_module(fullname, [self._root])
return imp.load_module(fullname, file, pathname, desc)
def load_module(self, fullname):
file, pathname, desc = imp.find_module(fullname, [self._root])
return imp.load_module(fullname, file, pathname, desc)


def update_sys_path(root):
Expand Down

0 comments on commit 04f3ef7

Please sign in to comment.