Implement changes to support PEP 552

This commit is contained in:
Simon Gomizelj 2018-02-09 16:43:25 -05:00
parent 7dcf1fa63d
commit a2c8f50b30
2 changed files with 8 additions and 1 deletions

View File

@ -23,6 +23,7 @@ import sys
PY3 = sys.version_info[0] >= 3
PY35 = sys.version_info >= (3, 5)
PY36 = sys.version_info >= (3, 6)
PY37 = sys.version_info >= (3, 7)
str_type = str if PY3 else unicode # NOQA
bytes_type = bytes if PY3 else str # NOQA

View File

@ -18,7 +18,7 @@ import inspect
import os
import __future__
from hy._compat import PY3, MAGIC, builtins, long_type, wr_long
from hy._compat import PY3, PY37, MAGIC, builtins, long_type, wr_long
from hy._compat import string_types
@ -220,6 +220,12 @@ def write_code_as_pyc(fname, code):
with builtins.open(cfile, 'wb') as fc:
fc.write(MAGIC)
if PY37:
# With PEP 552, the header structure has a new flags field
# that we need to fill in. All zeros preserve the legacy
# behaviour, but should we implement reproducible builds,
# this is where we'd add the information.
wr_long(fc, 0)
wr_long(fc, timestamp)
if PY3:
wr_long(fc, st.st_size)