Commit deef9b9f authored by Sergei Lebedev's avatar Sergei Lebedev

Addressed review comments

parent 17bef673
......@@ -308,27 +308,31 @@ class PyxImporter(object):
elif not os.path.isabs(path):
path = os.path.abspath(path)
try:
zi = zipimporter(path)
data = zi.get_data(pyx_module_name)
except (ZipImportError, IOError):
pyx_module_path = os.path.join(path, pyx_module_name)
if os.path.isfile(path):
try:
zi = zipimporter(path)
data = zi.get_data(pyx_module_name)
except (ZipImportError, IOError):
continue # Module not found.
else:
# XXX unzip the imported file into the build dir. A bit
# hacky, but it works!
if not os.path.exists(self.pyxbuild_dir):
os.makedirs(self.pyxbuild_dir)
pyx_module_path = os.path.join(self.pyxbuild_dir,
pyx_module_name)
with open(pyx_module_path, "wb") as f:
f.write(data)
else:
# XXX unzip the imported file into the build dir. A bit
# hacky, but it works!
if not os.path.exists(self.pyxbuild_dir):
os.makedirs(self.pyxbuild_dir)
pyx_module_path = os.path.join(self.pyxbuild_dir,
pyx_module_name)
with open(pyx_module_path, "wb") as handle:
handle.write(data)
if os.path.isfile(pyx_module_path):
return PyxLoader(fullname, pyx_module_path,
pyxbuild_dir=self.pyxbuild_dir,
inplace=self.inplace,
language_level=self.language_level)
pyx_module_path = os.path.join(path, pyx_module_name)
if not os.path.isfile(pyx_module_path):
continue # Module not found.
return PyxLoader(fullname, pyx_module_path,
pyxbuild_dir=self.pyxbuild_dir,
inplace=self.inplace,
language_level=self.language_level)
# not found, normal package, not a .pyx file, none of our business
_debug("%s not found" % fullname)
......
......@@ -96,6 +96,15 @@ def test_zip():
assert test_zip_module.x == 42
finally:
os.remove(zip_path)
sys.path.remove(zip_path)
def test_zip_nonexisting():
sys.path.append("nonexisting_zip_module.zip")
try:
import nonexisting_zip_module
except ImportError:
pass
if __name__== "__main__":
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment