mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 08:24:40 +01:00
added python version to code cache
This commit is contained in:
parent
3236f3507f
commit
727550f9ef
3 changed files with 21 additions and 7 deletions
|
@ -18,8 +18,6 @@ else:
|
|||
_sys.modules['xonsh.lazyasd'] = __amalgam__
|
||||
lazyjson = __amalgam__
|
||||
_sys.modules['xonsh.lazyjson'] = __amalgam__
|
||||
codecache = __amalgam__
|
||||
_sys.modules['xonsh.codecache'] = __amalgam__
|
||||
color_tools = __amalgam__
|
||||
_sys.modules['xonsh.color_tools'] = __amalgam__
|
||||
platform = __amalgam__
|
||||
|
@ -28,6 +26,8 @@ else:
|
|||
_sys.modules['xonsh.pretty'] = __amalgam__
|
||||
ansi_colors = __amalgam__
|
||||
_sys.modules['xonsh.ansi_colors'] = __amalgam__
|
||||
codecache = __amalgam__
|
||||
_sys.modules['xonsh.codecache'] = __amalgam__
|
||||
lazyimps = __amalgam__
|
||||
_sys.modules['xonsh.lazyimps'] = __amalgam__
|
||||
parser = __amalgam__
|
||||
|
|
|
@ -7,6 +7,7 @@ import builtins
|
|||
|
||||
from xonsh import __version__ as XONSH_VERSION
|
||||
from xonsh.lazyasd import lazyobject
|
||||
from xonsh.platform import PYTHON_VERSION_INFO_BYTES
|
||||
|
||||
|
||||
def _splitpath(path, sofar=[]):
|
||||
|
@ -92,12 +93,17 @@ def update_cache(ccode, cache_file_name):
|
|||
_make_if_not_exists(os.path.dirname(cache_file_name))
|
||||
with open(cache_file_name, 'wb') as cfile:
|
||||
cfile.write(XONSH_VERSION.encode() + b'\n')
|
||||
cfile.write(bytes(PYTHON_VERSION_INFO_BYTES) + b'\n')
|
||||
marshal.dump(ccode, cfile)
|
||||
|
||||
|
||||
def _check_cache_xonsh_version(cfile):
|
||||
ver = cfile.readline(1024).strip() # version should be < 1 kb
|
||||
return ver == XONSH_VERSION.encode()
|
||||
def _check_cache_versions(cfile):
|
||||
# version data should be < 1 kb
|
||||
ver = cfile.readline(1024).strip()
|
||||
if ver != XONSH_VERSION.encode():
|
||||
return False
|
||||
ver = cfile.readline(1024).strip()
|
||||
return ver == PYTHON_VERSION_INFO_BYTES
|
||||
|
||||
|
||||
def compile_code(filename, code, execer, glb, loc, mode):
|
||||
|
@ -131,7 +137,7 @@ def script_cache_check(filename, cachefname):
|
|||
if os.path.isfile(cachefname):
|
||||
if os.stat(cachefname).st_mtime >= os.stat(filename).st_mtime:
|
||||
with open(cachefname, 'rb') as cfile:
|
||||
if not _check_cache_xonsh_version(cfile):
|
||||
if not _check_cache_versions(cfile):
|
||||
return False, None
|
||||
ccode = marshal.load(cfile)
|
||||
run_cached = True
|
||||
|
@ -179,7 +185,7 @@ def code_cache_check(cachefname):
|
|||
run_cached = False
|
||||
if os.path.isfile(cachefname):
|
||||
with open(cachefname, 'rb') as cfile:
|
||||
if not _check_cache_xonsh_version(cfile):
|
||||
if not _check_cache_versions(cfile):
|
||||
return False, None
|
||||
ccode = marshal.load(cfile)
|
||||
run_cached = True
|
||||
|
|
|
@ -74,6 +74,14 @@ def ON_BEOS():
|
|||
|
||||
PYTHON_VERSION_INFO = sys.version_info[:3]
|
||||
""" Version of Python interpreter as three-value tuple. """
|
||||
|
||||
|
||||
@lazyobject
|
||||
def PYTHON_VERSION_INFO_BYTES():
|
||||
"""The python version info tuple in a canonical bytes form."""
|
||||
return '.'.join(map(str, sys.version_info)).encode()
|
||||
|
||||
|
||||
ON_ANACONDA = LazyBool(
|
||||
lambda: any(s in sys.version for s in {'Anaconda', 'Continuum', 'conda-forge'}),
|
||||
globals(), 'ON_ANACONDA')
|
||||
|
|
Loading…
Add table
Reference in a new issue