]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-40334: Allow to run make regen-pegen without distutils (GH-19684)
authorPablo Galindo <Pablogsal@gmail.com>
Thu, 23 Apr 2020 23:53:29 +0000 (00:53 +0100)
committerGitHub <noreply@github.com>
Thu, 23 Apr 2020 23:53:29 +0000 (00:53 +0100)
Tools/peg_generator/pegen/__main__.py
Tools/peg_generator/pegen/build.py

index 874b307ab5c18a670f35c6625141fed9a6548bf6..6696d135a8b6954a97e7b7757c0ee32ea9d2933b 100755 (executable)
@@ -11,11 +11,6 @@ import time
 import token
 import traceback
 
-from typing import Final
-
-from pegen.build import build_parser_and_generator
-from pegen.testutil import print_memstats
-
 
 argparser = argparse.ArgumentParser(
     prog="pegen", description="Experimental PEG-like parser generator"
@@ -52,6 +47,9 @@ argparser.add_argument(
 
 
 def main() -> None:
+    from pegen.build import build_parser_and_generator
+    from pegen.testutil import print_memstats
+
     args = argparser.parse_args()
     verbose = args.verbose
     verbose_tokenizer = verbose >= 3
@@ -133,4 +131,7 @@ def main() -> None:
 
 
 if __name__ == "__main__":
+    if sys.version_info < (3, 8):
+        print("ERROR: using pegen requires at least Python 3.8!", file=sys.stderr)
+        sys.exit(1)
     main()
index 6ead94796f7458c25ef916e9469cc88000d2ab22..0ecb37051033c7a354687907b06c55db4a883f4c 100644 (file)
@@ -6,12 +6,6 @@ import sysconfig
 
 from typing import Optional, Tuple
 
-import distutils.log
-from distutils.core import Distribution, Extension
-from distutils.command.clean import clean  # type: ignore
-from distutils.command.build_ext import build_ext  # type: ignore
-from distutils.tests.support import fixup_build_ext
-
 from pegen.c_generator import CParserGenerator
 from pegen.grammar import Grammar
 from pegen.grammar_parser import GeneratedParser as GrammarParser
@@ -47,6 +41,12 @@ def compile_c_extension(
     If *build_dir* is provided, that path will be used as the temporary build directory
     of distutils (this is useful in case you want to use a temporary directory).
     """
+    import distutils.log
+    from distutils.core import Distribution, Extension
+    from distutils.command.clean import clean  # type: ignore
+    from distutils.command.build_ext import build_ext  # type: ignore
+    from distutils.tests.support import fixup_build_ext
+
     if verbose:
         distutils.log.set_verbosity(distutils.log.DEBUG)