aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLysandros Nikolaou <lisandrosnik@gmail.com>2020-05-18 21:27:40 +0300
committerGitHub <noreply@github.com>2020-05-18 11:27:40 -0700
commitdc31800f86fbcd40ee616984820b885d8adaa6a7 (patch)
treeabb3f07fd5a54fb652cc91e192ebe89918903cc5 /Tools/peg_generator
parentbpo-40663: Correctly handle annotations with subscripts in ast_unparse.c (GH-... (diff)
downloadcpython-dc31800f86fbcd40ee616984820b885d8adaa6a7.tar.gz
cpython-dc31800f86fbcd40ee616984820b885d8adaa6a7.tar.bz2
cpython-dc31800f86fbcd40ee616984820b885d8adaa6a7.zip
bpo-40669: Install PEG benchmarking dependencies in a venv (GH-20183)
Create a `make venv` target, that creates a virtual environment and installs the dependency in that venv. `make time` and all the related targets are changed to use the virtual environment python. Automerge-Triggered-By: @pablogsal
Diffstat (limited to 'Tools/peg_generator')
-rw-r--r--Tools/peg_generator/.gitignore1
-rw-r--r--Tools/peg_generator/Makefile34
-rw-r--r--Tools/peg_generator/scripts/benchmark.py9
3 files changed, 29 insertions, 15 deletions
diff --git a/Tools/peg_generator/.gitignore b/Tools/peg_generator/.gitignore
index 91c41f89e8c..f25e54195e4 100644
--- a/Tools/peg_generator/.gitignore
+++ b/Tools/peg_generator/.gitignore
@@ -1,3 +1,4 @@
peg_extension/parse.c
data/xxl.py
+venv/
@data
diff --git a/Tools/peg_generator/Makefile b/Tools/peg_generator/Makefile
index c1219b92638..7b33a86b24a 100644
--- a/Tools/peg_generator/Makefile
+++ b/Tools/peg_generator/Makefile
@@ -5,7 +5,8 @@ endif
ifeq ($(UNAME_S),Darwin)
PYTHON ?= ../../python.exe
endif
-
+VENVDIR ?= ./venv
+VENVPYTHON ?= $(VENVDIR)/bin/python
CPYTHON ?= ../../Lib
MYPY ?= mypy
@@ -27,6 +28,7 @@ peg_extension/parse.c: $(GRAMMAR) $(TOKENS) pegen/*.py peg_extension/peg_extensi
clean:
-rm -f peg_extension/*.o peg_extension/*.so peg_extension/parse.c
-rm -f data/xxl.py
+ -rm -rf $(VENVDIR)
dump: peg_extension/parse.c
cat -n $(TESTFILE)
@@ -41,6 +43,12 @@ regen-metaparser: pegen/metagrammar.gram pegen/*.py
.PHONY: test
+venv:
+ $(PYTHON) -m venv $(VENVDIR)
+ $(VENVPYTHON) -m pip install -U pip setuptools
+ $(VENVPYTHON) -m pip install -U memory_profiler
+ @echo "The venv has been created in the $(VENVDIR) directory"
+
test: run
run: peg_extension/parse.c
@@ -61,22 +69,22 @@ stats: peg_extension/parse.c data/xxl.py
time: time_compile
-time_compile: peg_extension/parse.c data/xxl.py
- $(PYTHON) scripts/benchmark.py --parser=pegen --target=xxl compile
+time_compile: venv peg_extension/parse.c data/xxl.py
+ $(VENVPYTHON) scripts/benchmark.py --parser=pegen --target=xxl compile
-time_parse: peg_extension/parse.c data/xxl.py
- $(PYTHON) scripts/benchmark.py --parser=pegen --target=xxl parse
+time_parse: venv peg_extension/parse.c data/xxl.py
+ $(VENVPYTHON) scripts/benchmark.py --parser=pegen --target=xxl parse
-time_check: peg_extension/parse.c data/xxl.py
- $(PYTHON) scripts/benchmark.py --parser=pegen --target=xxl check
+time_check: venv peg_extension/parse.c data/xxl.py
+ $(VENVPYTHON) scripts/benchmark.py --parser=pegen --target=xxl check
time_stdlib: time_stdlib_compile
-time_stdlib_compile: data/xxl.py
- $(PYTHON) scripts/benchmark.py --parser=cpython --target=xxl compile
+time_stdlib_compile: venv peg_extension/parse.c data/xxl.py
+ $(VENVPYTHON) scripts/benchmark.py --parser=cpython --target=xxl compile
-time_stdlib_parse: data/xxl.py
- $(PYTHON) scripts/benchmark.py --parser=cpython --target=xxl parse
+time_stdlib_parse: venv peg_extension/parse.c data/xxl.py
+ $(VENVPYTHON) scripts/benchmark.py --parser=cpython --target=xxl parse
test_local:
$(PYTHON) scripts/test_parse_directory.py \
@@ -105,8 +113,8 @@ mypy: regen-metaparser
format-python:
black pegen scripts
-bench:
- $(PYTHON) scripts/benchmark.py --parser=pegen --target=stdlib check
+bench: venv
+ $(VENVPYTHON) scripts/benchmark.py --parser=pegen --target=stdlib check
format: format-python
diff --git a/Tools/peg_generator/scripts/benchmark.py b/Tools/peg_generator/scripts/benchmark.py
index d39ac3dca79..4942b99b661 100644
--- a/Tools/peg_generator/scripts/benchmark.py
+++ b/Tools/peg_generator/scripts/benchmark.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python3.9
+#!/usr/bin/env python3
import argparse
import ast
@@ -6,7 +6,12 @@ import sys
import os
from time import time
-import memory_profiler
+try:
+ import memory_profiler
+except ModuleNotFoundError:
+ print("Please run `make venv` to create a virtual environment and install"
+ " all the dependencies, before running this script.")
+ sys.exit(1)
sys.path.insert(0, os.getcwd())
from peg_extension import parse