提交 12152e3d authored 作者: Olivier Delalleau's avatar Olivier Delalleau

Modified the way the version of lazylinker is checked to avoid problems under Windows.

The problem was that the version was obtained *after* importing the C module. As a result, recompilation would fail because the library was still in use. This change also saves the version in the __init__.py file of the lazylinker_ext base module, so that it can be checked without loading the C module.
上级 a1197aac
...@@ -11,14 +11,12 @@ if config.compiledir not in sys.path: ...@@ -11,14 +11,12 @@ if config.compiledir not in sys.path:
sys.path.append(config.compiledir) sys.path.append(config.compiledir)
version = 0.1 # must match constant returned in function get_version() version = 0.1 # must match constant returned in function get_version()
need_reload = False
try: try:
import lazylinker_ext import lazylinker_ext
try: need_reload = True
import lazylinker_ext.lazylinker_ext if version != getattr(lazylinker_ext, '_version', None):
get_version = lazylinker_ext.lazylinker_ext.get_version
except:
get_version = lambda: None
if version != get_version():
raise ImportError() raise ImportError()
except ImportError: except ImportError:
get_lock() get_lock()
...@@ -26,13 +24,14 @@ except ImportError: ...@@ -26,13 +24,14 @@ except ImportError:
# Maybe someone else already finished compiling it while we were # Maybe someone else already finished compiling it while we were
# waiting for the lock? # waiting for the lock?
try: try:
import lazylinker_ext if need_reload:
try: # The module was successfully imported earlier: we need to
import lazylinker_ext.lazylinker_ext # reload it to check if the version was updated.
get_version = lazylinker_ext.lazylinker_ext.get_version reload(lazylinker_ext)
except: else:
get_version = lambda: None import lazylinker_ext
if version != get_version(): need_reload = True
if version != getattr(lazylinker_ext, '_version', None):
raise ImportError() raise ImportError()
except ImportError: except ImportError:
print "COMPILING NEW CVM" print "COMPILING NEW CVM"
...@@ -43,7 +42,21 @@ except ImportError: ...@@ -43,7 +42,21 @@ except ImportError:
if not os.path.exists(loc): if not os.path.exists(loc):
os.mkdir(loc) os.mkdir(loc)
cmodule.gcc_module_compile_str(dirname, code, location=loc) cmodule.gcc_module_compile_str(dirname, code, location=loc)
print "NEW VERSION", lazylinker_ext.lazylinker_ext.get_version() # Save version into the __init__.py file.
init_py = os.path.join(loc, '__init__.py')
open(init_py, 'w').write('_version = %s\n' % version)
# If we just compiled the module for the first time, then it was
# imported at the same time: we need to make sure we do not
# reload the now outdated __init__.pyc below.
init_pyc = os.path.join(loc, '__init__.pyc')
if os.path.isfile(init_pyc):
os.remove(init_pyc)
import lazylinker_ext
reload(lazylinker_ext)
from lazylinker_ext import lazylinker_ext as lazy_c
assert (lazylinker_ext._version ==
lazy_c.get_version())
print "NEW VERSION", lazylinker_ext._version
finally: finally:
# Release lock on compilation directory. # Release lock on compilation directory.
release_lock() release_lock()
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论