|
1 |
| -tag := latest |
2 |
| -git_hash ?= $(shell git log -1 --pretty=format:%h) |
3 |
| - |
4 |
| -base_dir ?= $(shell git rev-parse --show-toplevel) |
5 |
| -examples ?= ../$(base_dir)/examples |
6 |
| -app_dir ?= $(shell git rev-parse --show-prefix) |
7 |
| - |
8 |
| -CONDA_EXE := conda |
9 |
| -CONDA_ENV ?= $(base_dir)/env |
10 |
| -env := $(CONDA_ENV) |
11 |
| -conda_run := $(CONDA_EXE) run -p $(env) |
12 |
| -PYTEST_EXE := $(CONDA_ENV)/bin/pytest |
13 |
| - |
14 | 1 | MIN_NODE_VER := 14
|
15 |
| -MIN_NPM_VER := 6 |
16 |
| -NODE_VER := $(shell node -v | cut -d. -f1 | sed 's/^v\(.*\)/\1/') |
17 |
| -NPM_VER := $(shell npm -v | cut -d. -f1) |
18 |
| - |
19 |
| -ifeq ($(shell uname -s), Darwin) |
20 |
| - SED_I_ARG := -i '' |
21 |
| -else |
22 |
| - SED_I_ARG := -i |
23 |
| -endif |
| 2 | +MIN_NPM_VER := 6 |
| 3 | +MIN_PY_VER := 3.8 |
| 4 | +NODE_VER := $(shell node -v | cut -d. -f1 | sed 's/^v\(.*\)/\1/') |
| 5 | +NPM_VER := $(shell npm -v | cut -d. -f1) |
| 6 | +PY_VER := $(shell python -c "import sys;print(sys.version.split()[0])") |
| 7 | +PY_OK := $(shell python -c "from packaging import version;print(int(version.parse('$(PY_VER)') >= version.parse('$(MIN_PY_VER)')))") |
| 8 | + |
| 9 | +all: |
| 10 | + @echo "\nThere is no default Makefile target right now. Try:\n" |
| 11 | + @echo "make setup - check your environment and install the dependencies." |
| 12 | + @echo "make clean - clean up auto-generated assets." |
| 13 | + @echo "make build - build PyScript." |
| 14 | + @echo "make precommit-check - run the precommit checks (run eslint)." |
| 15 | + @echo "make test-integration - run all integration tests sequentially." |
| 16 | + @echo "make fmt - format the code." |
| 17 | + @echo "make fmt-check - check the code formatting.\n" |
24 | 18 |
|
25 | 19 | .PHONY: check-node
|
26 | 20 | check-node:
|
27 | 21 | @if [ $(NODE_VER) -lt $(MIN_NODE_VER) ]; then \
|
28 |
| - echo "Build requires Node $(MIN_NODE_VER).x or higher: $(NODE_VER) detected"; \ |
| 22 | + echo "\033[0;31mBuild requires Node $(MIN_NODE_VER).x or higher: $(NODE_VER) detected.\033[0m"; \ |
29 | 23 | false; \
|
30 | 24 | fi
|
31 | 25 |
|
32 | 26 | .PHONY: check-npm
|
33 | 27 | check-npm:
|
34 | 28 | @if [ $(NPM_VER) -lt $(MIN_NPM_VER) ]; then \
|
35 |
| - echo "Build requires Node $(MIN_NPM_VER).x or higher: $(NPM_VER) detected"; \ |
| 29 | + echo "\033[0;31mBuild requires Node $(MIN_NPM_VER).x or higher: $(NPM_VER) detected.\033[0m"; \ |
36 | 30 | false; \
|
37 | 31 | fi
|
38 | 32 |
|
39 |
| -setup: check-node check-npm |
| 33 | +.PHONY: check-python |
| 34 | +check-python: |
| 35 | + @if [ $(PY_OK) -eq 0 ]; then \ |
| 36 | + echo "\033[0;31mRequires Python $(MIN_PY_VER).x or higher: $(PY_VER) detected.\033[0m"; \ |
| 37 | + false; \ |
| 38 | + fi |
| 39 | + |
| 40 | +# Check the environment, install the dependencies. |
| 41 | +setup: check-node check-npm check-python |
40 | 42 | cd pyscript.core && npm install && cd ..
|
41 |
| - $(CONDA_EXE) env $(shell [ -d $(env) ] && echo update || echo create) -p $(env) --file environment.yml |
42 |
| - $(conda_run) playwright install |
43 |
| - $(CONDA_EXE) install -c anaconda pytest -y |
| 43 | +ifeq ($(VIRTUAL_ENV),) |
| 44 | + @echo "\n\n\033[0;31mCannot install Python dependencies. Your virtualenv is not activated.\033[0m" |
| 45 | + false |
| 46 | +else |
| 47 | + python -m pip install -r requirements.txt |
| 48 | + playwright install |
| 49 | +endif |
44 | 50 |
|
| 51 | +# Clean up generated assets. |
45 | 52 | clean:
|
46 | 53 | find . -name \*.py[cod] -delete
|
47 |
| - rm -rf .pytest_cache .coverage coverage.xml |
48 |
| - |
49 |
| -clean-all: clean |
50 | 54 | rm -rf $(env) *.egg-info
|
| 55 | + rm -rf .pytest_cache .coverage coverage.xml |
51 | 56 |
|
52 |
| -shell: |
53 |
| - @export CONDA_ENV_PROMPT='<{name}>' |
54 |
| - @echo 'conda activate $(env)' |
55 |
| - |
56 |
| -dev: |
57 |
| - cd pyscript.core && npm run dev |
58 |
| - |
| 57 | +# Build PyScript. |
59 | 58 | build:
|
60 | 59 | cd pyscript.core && npm run build
|
61 | 60 |
|
62 |
| -# use the following rule to do all the checks done by precommit: in |
63 |
| -# particular, use this if you want to run eslint. |
| 61 | +# Run the precommit checks (run eslint). |
64 | 62 | precommit-check:
|
65 | 63 | pre-commit run --all-files
|
66 | 64 |
|
67 |
| -examples: |
68 |
| - mkdir -p ./examples |
69 |
| - cp -r ../examples/* ./examples |
70 |
| - chmod -R 755 examples |
71 |
| - find ./examples/toga -type f -name '*.html' -exec sed $(SED_I_ARG) s+https://pyscript.net/latest/+../../build/+g {} \; |
72 |
| - find ./examples/webgl -type f -name '*.html' -exec sed $(SED_I_ARG) s+https://pyscript.net/latest/+../../../build/+g {} \; |
73 |
| - find ./examples -type f -name '*.html' -exec sed $(SED_I_ARG) s+https://pyscript.net/latest/+../build/+g {} \; |
74 |
| - npm run build |
75 |
| - rm -rf ./examples/build |
76 |
| - mkdir -p ./examples/build |
77 |
| - cp -R ./build/* ./examples/build |
78 |
| - @echo "To serve examples run: $(conda_run) python -m http.server 8080 --directory examples" |
79 |
| - |
80 |
| -# run prerequisites and serve pyscript examples at http://localhost:8000/examples/ |
81 |
| -run-examples: setup build examples |
82 |
| - make examples |
83 |
| - npm install |
84 |
| - make dev |
85 |
| - |
86 |
| -# run all integration tests *including examples* sequentially |
87 |
| -# TODO: (fpliger) The cd pyscript.core before running the tests shouldn't be needed but for |
88 |
| -# but for some reason it seems to bother pytest tmppaths (or test cache?). Unclear. |
| 65 | +# Run all integration tests sequentially. |
89 | 66 | test-integration:
|
90 | 67 | mkdir -p test_results
|
91 |
| - $(PYTEST_EXE) -vv $(ARGS) pyscript.core/tests/integration/ --log-cli-level=warning --junitxml=test_results/integration.xml |
| 68 | + pytest -vv $(ARGS) pyscript.core/tests/integration/ --log-cli-level=warning --junitxml=test_results/integration.xml |
92 | 69 |
|
93 |
| -# run all integration tests *except examples* in parallel (examples use too much memory) |
| 70 | +# Run all integration tests in parallel. |
94 | 71 | test-integration-parallel:
|
95 | 72 | mkdir -p test_results
|
96 |
| - $(PYTEST_EXE) --numprocesses auto -vv $(ARGS) pyscript.core/tests/integration/ --log-cli-level=warning --junitxml=test_results/integration.xml |
97 |
| - |
98 |
| -# run integration tests on only examples sequentially (to avoid running out of memory) |
99 |
| -test-examples: |
100 |
| - mkdir -p test_results |
101 |
| - $(PYTEST_EXE) -vv $(ARGS) pyscript.core/tests/integration/ --log-cli-level=warning --junitxml=test_results/integration.xml -k 'zz_examples' |
| 73 | + pytest --numprocesses auto -vv $(ARGS) pyscript.core/tests/integration/ --log-cli-level=warning --junitxml=test_results/integration.xml |
102 | 74 |
|
103 |
| -fmt: fmt-py fmt-ts |
| 75 | +# Format the code. |
| 76 | +fmt: fmt-py |
104 | 77 | @echo "Format completed"
|
105 | 78 |
|
106 |
| -fmt-check: fmt-ts-check fmt-py-check |
| 79 | +# Check the code formatting. |
| 80 | +fmt-check: fmt-py-check |
107 | 81 | @echo "Format check completed"
|
108 | 82 |
|
109 |
| -fmt-ts: |
110 |
| - npm run format |
111 |
| - |
112 |
| -fmt-ts-check: |
113 |
| - npm run format:check |
114 |
| - |
| 83 | +# Format Python code. |
115 | 84 | fmt-py:
|
116 |
| - $(conda_run) black --skip-string-normalization . |
117 |
| - $(conda_run) isort --profile black . |
| 85 | + black -l 88 --skip-string-normalization . |
| 86 | + isort --profile black . |
118 | 87 |
|
| 88 | +# Check the format of Python code. |
119 | 89 | fmt-py-check:
|
120 |
| - $(conda_run) black -l 88 --check . |
| 90 | + black -l 88 --check . |
121 | 91 |
|
122 | 92 | .PHONY: $(MAKECMDGOALS)
|
0 commit comments