8000 Simplify Makefile. Remove Conda. Use requirements.txt. Remove pointle… · pyscript/pyscript@56b1b1a · GitHub
[go: up one dir, main page]

Skip to content

Commit 56b1b1a

Browse files
committed
Simplify Makefile. Remove Conda. Use requirements.txt. Remove pointless type annotations. Update CI tests.yml.
1 parent 4256a81 commit 56b1b1a

File tree

5 files changed

+78
-111
lines changed

5 files changed

+78
-111
lines changed

.github/workflows/test.yml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,25 @@ jobs:
5757
- name: setup Miniconda
5858
uses: conda-incubator/setup-miniconda@v2
5959

60-
- name: Setup Environment
61-
run: make setup
60+
- name: Create and activate virtual environment
61+
run: |
62+
python3 -m venv test_venv
63+
source test_venv/bin/activate
64+
echo "venv: " $VIRTUAL_ENV
65+
66+
- name: Setup dependencies in virtual environment
67+
run: |
68+
source test_venv/bin/activate
69+
make setup
6270
6371
- name: Build
6472
run: make build
6573

6674
- name: Integration Tests
6775
#run: make test-integration-parallel
68-
run: make test-integration
76+
run: |
77+
source test_venv/bin/activate
78+
make test-integration
6979
7080
- uses: actions/upload-artifact@v3
7181
with:

Makefile

Lines changed: 51 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,122 +1,92 @@
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-
141
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"
2418

2519
.PHONY: check-node
2620
check-node:
2721
@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"; \
2923
false; \
3024
fi
3125

3226
.PHONY: check-npm
3327
check-npm:
3428
@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"; \
3630
false; \
3731
fi
3832

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
4042
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
4450

51+
# Clean up generated assets.
4552
clean:
4653
find . -name \*.py[cod] -delete
47-
rm -rf .pytest_cache .coverage coverage.xml
48-
49-
clean-all: clean
5054
rm -rf $(env) *.egg-info
55+
rm -rf .pytest_cache .coverage coverage.xml
5156

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.
5958
build:
6059
cd pyscript.core && npm run build
6160

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).
6462
precommit-check:
6563
pre-commit run --all-files
6664

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.
8966
test-integration:
9067
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
9269

93-
# run all integration tests *except examples* in parallel (examples use too much memory)
70+
# Run all integration tests in parallel.
9471
test-integration-parallel:
9572
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
10274

103-
fmt: fmt-py fmt-ts
75+
# Format the code.
76+
fmt: fmt-py
10477
@echo "Format completed"
10578

106-
fmt-check: fmt-ts-check fmt-py-check
79+
# Check the code formatting.
80+
fmt-check: fmt-py-check
10781
@echo "Format check completed"
10882

109-
fmt-ts:
110-
npm run format
111-
112-
fmt-ts-check:
113-
npm run format:check
114-
83+
# Format Python code.
11584
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 .
11887

88+
# Check the format of Python code.
11989
fmt-py-check:
120-
$(conda_run) black -l 88 --check .
90+
black -l 88 --check .
12191

12292
.PHONY: $(MAKECMDGOALS)

environment.yml

Lines changed: 0 additions & 26 deletions
This file was deleted.

pyscript.core/tests/integration/support.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ def check_tutor_generated_code(self, modules_to_check=None):
652652
) # 120 iters of 1/4 second
653653

654654

655-
def wait_for_render(page, selector, pattern, timeout_seconds: int | None = None):
655+
def wait_for_render(page, selector, pattern, timeout_seconds=None):
656656
"""
657657
Assert that rendering inserts data into the page as expected: search the
658658
DOM from within the timing loop for a string that is not present in the

requirements.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
black
2+
isort
3+
pytest==7.1.2
4+
pre-commit
5+
playwright==1.33.0
6+
pytest-playwright==0.3.3
7+
pytest-xdist==3.3.0
8+
pexpect
9+
pyodide_py==0.24.1
10+
micropip
11+
toml
12+
numpy
13+
pillow

0 commit comments

Comments
 (0)
0