ifeq ($(UNAME_S),Darwin)
PYTHON ?= ../../python.exe
endif
-
+VENVDIR ?= ./venv
+VENVPYTHON ?= $(VENVDIR)/bin/python
CPYTHON ?= ../../Lib
MYPY ?= mypy
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)
.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
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 \
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
-#!/usr/bin/env python3.9
+#!/usr/bin/env python3
import argparse
import ast
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