cinderx 2026.1.16.2__cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. __static__/__init__.py +641 -0
  2. __static__/compiler_flags.py +8 -0
  3. __static__/enum.py +160 -0
  4. __static__/native_utils.py +77 -0
  5. __static__/type_code.py +48 -0
  6. __strict__/__init__.py +39 -0
  7. _cinderx.so +0 -0
  8. cinderx/__init__.py +577 -0
  9. cinderx/__pycache__/__init__.cpython-314.pyc +0 -0
  10. cinderx/_asyncio.py +156 -0
  11. cinderx/compileall.py +710 -0
  12. cinderx/compiler/__init__.py +40 -0
  13. cinderx/compiler/__main__.py +137 -0
  14. cinderx/compiler/config.py +7 -0
  15. cinderx/compiler/consts.py +72 -0
  16. cinderx/compiler/debug.py +70 -0
  17. cinderx/compiler/dis_stable.py +283 -0
  18. cinderx/compiler/errors.py +151 -0
  19. cinderx/compiler/flow_graph_optimizer.py +1287 -0
  20. cinderx/compiler/future.py +91 -0
  21. cinderx/compiler/misc.py +32 -0
  22. cinderx/compiler/opcode_cinder.py +18 -0
  23. cinderx/compiler/opcode_static.py +100 -0
  24. cinderx/compiler/opcodebase.py +158 -0
  25. cinderx/compiler/opcodes.py +991 -0
  26. cinderx/compiler/optimizer.py +547 -0
  27. cinderx/compiler/pyassem.py +3711 -0
  28. cinderx/compiler/pycodegen.py +7660 -0
  29. cinderx/compiler/pysourceloader.py +62 -0
  30. cinderx/compiler/static/__init__.py +1404 -0
  31. cinderx/compiler/static/compiler.py +629 -0
  32. cinderx/compiler/static/declaration_visitor.py +335 -0
  33. cinderx/compiler/static/definite_assignment_checker.py +280 -0
  34. cinderx/compiler/static/effects.py +160 -0
  35. cinderx/compiler/static/module_table.py +666 -0
  36. cinderx/compiler/static/type_binder.py +2176 -0
  37. cinderx/compiler/static/types.py +10580 -0
  38. cinderx/compiler/static/util.py +81 -0
  39. cinderx/compiler/static/visitor.py +91 -0
  40. cinderx/compiler/strict/__init__.py +69 -0
  41. cinderx/compiler/strict/class_conflict_checker.py +249 -0
  42. cinderx/compiler/strict/code_gen_base.py +409 -0
  43. cinderx/compiler/strict/common.py +507 -0
  44. cinderx/compiler/strict/compiler.py +352 -0
  45. cinderx/compiler/strict/feature_extractor.py +130 -0
  46. cinderx/compiler/strict/flag_extractor.py +97 -0
  47. cinderx/compiler/strict/loader.py +827 -0
  48. cinderx/compiler/strict/preprocessor.py +11 -0
  49. cinderx/compiler/strict/rewriter/__init__.py +5 -0
  50. cinderx/compiler/strict/rewriter/remove_annotations.py +84 -0
  51. cinderx/compiler/strict/rewriter/rewriter.py +975 -0
  52. cinderx/compiler/strict/runtime.py +77 -0
  53. cinderx/compiler/symbols.py +1754 -0
  54. cinderx/compiler/unparse.py +414 -0
  55. cinderx/compiler/visitor.py +194 -0
  56. cinderx/jit.py +230 -0
  57. cinderx/opcode.py +202 -0
  58. cinderx/static.py +113 -0
  59. cinderx/strictmodule.py +6 -0
  60. cinderx/test_support.py +341 -0
  61. cinderx-2026.1.16.2.dist-info/METADATA +15 -0
  62. cinderx-2026.1.16.2.dist-info/RECORD +68 -0
  63. cinderx-2026.1.16.2.dist-info/WHEEL +6 -0
  64. cinderx-2026.1.16.2.dist-info/licenses/LICENSE +21 -0
  65. cinderx-2026.1.16.2.dist-info/top_level.txt +5 -0
  66. opcodes/__init__.py +0 -0
  67. opcodes/assign_opcode_numbers.py +272 -0
  68. opcodes/cinderx_opcodes.py +121 -0
cinderx/compileall.py ADDED
@@ -0,0 +1,710 @@
1
+ # Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ # pyre-strict
4
+
5
+ """Module/script to byte-compile all .py files to .pyc files.
6
+
7
+ When called as a script with arguments, this compiles the directories
8
+ given as arguments recursively; the -l option prevents it from
9
+ recursing into directories.
10
+
11
+ Without arguments, if compiles all modules on sys.path, without
12
+ recursing into subdirectories. (Even though it should do so for
13
+ packages -- for now, you'll have to deal with packages separately.)
14
+
15
+ See module py_compile for details of the actual byte-compilation.
16
+ """
17
+
18
+ import filecmp
19
+ import importlib.util
20
+ import os
21
+ import py_compile
22
+ import struct
23
+ import sys
24
+ from functools import partial
25
+ from pathlib import Path
26
+ from typing import Generator, Pattern, Type
27
+
28
+ import cinderx
29
+ from cinderx.compiler.pysourceloader import PySourceFileLoader
30
+ from cinderx.compiler.strict.loader import strict_compile as strict_compile_fn
31
+
32
+ __all__ = ["compile_dir", "compile_file", "compile_path"]
33
+
34
+
35
+ def _walk_dir(dir: str, maxlevels: int, quiet: int = 0) -> Generator[str, None, None]:
36
+ if quiet < 2 and isinstance(dir, os.PathLike):
37
+ dir = os.fspath(dir)
38
+ if not quiet:
39
+ print("Listing {!r}...".format(dir))
40
+ try:
41
+ names = os.listdir(dir)
42
+ except OSError:
43
+ if quiet < 2:
44
+ print("Can't list {!r}".format(dir))
45
+ names = []
46
+ names.sort()
47
+ for name in names:
48
+ if name == "__pycache__":
49
+ continue
50
+ fullname = os.path.join(dir, name)
51
+ if not os.path.isdir(fullname):
52
+ yield fullname
53
+ elif (
54
+ maxlevels > 0
55
+ and name != os.curdir
56
+ and name != os.pardir
57
+ and os.path.isdir(fullname)
58
+ and not os.path.islink(fullname)
59
+ ):
60
+ yield from _walk_dir(fullname, maxlevels=maxlevels - 1, quiet=quiet)
61
+
62
+
63
+ def compile_dir(
64
+ dir: str,
65
+ maxlevels: int | None = None,
66
+ ddir: str | None = None,
67
+ force: bool = False,
68
+ rx: Pattern | None = None,
69
+ quiet: int = 0,
70
+ legacy: bool = False,
71
+ optimize: int | list[int] = -1,
72
+ workers: int = 1,
73
+ invalidation_mode: py_compile.PycInvalidationMode | None = None,
74
+ *,
75
+ stripdir: str | None = None,
76
+ prependdir: str | None = None,
77
+ limit_sl_dest: str | None = None,
78
+ hardlink_dupes: bool = False,
79
+ loader_override: Type[PySourceFileLoader] | None = None,
80
+ strict_compile: bool = False,
81
+ ) -> bool:
82
+ """Byte-compile all modules in the given directory tree.
83
+
84
+ Arguments (only dir is required):
85
+
86
+ dir: the directory to byte-compile
87
+ maxlevels: maximum recursion level (default `sys.getrecursionlimit()`)
88
+ ddir: the directory that will be prepended to the path to the
89
+ file as it is compiled into each byte-code file.
90
+ force: if True, force compilation, even if timestamps are up-to-date
91
+ quiet: full output with False or 0, errors only with 1,
92
+ no output with 2
93
+ legacy: if True, produce legacy pyc paths instead of PEP 3147 paths
94
+ optimize: int or list of optimization levels or -1 for level of
95
+ the interpreter. Multiple levels leads to multiple compiled
96
+ files each with one optimization level.
97
+ workers: maximum number of parallel workers
98
+ invalidation_mode: how the up-to-dateness of the pyc will be checked
99
+ stripdir: part of path to left-strip from source file path
100
+ prependdir: path to prepend to beginning of original file path, applied
101
+ after stripdir
102
+ limit_sl_dest: ignore symlinks if they are pointing outside of
103
+ the defined path
104
+ hardlink_dupes: hardlink duplicated pyc files
105
+ loader_override: loader type to use instead of default SourceFileLoader
106
+ strict_compile: Whether to use the strict compiler instead of the default.
107
+ """
108
+ poolexecutor = None
109
+ if ddir is not None and (stripdir is not None or prependdir is not None):
110
+ raise ValueError(
111
+ (
112
+ "Destination dir (ddir) cannot be used "
113
+ "in combination with stripdir or prependdir"
114
+ )
115
+ )
116
+ if ddir is not None:
117
+ stripdir = dir
118
+ prependdir = ddir
119
+ ddir = None
120
+ if workers < 0:
121
+ raise ValueError("workers must be greater or equal to 0")
122
+ if workers != 1:
123
+ # Check if this is a system where ProcessPoolExecutor can function.
124
+ from concurrent.futures.process import _check_system_limits
125
+
126
+ try:
127
+ _check_system_limits()
128
+ except NotImplementedError:
129
+ workers = 1
130
+ else:
131
+ from concurrent.futures import ProcessPoolExecutor
132
+
133
+ poolexecutor = ProcessPoolExecutor
134
+ if maxlevels is None:
135
+ maxlevels = sys.getrecursionlimit()
136
+ files = _walk_dir(dir, quiet=quiet, maxlevels=maxlevels)
137
+ success = True
138
+ if workers != 1 and poolexecutor is not None:
139
+ # If workers == 0, let ProcessPoolExecutor choose
140
+ workers = workers or None
141
+ with poolexecutor(max_workers=workers) as executor:
142
+ results = executor.map(
143
+ partial(
144
+ compile_file,
145
+ ddir=ddir,
146
+ force=force,
147
+ rx=rx,
148
+ quiet=quiet,
149
+ legacy=legacy,
150
+ optimize=optimize,
151
+ invalidation_mode=invalidation_mode,
152
+ stripdir=stripdir,
153
+ prependdir=prependdir,
154
+ limit_sl_dest=limit_sl_dest,
155
+ hardlink_dupes=hardlink_dupes,
156
+ loader_override=loader_override,
157
+ strict_compile=strict_compile,
158
+ ),
159
+ files,
160
+ )
161
+ success = min(results, default=True)
162
+ else:
163
+ for file in files:
164
+ if not compile_file(
165
+ file,
166
+ ddir,
167
+ force,
168
+ rx,
169
+ quiet,
170
+ legacy,
171
+ optimize,
172
+ invalidation_mode,
173
+ stripdir=stripdir,
174
+ prependdir=prependdir,
175
+ limit_sl_dest=limit_sl_dest,
176
+ hardlink_dupes=hardlink_dupes,
177
+ loader_override=loader_override,
178
+ strict_compile=strict_compile,
179
+ ):
180
+ success = False
181
+ return success
182
+
183
+
184
+ def compile_file(
185
+ fullname: str,
186
+ ddir: str | None = None,
187
+ force: bool = False,
188
+ rx: Pattern | None = None,
189
+ quiet: int = 0,
190
+ legacy: bool = False,
191
+ optimize: int | list[int] = -1,
192
+ invalidation_mode: py_compile.PycInvalidationMode | None = None,
193
+ *,
194
+ stripdir: str | None = None,
195
+ prependdir: str | None = None,
196
+ limit_sl_dest: str | None = None,
197
+ hardlink_dupes: bool = False,
198
+ loader_override: Type[PySourceFileLoader] | None = None,
199
+ strict_compile: bool = False,
200
+ ) -> bool:
201
+ """Byte-compile one file.
202
+
203
+ Arguments (only fullname is required):
204
+
205
+ fullname: the file to byte-compile
206
+ ddir: if given, the directory name compiled in to the
207
+ byte-code file.
208
+ force: if True, force compilation, even if timestamps are up-to-date
209
+ quiet: full output with False or 0, errors only with 1,
210
+ no output with 2
211
+ legacy: if True, produce legacy pyc paths instead of PEP 3147 paths
212
+ optimize: int or list of optimization levels or -1 for level of
213
+ the interpreter. Multiple levels leads to multiple compiled
214
+ files each with one optimization level.
215
+ invalidation_mode: how the up-to-dateness of the pyc will be checked
216
+ stripdir: part of path to left-strip from source file path
217
+ prependdir: path to prepend to beginning of original file path, applied
218
+ after stripdir
219
+ limit_sl_dest: ignore symlinks if they are pointing outside of
220
+ the defined path.
221
+ hardlink_dupes: hardlink duplicated pyc files
222
+ loader_override: loader type to use instead of default SourceFileLoader
223
+ """
224
+
225
+ if ddir is not None and (stripdir is not None or prependdir is not None):
226
+ raise ValueError(
227
+ (
228
+ "Destination dir (ddir) cannot be used "
229
+ "in combination with stripdir or prependdir"
230
+ )
231
+ )
232
+
233
+ success = True
234
+ if quiet < 2 and isinstance(fullname, os.PathLike):
235
+ fullname = os.fspath(fullname)
236
+ name = os.path.basename(fullname)
237
+
238
+ dfile = None
239
+
240
+ if ddir is not None:
241
+ dfile = os.path.join(ddir, name)
242
+
243
+ if stripdir is not None:
244
+ fullname_parts = fullname.split(os.path.sep)
245
+ stripdir_parts = stripdir.split(os.path.sep)
246
+ ddir_parts = list(fullname_parts)
247
+
248
+ for spart, opart in zip(stripdir_parts, fullname_parts):
249
+ if spart == opart:
250
+ ddir_parts.remove(spart)
251
+
252
+ dfile = os.path.join(*ddir_parts)
253
+
254
+ if prependdir is not None:
255
+ if dfile is None:
256
+ dfile = os.path.join(prependdir, fullname)
257
+ else:
258
+ dfile = os.path.join(prependdir, dfile)
259
+
260
+ if isinstance(optimize, int):
261
+ optimize = [optimize]
262
+
263
+ # Use set() to remove duplicates.
264
+ # Use sorted() to create pyc files in a deterministic order.
265
+ optimize = sorted(set(optimize))
266
+
267
+ if hardlink_dupes and len(optimize) < 2:
268
+ raise ValueError(
269
+ "Hardlinking of duplicated bytecode makes sense "
270
+ "only for more than one optimization level"
271
+ )
272
+
273
+ if rx is not None:
274
+ mo = rx.search(fullname)
275
+ if mo:
276
+ return success
277
+
278
+ if limit_sl_dest is not None and os.path.islink(fullname):
279
+ if Path(limit_sl_dest).resolve() not in Path(fullname).resolve().parents:
280
+ return success
281
+
282
+ opt_cfiles = {}
283
+
284
+ if os.path.isfile(fullname):
285
+ for opt_level in optimize:
286
+ if legacy:
287
+ opt_cfiles[opt_level] = fullname + "c"
288
+ else:
289
+ if opt_level >= 0:
290
+ opt = opt_level if opt_level >= 1 else ""
291
+ cfile = importlib.util.cache_from_source(fullname, optimization=opt)
292
+ opt_cfiles[opt_level] = cfile
293
+ else:
294
+ cfile = importlib.util.cache_from_source(fullname)
295
+ opt_cfiles[opt_level] = cfile
296
+
297
+ tail = name[-3:]
298
+ if tail == ".py":
299
+ if not force:
300
+ try:
301
+ mtime = int(os.stat(fullname).st_mtime)
302
+ expect = struct.pack(
303
+ "<4sLL", importlib.util.MAGIC_NUMBER, 0, mtime & 0xFFFF_FFFF
304
+ )
305
+ for cfile in opt_cfiles.values():
306
+ with open(cfile, "rb") as chandle:
307
+ actual = chandle.read(12)
308
+ if expect != actual:
309
+ break
310
+ else:
311
+ return success
312
+ except OSError:
313
+ pass
314
+ if not quiet:
315
+ print("Compiling {!r}...".format(fullname))
316
+ ok = 0
317
+ try:
318
+ for index, opt_level in enumerate(optimize):
319
+ cfile = opt_cfiles[opt_level]
320
+ if strict_compile:
321
+ ok = strict_compile_fn(
322
+ fullname,
323
+ cfile,
324
+ dfile,
325
+ True,
326
+ optimize=opt_level,
327
+ invalidation_mode=invalidation_mode,
328
+ loader_override=loader_override,
329
+ )
330
+ else:
331
+ ok = py_compile.compile(
332
+ fullname,
333
+ cfile,
334
+ dfile,
335
+ True,
336
+ optimize=opt_level,
337
+ invalidation_mode=invalidation_mode,
338
+ )
339
+ if index > 0 and hardlink_dupes:
340
+ previous_cfile = opt_cfiles[optimize[index - 1]]
341
+ if filecmp.cmp(cfile, previous_cfile, shallow=False):
342
+ os.unlink(cfile)
343
+ os.link(previous_cfile, cfile)
344
+ except py_compile.PyCompileError as err:
345
+ success = False
346
+ if quiet >= 2:
347
+ return success
348
+ elif quiet:
349
+ print("*** Error compiling {!r}...".format(fullname))
350
+ else:
351
+ print("*** ", end="")
352
+ # escape non-printable characters in msg
353
+ encoding = sys.stdout.encoding or sys.getdefaultencoding()
354
+ msg = err.msg.encode(encoding, errors="backslashreplace").decode(
355
+ encoding
356
+ )
357
+ print(msg)
358
+ except (SyntaxError, UnicodeError, OSError) as e:
359
+ success = False
360
+ if quiet >= 2:
361
+ return success
362
+ elif quiet:
363
+ print("*** Error compiling {!r}...".format(fullname))
364
+ else:
365
+ print("*** ", end="")
366
+ print(e.__class__.__name__ + ":", e)
367
+ else:
368
+ if ok == 0:
369
+ success = False
370
+ return success
371
+
372
+
373
+ def compile_path(
374
+ skip_curdir: int = 1,
375
+ maxlevels: int = 0,
376
+ force: bool = False,
377
+ quiet: int = 0,
378
+ legacy: bool = False,
379
+ optimize: int | list[int] = -1,
380
+ invalidation_mode: py_compile.PycInvalidationMode | None = None,
381
+ loader_override: Type[PySourceFileLoader] | None = None,
382
+ strict_compile: bool = False,
383
+ ) -> bool:
384
+ """Byte-compile all module on sys.path.
385
+
386
+ Arguments (all optional):
387
+
388
+ skip_curdir: if true, skip current directory (default True)
389
+ maxlevels: max recursion level (default 0)
390
+ force: as for compile_dir() (default False)
391
+ quiet: as for compile_dir() (default 0)
392
+ legacy: as for compile_dir() (default False)
393
+ optimize: as for compile_dir() (default -1)
394
+ invalidation_mode: as for compiler_dir()
395
+ loader_override: as for compiler_dir()
396
+ """
397
+ success = True
398
+ for dir in sys.path:
399
+ if (not dir or dir == os.curdir) and skip_curdir:
400
+ if quiet < 2:
401
+ print("Skipping current directory")
402
+ else:
403
+ success = success and compile_dir(
404
+ dir,
405
+ maxlevels,
406
+ None,
407
+ force,
408
+ quiet=quiet,
409
+ legacy=legacy,
410
+ optimize=optimize,
411
+ invalidation_mode=invalidation_mode,
412
+ loader_override=loader_override,
413
+ strict_compile=strict_compile,
414
+ )
415
+ return success
416
+
417
+
418
+ def main() -> bool:
419
+ """Script main program."""
420
+ import argparse
421
+
422
+ parser = argparse.ArgumentParser(
423
+ description="Utilities to support installing Python libraries."
424
+ )
425
+ parser.add_argument(
426
+ "-l",
427
+ action="store_const",
428
+ const=0,
429
+ default=None,
430
+ dest="maxlevels",
431
+ help="don't recurse into subdirectories",
432
+ )
433
+ parser.add_argument(
434
+ "-r",
435
+ type=int,
436
+ dest="recursion",
437
+ help=(
438
+ "control the maximum recursion level. "
439
+ "if `-l` and `-r` options are specified, "
440
+ "then `-r` takes precedence."
441
+ ),
442
+ )
443
+ parser.add_argument(
444
+ "-f",
445
+ action="store_true",
446
+ dest="force",
447
+ help="force rebuild even if timestamps are up to date",
448
+ )
449
+ parser.add_argument(
450
+ "-q",
451
+ action="count",
452
+ dest="quiet",
453
+ default=0,
454
+ help="output only error messages; -qq will suppress "
455
+ "the error messages as well.",
456
+ )
457
+ parser.add_argument(
458
+ "-b",
459
+ action="store_true",
460
+ dest="legacy",
461
+ help="use legacy (pre-PEP3147) compiled file locations",
462
+ )
463
+ parser.add_argument(
464
+ "-d",
465
+ metavar="DESTDIR",
466
+ dest="ddir",
467
+ default=None,
468
+ help=(
469
+ "directory to prepend to file paths for use in "
470
+ "compile-time tracebacks and in runtime "
471
+ "tracebacks in cases where the source file is "
472
+ "unavailable"
473
+ ),
474
+ )
475
+ parser.add_argument(
476
+ "-s",
477
+ metavar="STRIPDIR",
478
+ dest="stripdir",
479
+ default=None,
480
+ help=(
481
+ "part of path to left-strip from path "
482
+ "to source file - for example buildroot. "
483
+ "`-d` and `-s` options cannot be "
484
+ "specified together."
485
+ ),
486
+ )
487
+ parser.add_argument(
488
+ "-p",
489
+ metavar="PREPENDDIR",
490
+ dest="prependdir",
491
+ default=None,
492
+ help=(
493
+ "path to add as prefix to path "
494
+ "to source file - for example / to make "
495
+ "it absolute when some part is removed "
496
+ "by `-s` option. "
497
+ "`-d` and `-p` options cannot be "
498
+ "specified together."
499
+ ),
500
+ )
501
+ parser.add_argument(
502
+ "-x",
503
+ metavar="REGEXP",
504
+ dest="rx",
505
+ default=None,
506
+ help=(
507
+ "skip files matching the regular expression; "
508
+ "the regexp is searched for in the full path "
509
+ "of each file considered for compilation"
510
+ ),
511
+ )
512
+ parser.add_argument(
513
+ "-i",
514
+ metavar="FILE",
515
+ dest="flist",
516
+ help=(
517
+ "add all the files and directories listed in "
518
+ "FILE to the list considered for compilation; "
519
+ 'if "-", names are read from stdin'
520
+ ),
521
+ )
522
+ parser.add_argument(
523
+ "compile_dest",
524
+ metavar="FILE|DIR",
525
+ nargs="*",
526
+ help=(
527
+ "zero or more file and directory names "
528
+ "to compile; if no arguments given, defaults "
529
+ "to the equivalent of -l sys.path"
530
+ ),
531
+ )
532
+ parser.add_argument(
533
+ "-j", "--workers", default=1, type=int, help="Run compileall concurrently"
534
+ )
535
+ invalidation_modes = [
536
+ mode.name.lower().replace("_", "-") for mode in py_compile.PycInvalidationMode
537
+ ]
538
+ parser.add_argument(
539
+ "--invalidation-mode",
540
+ choices=sorted(invalidation_modes),
541
+ help=(
542
+ "set .pyc invalidation mode; defaults to "
543
+ '"checked-hash" if the SOURCE_DATE_EPOCH '
544
+ "environment variable is set, and "
545
+ '"timestamp" otherwise.'
546
+ ),
547
+ )
548
+ parser.add_argument(
549
+ "-o",
550
+ action="append",
551
+ type=int,
552
+ dest="opt_levels",
553
+ help=(
554
+ "Optimization levels to run compilation with. "
555
+ "Default is -1 which uses the optimization level "
556
+ "of the Python interpreter itself (see -O)."
557
+ ),
558
+ )
559
+ parser.add_argument(
560
+ "-e",
561
+ metavar="DIR",
562
+ dest="limit_sl_dest",
563
+ help="Ignore symlinks pointing outsite of the DIR",
564
+ )
565
+ parser.add_argument(
566
+ "--hardlink-dupes",
567
+ action="store_true",
568
+ dest="hardlink_dupes",
569
+ help="Hardlink duplicated pyc files",
570
+ )
571
+ parser.add_argument(
572
+ "--python-loader",
573
+ action="store_true",
574
+ dest="use_py_loader",
575
+ help=("use loader that uses CinderX compiler"),
576
+ )
577
+ parser.add_argument(
578
+ "--strict-compile",
579
+ action="store_true",
580
+ dest="strict_compile",
581
+ help=("use the bytecode compiler bundled with the strict-module loader"),
582
+ )
583
+
584
+ args = parser.parse_args()
585
+ compile_dests = args.compile_dest
586
+
587
+ if args.rx:
588
+ import re
589
+
590
+ args.rx = re.compile(args.rx)
591
+
592
+ if args.limit_sl_dest == "":
593
+ args.limit_sl_dest = None
594
+
595
+ if args.recursion is not None:
596
+ maxlevels = args.recursion
597
+ else:
598
+ maxlevels = args.maxlevels
599
+
600
+ if args.opt_levels is None:
601
+ args.opt_levels = [-1]
602
+
603
+ if len(args.opt_levels) == 1 and args.hardlink_dupes:
604
+ parser.error(
605
+ (
606
+ "Hardlinking of duplicated bytecode makes sense "
607
+ "only for more than one optimization level."
608
+ )
609
+ )
610
+
611
+ if args.ddir is not None and (
612
+ args.stripdir is not None or args.prependdir is not None
613
+ ):
614
+ parser.error("-d cannot be used in combination with -s or -p")
615
+
616
+ # if flist is provided then load it
617
+ if args.flist:
618
+ try:
619
+ with (
620
+ sys.stdin if args.flist == "-" else open(args.flist, encoding="utf-8")
621
+ ) as f:
622
+ for line in f:
623
+ compile_dests.append(line.strip())
624
+ except OSError:
625
+ if args.quiet < 2:
626
+ print("Error reading file list {}".format(args.flist))
627
+ return False
628
+
629
+ if args.invalidation_mode:
630
+ ivl_mode = args.invalidation_mode.replace("-", "_").upper()
631
+ invalidation_mode = py_compile.PycInvalidationMode[ivl_mode]
632
+ else:
633
+ invalidation_mode = None
634
+
635
+ success = True
636
+ loader_override = None
637
+ if args.use_py_loader:
638
+ loader_override = PySourceFileLoader
639
+ sys.setrecursionlimit(sys.getrecursionlimit() * 100)
640
+ strict_compile = args.strict_compile
641
+ try:
642
+ if compile_dests:
643
+ for dest in compile_dests:
644
+ if os.path.isfile(dest):
645
+ if not compile_file(
646
+ dest,
647
+ args.ddir,
648
+ args.force,
649
+ args.rx,
650
+ args.quiet,
651
+ args.legacy,
652
+ invalidation_mode=invalidation_mode,
653
+ stripdir=args.stripdir,
654
+ prependdir=args.prependdir,
655
+ optimize=args.opt_levels,
656
+ limit_sl_dest=args.limit_sl_dest,
657
+ hardlink_dupes=args.hardlink_dupes,
658
+ loader_override=loader_override,
659
+ strict_compile=strict_compile,
660
+ ):
661
+ success = False
662
+ else:
663
+ appended = False
664
+ try:
665
+ if strict_compile and dest not in sys.path:
666
+ sys.path.append(dest)
667
+ appended = True
668
+
669
+ if not compile_dir(
670
+ dest,
671
+ maxlevels,
672
+ args.ddir,
673
+ args.force,
674
+ args.rx,
675
+ args.quiet,
676
+ args.legacy,
677
+ workers=args.workers,
678
+ invalidation_mode=invalidation_mode,
679
+ stripdir=args.stripdir,
680
+ prependdir=args.prependdir,
681
+ optimize=args.opt_levels,
682
+ limit_sl_dest=args.limit_sl_dest,
683
+ hardlink_dupes=args.hardlink_dupes,
684
+ loader_override=loader_override,
685
+ strict_compile=strict_compile,
686
+ ):
687
+ success = False
688
+ finally:
689
+ if appended:
690
+ sys.path.remove(dest)
691
+ return success
692
+ else:
693
+ return compile_path(
694
+ legacy=args.legacy,
695
+ force=args.force,
696
+ quiet=args.quiet,
697
+ invalidation_mode=invalidation_mode,
698
+ loader_override=loader_override,
699
+ strict_compile=strict_compile,
700
+ )
701
+ except KeyboardInterrupt:
702
+ if args.quiet < 2:
703
+ print("\n[interrupted]")
704
+ return False
705
+ return True
706
+
707
+
708
+ if __name__ == "__main__":
709
+ exit_status = int(not main())
710
+ sys.exit(exit_status)