mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-19 18:27:29 -05:00
Simplify Makefile. Remove Conda. Use requirements.txt. Remove pointless type annotations. Update CI tests.yml. (#1793)
This commit is contained in:
committed by
GitHub
parent
aeb6f1a755
commit
13604e0a47
15
.github/workflows/test.yml
vendored
15
.github/workflows/test.yml
vendored
@@ -57,15 +57,24 @@ jobs:
|
|||||||
- name: setup Miniconda
|
- name: setup Miniconda
|
||||||
uses: conda-incubator/setup-miniconda@v2
|
uses: conda-incubator/setup-miniconda@v2
|
||||||
|
|
||||||
- name: Setup Environment
|
- name: Create and activate virtual environment
|
||||||
run: make setup
|
run: |
|
||||||
|
python3 -m venv test_venv
|
||||||
|
source test_venv/bin/activate
|
||||||
|
echo PATH=$PATH >> $GITHUB_ENV
|
||||||
|
echo VIRTUAL_ENV=$VIRTUAL_ENV >> $GITHUB_ENV
|
||||||
|
|
||||||
|
- name: Setup dependencies in virtual environment
|
||||||
|
run: |
|
||||||
|
make setup
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
run: make build
|
run: make build
|
||||||
|
|
||||||
- name: Integration Tests
|
- name: Integration Tests
|
||||||
#run: make test-integration-parallel
|
#run: make test-integration-parallel
|
||||||
run: make test-integration
|
run: |
|
||||||
|
make test-integration
|
||||||
|
|
||||||
- uses: actions/upload-artifact@v3
|
- uses: actions/upload-artifact@v3
|
||||||
with:
|
with:
|
||||||
|
|||||||
128
Makefile
128
Makefile
@@ -1,122 +1,92 @@
|
|||||||
tag := latest
|
MIN_NODE_VER := 20
|
||||||
git_hash ?= $(shell git log -1 --pretty=format:%h)
|
|
||||||
|
|
||||||
base_dir ?= $(shell git rev-parse --show-toplevel)
|
|
||||||
examples ?= ../$(base_dir)/examples
|
|
||||||
app_dir ?= $(shell git rev-parse --show-prefix)
|
|
||||||
|
|
||||||
CONDA_EXE := conda
|
|
||||||
CONDA_ENV ?= $(base_dir)/env
|
|
||||||
env := $(CONDA_ENV)
|
|
||||||
conda_run := $(CONDA_EXE) run -p $(env)
|
|
||||||
PYTEST_EXE := $(CONDA_ENV)/bin/pytest
|
|
||||||
|
|
||||||
MIN_NODE_VER := 14
|
|
||||||
MIN_NPM_VER := 6
|
MIN_NPM_VER := 6
|
||||||
|
MIN_PY3_VER := 8
|
||||||
NODE_VER := $(shell node -v | cut -d. -f1 | sed 's/^v\(.*\)/\1/')
|
NODE_VER := $(shell node -v | cut -d. -f1 | sed 's/^v\(.*\)/\1/')
|
||||||
NPM_VER := $(shell npm -v | cut -d. -f1)
|
NPM_VER := $(shell npm -v | cut -d. -f1)
|
||||||
|
PY3_VER := $(shell python3 -c "import sys;t='{v[1]}'.format(v=list(sys.version_info[:2]));print(t)")
|
||||||
|
PY_OK := $(shell python3 -c "print(int($(PY3_VER) >= $(MIN_PY3_VER)))")
|
||||||
|
|
||||||
ifeq ($(shell uname -s), Darwin)
|
all:
|
||||||
SED_I_ARG := -i ''
|
@echo "\nThere is no default Makefile target right now. Try:\n"
|
||||||
else
|
@echo "make setup - check your environment and install the dependencies."
|
||||||
SED_I_ARG := -i
|
@echo "make clean - clean up auto-generated assets."
|
||||||
endif
|
@echo "make build - build PyScript."
|
||||||
|
@echo "make precommit-check - run the precommit checks (run eslint)."
|
||||||
|
@echo "make test-integration - run all integration tests sequentially."
|
||||||
|
@echo "make fmt - format the code."
|
||||||
|
@echo "make fmt-check - check the code formatting.\n"
|
||||||
|
|
||||||
.PHONY: check-node
|
.PHONY: check-node
|
||||||
check-node:
|
check-node:
|
||||||
@if [ $(NODE_VER) -lt $(MIN_NODE_VER) ]; then \
|
@if [ $(NODE_VER) -lt $(MIN_NODE_VER) ]; then \
|
||||||
echo "Build requires Node $(MIN_NODE_VER).x or higher: $(NODE_VER) detected"; \
|
echo "\033[0;31mBuild requires Node $(MIN_NODE_VER).x or higher: $(NODE_VER) detected.\033[0m"; \
|
||||||
false; \
|
false; \
|
||||||
fi
|
fi
|
||||||
|
|
||||||
.PHONY: check-npm
|
.PHONY: check-npm
|
||||||
check-npm:
|
check-npm:
|
||||||
@if [ $(NPM_VER) -lt $(MIN_NPM_VER) ]; then \
|
@if [ $(NPM_VER) -lt $(MIN_NPM_VER) ]; then \
|
||||||
echo "Build requires Node $(MIN_NPM_VER).x or higher: $(NPM_VER) detected"; \
|
echo "\033[0;31mBuild requires Node $(MIN_NPM_VER).x or higher: $(NPM_VER) detected.\033[0m"; \
|
||||||
false; \
|
false; \
|
||||||
fi
|
fi
|
||||||
|
|
||||||
setup: check-node check-npm
|
.PHONY: check-python
|
||||||
cd pyscript.core && npm install && cd ..
|
check-python:
|
||||||
$(CONDA_EXE) env $(shell [ -d $(env) ] && echo update || echo create) -p $(env) --file environment.yml
|
@if [ $(PY_OK) -eq 0 ]; then \
|
||||||
$(conda_run) playwright install
|
echo "\033[0;31mRequires Python 3.$(MIN_PY3_VER).x or higher: 3.$(PY3_VER) detected.\033[0m"; \
|
||||||
$(CONDA_EXE) install -c anaconda pytest -y
|
false; \
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check the environment, install the dependencies.
|
||||||
|
setup: check-node check-npm check-python
|
||||||
|
cd pyscript.core && npm install && cd ..
|
||||||
|
ifeq ($(VIRTUAL_ENV),)
|
||||||
|
echo "\n\n\033[0;31mCannot install Python dependencies. Your virtualenv is not activated.\033[0m"
|
||||||
|
false
|
||||||
|
else
|
||||||
|
python -m pip install -r requirements.txt
|
||||||
|
playwright install
|
||||||
|
endif
|
||||||
|
|
||||||
|
# Clean up generated assets.
|
||||||
clean:
|
clean:
|
||||||
find . -name \*.py[cod] -delete
|
find . -name \*.py[cod] -delete
|
||||||
|
rm -rf $(env) *.egg-info
|
||||||
rm -rf .pytest_cache .coverage coverage.xml
|
rm -rf .pytest_cache .coverage coverage.xml
|
||||||
|
|
||||||
clean-all: clean
|
# Build PyScript.
|
||||||
rm -rf $(env) *.egg-info
|
|
||||||
|
|
||||||
shell:
|
|
||||||
@export CONDA_ENV_PROMPT='<{name}>'
|
|
||||||
@echo 'conda activate $(env)'
|
|
||||||
|
|
||||||
dev:
|
|
||||||
cd pyscript.core && npm run dev
|
|
||||||
|
|
||||||
build:
|
build:
|
||||||
cd pyscript.core && npm run build
|
cd pyscript.core && npm run build
|
||||||
|
|
||||||
# use the following rule to do all the checks done by precommit: in
|
# Run the precommit checks (run eslint).
|
||||||
# particular, use this if you want to run eslint.
|
|
||||||
precommit-check:
|
precommit-check:
|
||||||
pre-commit run --all-files
|
pre-commit run --all-files
|
||||||
|
|
||||||
examples:
|
# Run all integration tests sequentially.
|
||||||
mkdir -p ./examples
|
|
||||||
cp -r ../examples/* ./examples
|
|
||||||
chmod -R 755 examples
|
|
||||||
find ./examples/toga -type f -name '*.html' -exec sed $(SED_I_ARG) s+https://pyscript.net/latest/+../../build/+g {} \;
|
|
||||||
find ./examples/webgl -type f -name '*.html' -exec sed $(SED_I_ARG) s+https://pyscript.net/latest/+../../../build/+g {} \;
|
|
||||||
find ./examples -type f -name '*.html' -exec sed $(SED_I_ARG) s+https://pyscript.net/latest/+../build/+g {} \;
|
|
||||||
npm run build
|
|
||||||
rm -rf ./examples/build
|
|
||||||
mkdir -p ./examples/build
|
|
||||||
cp -R ./build/* ./examples/build
|
|
||||||
@echo "To serve examples run: $(conda_run) python -m http.server 8080 --directory examples"
|
|
||||||
|
|
||||||
# run prerequisites and serve pyscript examples at http://localhost:8000/examples/
|
|
||||||
run-examples: setup build examples
|
|
||||||
make examples
|
|
||||||
npm install
|
|
||||||
make dev
|
|
||||||
|
|
||||||
# run all integration tests *including examples* sequentially
|
|
||||||
# TODO: (fpliger) The cd pyscript.core before running the tests shouldn't be needed but for
|
|
||||||
# but for some reason it seems to bother pytest tmppaths (or test cache?). Unclear.
|
|
||||||
test-integration:
|
test-integration:
|
||||||
mkdir -p test_results
|
mkdir -p test_results
|
||||||
$(PYTEST_EXE) -vv $(ARGS) pyscript.core/tests/integration/ --log-cli-level=warning --junitxml=test_results/integration.xml
|
pytest -vv $(ARGS) pyscript.core/tests/integration/ --log-cli-level=warning --junitxml=test_results/integration.xml
|
||||||
|
|
||||||
# run all integration tests *except examples* in parallel (examples use too much memory)
|
# Run all integration tests in parallel.
|
||||||
test-integration-parallel:
|
test-integration-parallel:
|
||||||
mkdir -p test_results
|
mkdir -p test_results
|
||||||
$(PYTEST_EXE) --numprocesses auto -vv $(ARGS) pyscript.core/tests/integration/ --log-cli-level=warning --junitxml=test_results/integration.xml
|
pytest --numprocesses auto -vv $(ARGS) pyscript.core/tests/integration/ --log-cli-level=warning --junitxml=test_results/integration.xml
|
||||||
|
|
||||||
# run integration tests on only examples sequentially (to avoid running out of memory)
|
# Format the code.
|
||||||
test-examples:
|
fmt: fmt-py
|
||||||
mkdir -p test_results
|
|
||||||
$(PYTEST_EXE) -vv $(ARGS) pyscript.core/tests/integration/ --log-cli-level=warning --junitxml=test_results/integration.xml -k 'zz_examples'
|
|
||||||
|
|
||||||
fmt: fmt-py fmt-ts
|
|
||||||
@echo "Format completed"
|
@echo "Format completed"
|
||||||
|
|
||||||
fmt-check: fmt-ts-check fmt-py-check
|
# Check the code formatting.
|
||||||
|
fmt-check: fmt-py-check
|
||||||
@echo "Format check completed"
|
@echo "Format check completed"
|
||||||
|
|
||||||
fmt-ts:
|
# Format Python code.
|
||||||
npm run format
|
|
||||||
|
|
||||||
fmt-ts-check:
|
|
||||||
npm run format:check
|
|
||||||
|
|
||||||
fmt-py:
|
fmt-py:
|
||||||
$(conda_run) black --skip-string-normalization .
|
black -l 88 --skip-string-normalization .
|
||||||
$(conda_run) isort --profile black .
|
isort --profile black .
|
||||||
|
|
||||||
|
# Check the format of Python code.
|
||||||
fmt-py-check:
|
fmt-py-check:
|
||||||
$(conda_run) black -l 88 --check .
|
black -l 88 --check .
|
||||||
|
|
||||||
.PHONY: $(MAKECMDGOALS)
|
.PHONY: $(MAKECMDGOALS)
|
||||||
|
|||||||
@@ -1,26 +0,0 @@
|
|||||||
channels:
|
|
||||||
- defaults
|
|
||||||
- conda-forge
|
|
||||||
- microsoft
|
|
||||||
dependencies:
|
|
||||||
- python=3.11.3
|
|
||||||
- pip
|
|
||||||
- pytest=7.1.2
|
|
||||||
- nodejs=16
|
|
||||||
- black
|
|
||||||
- isort
|
|
||||||
- codespell
|
|
||||||
- pre-commit
|
|
||||||
- pillow
|
|
||||||
- numpy
|
|
||||||
- markdown
|
|
||||||
- toml
|
|
||||||
- pip:
|
|
||||||
- playwright==1.33.0
|
|
||||||
- pytest-playwright==0.3.3
|
|
||||||
- pytest-xdist==3.3.0
|
|
||||||
- pexpect
|
|
||||||
# We need Pyodide and micropip so we can import them in our Python
|
|
||||||
# unit tests
|
|
||||||
- pyodide_py==0.23.2
|
|
||||||
- micropip==0.2.2
|
|
||||||
@@ -652,7 +652,7 @@ TEST_ITERATIONS = math.ceil(
|
|||||||
) # 120 iters of 1/4 second
|
) # 120 iters of 1/4 second
|
||||||
|
|
||||||
|
|
||||||
def wait_for_render(page, selector, pattern, timeout_seconds: int | None = None):
|
def wait_for_render(page, selector, pattern, timeout_seconds=None):
|
||||||
"""
|
"""
|
||||||
Assert that rendering inserts data into the page as expected: search the
|
Assert that rendering inserts data into the page as expected: search the
|
||||||
DOM from within the timing loop for a string that is not present in the
|
DOM from within the timing loop for a string that is not present in the
|
||||||
|
|||||||
13
requirements.txt
Normal file
13
requirements.txt
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
black
|
||||||
|
isort
|
||||||
|
pytest==7.1.2
|
||||||
|
pre-commit
|
||||||
|
playwright==1.33.0
|
||||||
|
pytest-playwright==0.3.3
|
||||||
|
pytest-xdist==3.3.0
|
||||||
|
pexpect
|
||||||
|
pyodide_py==0.24.1
|
||||||
|
micropip
|
||||||
|
toml
|
||||||
|
numpy
|
||||||
|
pillow
|
||||||
Reference in New Issue
Block a user