Matt Riedemann 8252703f56 Unblock migrate (py26 and py3* testing issues)
There are two changes which have to go together to pass the gate
tests:

1. Update pbr and mock requirements from global-requirements

mock 1.2 supports py26 again so make that the minimum version. The
same change is being made in g-r with:

Ic6b9e18eaec9c81bbbbc57129e024904be928e09

Sync up with latest pbr in global-requirements while we're at it.

Closes-Bug: #1474925

2. Fix the importpath module to work with python >= 3.3 where the
__import__ built-in is raising an ImportError on a temporary file
that is added to the system path.

Closes-Bug: #1475339

Change-Id: Ie98938ba75f3983094dd540b7d26a7ec46be4f6e
2015-07-18 10:39:35 -07:00

31 lines
886 B
Python

import os
import sys
PY33 = sys.version_info >= (3, 3)
if PY33:
from importlib import machinery
else:
from six.moves import reload_module as reload
def import_path(fullpath):
""" Import a file with full path specification. Allows one to
import from anywhere, something __import__ does not do.
"""
if PY33:
name = os.path.splitext(os.path.basename(fullpath))[0]
return machinery.SourceFileLoader(
name, fullpath).load_module(name)
else:
# http://zephyrfalcon.org/weblog/arch_d7_2002_08_31.html
path, filename = os.path.split(fullpath)
filename, ext = os.path.splitext(filename)
sys.path.append(path)
try:
module = __import__(filename)
reload(module) # Might be out of date during tests
return module
finally:
del sys.path[-1]