bpo-35596: Use unchecked PYCs for the embeddable distro to avoid zipi… · python/cpython@69f64b6 (original) (raw)

`@@ -240,12 +240,18 @@ def _c(d):

`

240

240

`yield "DLLs/{}".format(ns.include_cat.name), ns.include_cat

`

241

241

``

242

242

``

243

``

`-

def _compile_one_py(src, dest, name, optimize):

`

``

243

`+

def _compile_one_py(src, dest, name, optimize, checked=True):

`

244

244

`import py_compile

`

245

245

``

246

246

`if dest is not None:

`

247

247

`dest = str(dest)

`

248

248

``

``

249

`+

mode = (

`

``

250

`+

py_compile.PycInvalidationMode.CHECKED_HASH

`

``

251

`+

if checked

`

``

252

`+

else py_compile.PycInvalidationMode.UNCHECKED_HASH

`

``

253

`+

)

`

``

254

+

249

255

`try:

`

250

256

`return Path(

`

251

257

`py_compile.compile(

`

`@@ -254,24 +260,24 @@ def _compile_one_py(src, dest, name, optimize):

`

254

260

`str(name),

`

255

261

`doraise=True,

`

256

262

`optimize=optimize,

`

257

``

`-

invalidation_mode=py_compile.PycInvalidationMode.CHECKED_HASH,

`

``

263

`+

invalidation_mode=mode,

`

258

264

` )

`

259

265

` )

`

260

266

`except py_compile.PyCompileError:

`

261

267

`log_warning("Failed to compile {}", src)

`

262

268

`return None

`

263

269

``

264

270

``

265

``

`-

def _py_temp_compile(src, ns, dest_dir=None):

`

``

271

`+

def _py_temp_compile(src, ns, dest_dir=None, checked=True):

`

266

272

`if not ns.precompile or src not in PY_FILES or src.parent in DATA_DIRS:

`

267

273

`return None

`

268

274

``

269

275

`dest = (dest_dir or ns.temp) / (src.stem + ".py")

`

270

``

`-

return _compile_one_py(src, dest.with_suffix(".pyc"), dest, optimize=2)

`

``

276

`+

return _compile_one_py(src, dest.with_suffix(".pyc"), dest, optimize=2, checked=checked)

`

271

277

``

272

278

``

273

``

`-

def _write_to_zip(zf, dest, src, ns):

`

274

``

`-

pyc = _py_temp_compile(src, ns)

`

``

279

`+

def _write_to_zip(zf, dest, src, ns, checked=True):

`

``

280

`+

pyc = _py_temp_compile(src, ns, checked=checked)

`

275

281

`if pyc:

`

276

282

`try:

`

277

283

`zf.write(str(pyc), dest.with_suffix(".pyc"))

`

`@@ -321,7 +327,7 @@ def generate_source_files(ns):

`

321

327

`ns.temp.mkdir(parents=True, exist_ok=True)

`

322

328

`with zipfile.ZipFile(zip_path, "w", zipfile.ZIP_DEFLATED) as zf:

`

323

329

`for dest, src in get_lib_layout(ns):

`

324

``

`-

_write_to_zip(zf, dest, src, ns)

`

``

330

`+

_write_to_zip(zf, dest, src, ns, checked=False)

`

325

331

``

326

332

`if ns.include_underpth:

`

327

333

`log_info("Generating {} in {}", PYTHON_PTH_NAME, ns.temp)

`