def write_hy_as_pyc(fname): with open(fname, 'U') as f: try: st = os.fstat(f.fileno()) except AttributeError: st = os.stat(fname) timestamp = long_type(st.st_mtime) _ast = import_file_to_ast(fname, os.path.basename(os.path.splitext(fname)[0])) code = ast_compile(_ast, fname, "exec") cfile = "%s.pyc" % fname[:-len(".hy")] open_ = builtins.open with open_(cfile, 'wb') as fc: if PY3: fc.write(b'\0\0\0\0') else: fc.write('\0\0\0\0') wr_long(fc, timestamp) if PY33: wr_long(fc, st.st_size) marshal.dump(code, fc) fc.flush() fc.seek(0, 0) fc.write(MAGIC)
def write_code_as_pyc(fname, code): st = os.stat(fname) timestamp = long_type(st.st_mtime) cfile = get_bytecode_path(fname) try: os.makedirs(os.path.dirname(cfile)) except (IOError, OSError): pass with builtins.open(cfile, 'wb') as fc: fc.write(MAGIC) wr_long(fc, timestamp) if PY3: wr_long(fc, st.st_size) marshal.dump(code, fc)
def write_code_as_pyc(fname, code): st = os.stat(fname) timestamp = long_type(st.st_mtime) cfile = get_bytecode_path(fname) try: os.makedirs(os.path.dirname(cfile)) except (IOError, OSError): pass 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) marshal.dump(code, fc)