The following code:
def _IMPORT_(path)
path = abspath(path)
namespace = path[len(getcwd())+1:].replace('/', '_').strip('\\/;,. ')
print(path)
print(namespace)
loader = importlib.machinery.SourceFileLoader(namespace, path+'.py')
handle = loader.load_module(namespace)
print(handle)
importlib.reload(handle)
return handle
Produces:
/home/torxed/git/test/unitest/unix
unitest_unix
<module 'unitest_unix' from '/home/torxed/git/test/unitest/unix.py'>
Traceback (most recent call last):
File "network.py", line 17, in <module>
handle = sock()
File "network.py", line 9, in __init__
sock = _IMPORT_('./unix')
File "/home/torxed/git/test/unitest/helpers.py", line 13, in _IMPORT_
imp.reload(handle)
File "/usr/lib/python3.4/imp.py", line 315, in reload
return importlib.reload(module)
File "/usr/lib/python3.4/importlib/__init__.py", line 149, in reload
methods.exec(module)
File "<frozen importlib._bootstrap>", line 1134, in exec
AttributeError: 'NoneType' object has no attribute 'name'
This works perfectly in Python 3.3.5 where this sort of operation was introduced (there were some similar import-mechanics before this). However on Python 3.4.2 This apparently doesn't work.
What's changed since 3.3.5? Can't find any traces of it or the change is somewhere in the middle of the releases. There were a patch last year for this exact behavior where the environment variables wasn't passed down but that appears to be working here.