summaryrefslogtreecommitdiffstats
path: root/Tools
diff options
context:
space:
mode:
authorPablo Galindo <Pablogsal@gmail.com>2020-04-23 23:53:29 (GMT)
committerGitHub <noreply@github.com>2020-04-23 23:53:29 (GMT)
commit50f28dea32c45e1a49b3bd07c874b4fa837a5e88 (patch)
tree433162193e8128163b826b53684085c83e5db701 /Tools
parent3e89251ba87333cdf0b41a90a7f5c83d1e2280fa (diff)
downloadcpython-50f28dea32c45e1a49b3bd07c874b4fa837a5e88.zip
cpython-50f28dea32c45e1a49b3bd07c874b4fa837a5e88.tar.gz
cpython-50f28dea32c45e1a49b3bd07c874b4fa837a5e88.tar.bz2
bpo-40334: Allow to run make regen-pegen without distutils (GH-19684)
Diffstat (limited to 'Tools')
-rwxr-xr-xTools/peg_generator/pegen/__main__.py11
-rw-r--r--Tools/peg_generator/pegen/build.py12
2 files changed, 12 insertions, 11 deletions
diff --git a/Tools/peg_generator/pegen/__main__.py b/Tools/peg_generator/pegen/__main__.py
index 874b307..6696d13 100755
--- a/Tools/peg_generator/pegen/__main__.py
+++ b/Tools/peg_generator/pegen/__main__.py
@@ -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()
diff --git a/Tools/peg_generator/pegen/build.py b/Tools/peg_generator/pegen/build.py
index 6ead947..0ecb370 100644
--- a/Tools/peg_generator/pegen/build.py
+++ b/Tools/peg_generator/pegen/build.py
@@ -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)