Add prettier to pre-commit (#1255)

* Add prettier to pre-commit

* Apply prettier
This commit is contained in:
Hood Chatham
2023-03-07 10:32:16 +01:00
committed by GitHub
parent 34a0205757
commit 03e798a079
16 changed files with 598 additions and 578 deletions

6
.github/release.yml vendored
View File

@@ -1,5 +1,5 @@
changelog: changelog:
categories: categories:
- title: New Features - title: New Features
- title: Breaking Changes - title: Breaking Changes
- title: Known Issues - title: Known Issues

View File

@@ -1,21 +1,21 @@
name: '[CI] Build Unstable' name: "[CI] Build Unstable"
on: on:
push: # Only run on merges into main that modify files under pyscriptjs/ and examples/ push: # Only run on merges into main that modify files under pyscriptjs/ and examples/
branches: branches:
- main - main
paths: paths:
- pyscriptjs/** - pyscriptjs/**
- examples/** - examples/**
- .github/workflows/build-latest.yml # Test that workflow works when changed - .github/workflows/build-latest.yml # Test that workflow works when changed
pull_request: # Run on any PR that modifies files under pyscriptjs/ and examples/ pull_request: # Run on any PR that modifies files under pyscriptjs/ and examples/
branches: branches:
- main - main
paths: paths:
- pyscriptjs/** - pyscriptjs/**
- examples/** - examples/**
- .github/workflows/build-unstable.yml # Test that workflow works when changed - .github/workflows/build-unstable.yml # Test that workflow works when changed
workflow_dispatch: workflow_dispatch:
jobs: jobs:
@@ -28,59 +28,59 @@ jobs:
MINICONDA_PYTHON_VERSION: py38 MINICONDA_PYTHON_VERSION: py38
MINICONDA_VERSION: 4.11.0 MINICONDA_VERSION: 4.11.0
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v3 uses: actions/checkout@v3
- name: Install node - name: Install node
uses: actions/setup-node@v3 uses: actions/setup-node@v3
with: with:
node-version: 18.x node-version: 18.x
- name: Cache node modules - name: Cache node modules
uses: actions/cache@v3 uses: actions/cache@v3
env: env:
cache-name: cache-node-modules cache-name: cache-node-modules
with: with:
# npm cache files are stored in `~/.npm` on Linux/macOS # npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: | restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}- ${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build- ${{ runner.os }}-build-
${{ runner.os }}- ${{ runner.os }}-
- name: setup Miniconda - name: setup Miniconda
uses: conda-incubator/setup-miniconda@v2 uses: conda-incubator/setup-miniconda@v2
- name: Setup Environment - name: Setup Environment
run: make setup run: make setup
- name: Build - name: Build
run: make build run: make build
- name: TypeScript Tests - name: TypeScript Tests
run: make test-ts run: make test-ts
- name: Python Tests - name: Python Tests
run: make test-py run: make test-py
- name: Integration Tests - name: Integration Tests
run: make test-integration-parallel run: make test-integration-parallel
- uses: actions/upload-artifact@v3 - uses: actions/upload-artifact@v3
with: with:
name: pyscript name: pyscript
path: | path: |
pyscriptjs/build/ pyscriptjs/build/
if-no-files-found: error if-no-files-found: error
retention-days: 7 retention-days: 7
- uses: actions/upload-artifact@v3 - uses: actions/upload-artifact@v3
if: success() || failure() if: success() || failure()
with: with:
name: test_results name: test_results
path: pyscriptjs/test_results path: pyscriptjs/test_results
if-no-files-found: error if-no-files-found: error
Deploy: Deploy:
runs-on: ubuntu-latest runs-on: ubuntu-latest
@@ -91,17 +91,17 @@ jobs:
id-token: write id-token: write
steps: steps:
- uses: actions/download-artifact@v3 - uses: actions/download-artifact@v3
with: with:
name: pyscript name: pyscript
path: ./build/ path: ./build/
# Deploy to S3 # Deploy to S3
- name: Configure AWS credentials - name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1.6.1 uses: aws-actions/configure-aws-credentials@v1.6.1
with: with:
aws-region: ${{ secrets.AWS_REGION }} aws-region: ${{ secrets.AWS_REGION }}
role-to-assume: ${{ secrets.AWS_OIDC_RUNNER_ROLE }} role-to-assume: ${{ secrets.AWS_OIDC_RUNNER_ROLE }}
- name: Sync to S3 - name: Sync to S3
run: aws s3 sync --quiet ./build/ s3://pyscript.net/unstable/ run: aws s3 sync --quiet ./build/ s3://pyscript.net/unstable/

View File

@@ -1,4 +1,4 @@
name: '[Docs] Build Release' name: "[Docs] Build Release"
on: on:
release: release:
@@ -13,50 +13,50 @@ jobs:
env: env:
SPHINX_HTML_BASE_URL: https://docs.pyscript.net/ SPHINX_HTML_BASE_URL: https://docs.pyscript.net/
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v3 uses: actions/checkout@v3
with: with:
persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal access token. persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal access token.
fetch-depth: 0 # otherwise, there would be errors pushing refs to the destination repository. fetch-depth: 0 # otherwise, there would be errors pushing refs to the destination repository.
- name: Setup - name: Setup
uses: conda-incubator/setup-miniconda@v2 uses: conda-incubator/setup-miniconda@v2
with: with:
auto-update-conda: true auto-update-conda: true
activate-environment: docs activate-environment: docs
environment-file: docs/environment.yml environment-file: docs/environment.yml
python-version: '3.9' python-version: "3.9"
- name: Build - name: Build
shell: bash -l {0} shell: bash -l {0}
run: | run: |
cd docs/ cd docs/
make html make html
- name: Upload artifacts - name: Upload artifacts
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v3
with: with:
name: pyscript-docs-${{ github.ref_name }} name: pyscript-docs-${{ github.ref_name }}
path: docs/_build/html/ path: docs/_build/html/
# Deploy to S3 # Deploy to S3
- name: Configure AWS credentials - name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1.6.1 uses: aws-actions/configure-aws-credentials@v1.6.1
with: with:
aws-region: ${{ secrets.AWS_REGION }} aws-region: ${{ secrets.AWS_REGION }}
role-to-assume: ${{ secrets.AWS_OIDC_RUNNER_ROLE }} role-to-assume: ${{ secrets.AWS_OIDC_RUNNER_ROLE }}
- name: Copy redirect file - name: Copy redirect file
run: aws s3 cp --quiet ./docs/_build/html/_static/redirect.html s3://docs.pyscript.net/index.html run: aws s3 cp --quiet ./docs/_build/html/_static/redirect.html s3://docs.pyscript.net/index.html
- name: Sync to S3 - name: Sync to S3
run: aws s3 sync --quiet ./docs/_build/html/ s3://docs.pyscript.net/${{ github.ref_name }}/ run: aws s3 sync --quiet ./docs/_build/html/ s3://docs.pyscript.net/${{ github.ref_name }}/
# Make sure to remove the latest folder so we sync the full docs upon release # Make sure to remove the latest folder so we sync the full docs upon release
- name: Delete latest directory - name: Delete latest directory
run: aws s3 rm --recursive s3://docs.pyscript.net/latest/ run: aws s3 rm --recursive s3://docs.pyscript.net/latest/
# Note that the files are the same as above, but we want to have folders with # Note that the files are the same as above, but we want to have folders with
# /<tag name>/ AND /latest/ which latest will always point to the latest release # /<tag name>/ AND /latest/ which latest will always point to the latest release
- name: Sync to /latest - name: Sync to /latest
run: aws s3 sync --quiet ./docs/_build/html/ s3://docs.pyscript.net/latest/ run: aws s3 sync --quiet ./docs/_build/html/ s3://docs.pyscript.net/latest/

View File

@@ -1,11 +1,11 @@
name: '[Docs] Build Review' name: "[Docs] Build Review"
on: on:
pull_request: pull_request:
branches: branches:
- '*' - "*"
paths: paths:
- docs/** - docs/**
concurrency: concurrency:
# Concurrency group that uses the workflow name and PR number if available # Concurrency group that uses the workflow name and PR number if available
@@ -26,48 +26,48 @@ jobs:
env: env:
SPHINX_HTML_BASE_URL: https://docs.pyscript.net/ SPHINX_HTML_BASE_URL: https://docs.pyscript.net/
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v3 uses: actions/checkout@v3
with: with:
persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal access token. persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal access token.
fetch-depth: 0 # otherwise, there would be errors pushing refs to the destination repository. fetch-depth: 0 # otherwise, there would be errors pushing refs to the destination repository.
- name: Setup - name: Setup
uses: conda-incubator/setup-miniconda@v2 uses: conda-incubator/setup-miniconda@v2
with: with:
auto-update-conda: true auto-update-conda: true
activate-environment: docs activate-environment: docs
environment-file: docs/environment.yml environment-file: docs/environment.yml
python-version: '3.9' python-version: "3.9"
- name: Build - name: Build
shell: bash -l {0} shell: bash -l {0}
run: | run: |
cd docs/ cd docs/
make html make html
- name: Upload artifacts - name: Upload artifacts
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v3
with: with:
name: pyscript-docs-review-${{ github.event.number }} name: pyscript-docs-review-${{ github.event.number }}
path: docs/_build/html/ path: docs/_build/html/
# Deploy to S3 # Deploy to S3
- name: Configure AWS credentials - name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1.6.1 uses: aws-actions/configure-aws-credentials@v1.6.1
with: with:
aws-region: ${{ secrets.AWS_REGION }} aws-region: ${{ secrets.AWS_REGION }}
role-to-assume: ${{ secrets.AWS_OIDC_RUNNER_ROLE }} role-to-assume: ${{ secrets.AWS_OIDC_RUNNER_ROLE }}
- name: Copy redirect file - name: Copy redirect file
run: aws s3 cp --quiet ./docs/_build/html/_static/redirect.html s3://docs.pyscript.net/index.html run: aws s3 cp --quiet ./docs/_build/html/_static/redirect.html s3://docs.pyscript.net/index.html
- name: Sync to S3 - name: Sync to S3
run: aws s3 sync --quiet ./docs/_build/html/ s3://docs.pyscript.net/review/${{ github.event.number }}/ run: aws s3 sync --quiet ./docs/_build/html/ s3://docs.pyscript.net/review/${{ github.event.number }}/
- name: Adding step summary - name: Adding step summary
run: | run: |
echo "### Review documentation" >> $GITHUB_STEP_SUMMARY echo "### Review documentation" >> $GITHUB_STEP_SUMMARY
echo "As with any pull request, you can find the rendered documentation version for pull request ${{ github.event.number }} here:" echo "As with any pull request, you can find the rendered documentation version for pull request ${{ github.event.number }} here:"
echo "" >> $GITHUB_STEP_SUMMARY # this is a blank line echo "" >> $GITHUB_STEP_SUMMARY # this is a blank line
echo "https://docs.pyscript.net/review/${{ github.event.number }}/" >> $GITHUB_STEP_SUMMARY echo "https://docs.pyscript.net/review/${{ github.event.number }}/" >> $GITHUB_STEP_SUMMARY

View File

@@ -1,11 +1,11 @@
name: '[Docs] Build Latest' name: "[Docs] Build Latest"
on: on:
push: push:
branches: branches:
- main - main
paths: paths:
- docs/** - docs/**
jobs: jobs:
build: build:
@@ -16,39 +16,39 @@ jobs:
env: env:
SPHINX_HTML_BASE_URL: https://docs.pyscript.net/ SPHINX_HTML_BASE_URL: https://docs.pyscript.net/
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v3 uses: actions/checkout@v3
with: with:
persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal access token. persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal access token.
fetch-depth: 0 # otherwise, there would be errors pushing refs to the destination repository. fetch-depth: 0 # otherwise, there would be errors pushing refs to the destination repository.
- name: Setup - name: Setup
uses: conda-incubator/setup-miniconda@v2 uses: conda-incubator/setup-miniconda@v2
with: with:
auto-update-conda: true auto-update-conda: true
activate-environment: docs activate-environment: docs
environment-file: docs/environment.yml environment-file: docs/environment.yml
python-version: '3.9' python-version: "3.9"
- name: Build - name: Build
shell: bash -l {0} shell: bash -l {0}
run: | run: |
cd docs/ cd docs/
make html make html
- name: Upload artifacts - name: Upload artifacts
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v3
with: with:
name: pyscript-docs-latest name: pyscript-docs-latest
path: docs/_build/html/ path: docs/_build/html/
# Deploy to S3 # Deploy to S3
- name: Configure AWS credentials - name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1.6.1 uses: aws-actions/configure-aws-credentials@v1.6.1
with: with:
aws-region: ${{ secrets.AWS_REGION }} aws-region: ${{ secrets.AWS_REGION }}
role-to-assume: ${{ secrets.AWS_OIDC_RUNNER_ROLE }} role-to-assume: ${{ secrets.AWS_OIDC_RUNNER_ROLE }}
# Sync will only copy changed files # Sync will only copy changed files
- name: Sync to S3 - name: Sync to S3
run: aws s3 sync --quiet ./docs/_build/html/ s3://docs.pyscript.net/unstable/ run: aws s3 sync --quiet ./docs/_build/html/ s3://docs.pyscript.net/unstable/

View File

@@ -1,9 +1,9 @@
name: '[CI] Prepare Release' name: "[CI] Prepare Release"
on: on:
push: push:
tags: tags:
- '[0-9][0-9][0-9][0-9].[0-9][0-9].[0-9]+' # YYYY.MM.MICRO - "[0-9][0-9][0-9][0-9].[0-9][0-9].[0-9]+" # YYYY.MM.MICRO
env: env:
MINICONDA_PYTHON_VERSION: py38 MINICONDA_PYTHON_VERSION: py38
@@ -17,43 +17,43 @@ jobs:
build: build:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v3 uses: actions/checkout@v3
- name: Install node - name: Install node
uses: actions/setup-node@v3 uses: actions/setup-node@v3
with: with:
node-version: 18.x node-version: 18.x
- name: Cache node modules - name: Cache node modules
uses: actions/cache@v3 uses: actions/cache@v3
env: env:
cache-name: cache-node-modules cache-name: cache-node-modules
with: with:
# npm cache files are stored in `~/.npm` on Linux/macOS # npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: | restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}- ${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build- ${{ runner.os }}-build-
${{ runner.os }}- ${{ runner.os }}-
- name: setup Miniconda - name: setup Miniconda
uses: conda-incubator/setup-miniconda@v2 uses: conda-incubator/setup-miniconda@v2
- name: Setup Environment - name: Setup Environment
run: make setup run: make setup
- name: Build and Test - name: Build and Test
run: make test run: make test
- name: Zip build folder - name: Zip build folder
run: zip -r -q ./build.zip ./build run: zip -r -q ./build.zip ./build
- name: Prepare Release - name: Prepare Release
uses: softprops/action-gh-release@v1 uses: softprops/action-gh-release@v1
with: with:
draft: true draft: true
prerelease: true prerelease: true
generate_release_notes: true generate_release_notes: true
files: ./build.zip files: ./build.zip

View File

@@ -1,4 +1,4 @@
name: '[CI] Publish Release' name: "[CI] Publish Release"
on: on:
release: release:
@@ -19,44 +19,45 @@ jobs:
contents: read contents: read
id-token: write id-token: write
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v3 uses: actions/checkout@v3
- name: Install node - name: Install node
uses: actions/setup-node@v3 uses: actions/setup-node@v3
with: with:
node-version: 18.x node-version: 18.x
- name: Cache node modules - name: Cache node modules
uses: actions/cache@v3 uses: actions/cache@v3
env: env:
cache-name: cache-node-modules cache-name: cache-node-modules
with: with:
# npm cache files are stored in `~/.npm` on Linux/macOS # npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: | restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}- ${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build- ${{ runner.os }}-build-
${{ runner.os }}- ${{ runner.os }}-
- name: setup Miniconda - name: setup Miniconda
uses: conda-incubator/setup-miniconda@v2 uses: conda-incubator/setup-miniconda@v2
- name: Setup Environment - name: Setup Environment
run: make setup run: make setup
- name: Build and Test - name: Build and Test
run: make test run: make test
# Upload to S3 # Upload to S3
- name: Configure AWS credentials - name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1.6.1 uses: aws-actions/configure-aws-credentials@v1.6.1
with: with:
aws-region: ${{ secrets.AWS_REGION }} aws-region: ${{ secrets.AWS_REGION }}
role-to-assume: ${{ secrets.AWS_OIDC_RUNNER_ROLE }} role-to-assume: ${{ secrets.AWS_OIDC_RUNNER_ROLE }}
- name: Sync to S3 - name: Sync to S3
run: | # Update /latest and create an explicitly versioned directory under releases/YYYY.MM.MICRO/ run:
aws s3 sync --quiet ./build/ s3://pyscript.net/latest/ | # Update /latest and create an explicitly versioned directory under releases/YYYY.MM.MICRO/
aws s3 sync --quiet ./build/ s3://pyscript.net/releases/${{ github.ref_name }}/ aws s3 sync --quiet ./build/ s3://pyscript.net/latest/
aws s3 sync --quiet ./build/ s3://pyscript.net/releases/${{ github.ref_name }}/

View File

@@ -1,11 +1,11 @@
name: '[CI] Publish Snapshot' name: "[CI] Publish Snapshot"
# Copy /unstable/ to /snapshots/2022.09.1.RC1/ # Copy /unstable/ to /snapshots/2022.09.1.RC1/
on: on:
workflow_dispatch: workflow_dispatch:
inputs: inputs:
snapshot_version: snapshot_version:
description: 'The calver version of this snapshot: 2022.09.1 or 2022.09.1.RC1' description: "The calver version of this snapshot: 2022.09.1 or 2022.09.1.RC1"
type: string type: string
required: true required: true
@@ -16,11 +16,11 @@ jobs:
contents: read contents: read
id-token: write id-token: write
steps: steps:
- name: Configure AWS credentials - name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1.6.1 uses: aws-actions/configure-aws-credentials@v1.6.1
with: with:
aws-region: ${{ secrets.AWS_REGION }} aws-region: ${{ secrets.AWS_REGION }}
role-to-assume: ${{ secrets.AWS_OIDC_RUNNER_ROLE }} role-to-assume: ${{ secrets.AWS_OIDC_RUNNER_ROLE }}
- name: Sync to S3 - name: Sync to S3
run: > run: >
aws s3 sync s3://pyscript.net/unstable/ s3://pyscript.net/snapshots/${{ inputs.snapshot_version }}/ aws s3 sync s3://pyscript.net/unstable/ s3://pyscript.net/snapshots/${{ inputs.snapshot_version }}/

View File

@@ -1,4 +1,4 @@
name: '[CI] Sync Examples' name: "[CI] Sync Examples"
on: on:
release: release:
@@ -16,13 +16,14 @@ jobs:
steps: steps:
# Deploy to S3 # Deploy to S3
- name: Checkout - name: Checkout
uses: actions/checkout@v3 uses: actions/checkout@v3
- name: Configure AWS credentials - name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1.6.1 uses: aws-actions/configure-aws-credentials@v1.6.1
with: with:
aws-region: ${{ secrets.AWS_REGION }} aws-region: ${{ secrets.AWS_REGION }}
role-to-assume: ${{ secrets.AWS_OIDC_RUNNER_ROLE }} role-to-assume: ${{ secrets.AWS_OIDC_RUNNER_ROLE }}
- name: Sync to S3 - name:
# Sync outdated or new files, delete ones no longer in source Sync to S3
run: aws s3 sync --quiet --delete . s3://pyscript.net/examples/ # Sync directory, delete what is not in source # Sync outdated or new files, delete ones no longer in source
run: aws s3 sync --quiet --delete . s3://pyscript.net/examples/ # Sync directory, delete what is not in source

View File

@@ -3,14 +3,14 @@ on:
workflow_run: workflow_run:
workflows: ['\[CI\] Build Unstable'] workflows: ['\[CI\] Build Unstable']
types: types:
- completed - completed
jobs: jobs:
report: report:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: dorny/test-reporter@v1.6.0 - uses: dorny/test-reporter@v1.6.0
with: with:
artifact: test_results artifact: test_results
name: Test reports name: Test reports
path: '*.xml' path: "*.xml"
reporter: java-junit reporter: java-junit

View File

@@ -3,66 +3,54 @@
default_stages: [commit] default_stages: [commit]
repos: repos:
- repo: https://github.com/pre-commit/pre-commit-hooks - repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0 rev: v4.4.0
hooks: hooks:
- id: check-builtin-literals - id: check-builtin-literals
- id: check-case-conflict - id: check-case-conflict
- id: check-docstring-first - id: check-docstring-first
- id: check-executables-have-shebangs - id: check-executables-have-shebangs
- id: check-json - id: check-json
exclude: tsconfig.json exclude: tsconfig.json
- id: check-toml - id: check-toml
- id: check-xml - id: check-xml
- id: check-yaml - id: check-yaml
- id: detect-private-key - id: detect-private-key
- id: end-of-file-fixer - id: end-of-file-fixer
exclude: \.min\.js$ exclude: \.min\.js$
- id: trailing-whitespace - id: trailing-whitespace
- repo: https://github.com/charliermarsh/ruff-pre-commit - repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.247 rev: v0.0.247
hooks: hooks:
- id: ruff - id: ruff
- repo: https://github.com/psf/black - repo: https://github.com/psf/black
rev: 23.1.0 rev: 23.1.0
hooks: hooks:
- id: black - id: black
- repo: https://github.com/codespell-project/codespell - repo: https://github.com/codespell-project/codespell
rev: v2.2.2 rev: v2.2.2
hooks: hooks:
- id: codespell # See 'pyproject.toml' for args - id: codespell # See 'pyproject.toml' for args
additional_dependencies: additional_dependencies:
- tomli - tomli
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks - repo: https://github.com/hoodmane/pyscript-prettier-precommit
rev: v2.7.0 rev: "v3.0.0-alpha.6"
hooks: hooks:
- id: pretty-format-yaml - id: prettier
args: [--autofix, --indent, '4'] args: [--tab-width, "4"]
exclude: .github/ISSUE_TEMPLATE/.*\.yml$
- repo: https://github.com/pre-commit/mirrors-eslint - repo: https://github.com/pre-commit/mirrors-eslint
rev: v8.35.0 rev: v8.35.0
hooks: hooks:
- id: eslint - id: eslint
files: pyscriptjs/src/.*\.[jt]sx?$ # *.js, *.jsx, *.ts and *.tsx files: pyscriptjs/src/.*\.[jt]sx?$ # *.js, *.jsx, *.ts and *.tsx
types: [file] types: [file]
additional_dependencies: additional_dependencies:
- eslint@8.25.0 - eslint@8.25.0
- typescript@4.8.4 - typescript@4.8.4
- '@typescript-eslint/eslint-plugin@5.39.0' - "@typescript-eslint/eslint-plugin@5.39.0"
- '@typescript-eslint/parser@5.39.0' - "@typescript-eslint/parser@5.39.0"
# Commented out until mdformat-myst supports custom extensions
# See https://github.com/executablebooks/mdformat-myst/pull/9
# - repo: https://github.com/executablebooks/mdformat
# rev: 0.7.14 # Use the ref you want to point at
# hooks:
# - id: mdformat
# additional_dependencies:
# - mdformat-gfm
# - mdformat-myst
# - mdformat-black

4
.prettierignore Normal file
View File

@@ -0,0 +1,4 @@
ISSUE_TEMPLATE
*.min.*
package-lock.json
docs

View File

@@ -25,4 +25,4 @@ conda:
# Optionally declare the Python requirements required to build your docs # Optionally declare the Python requirements required to build your docs
python: python:
install: install:
- requirements: docs/requirements.txt - requirements: docs/requirements.txt

View File

@@ -1,123 +1,137 @@
<!DOCTYPE html> <!doctype html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" /> <meta name="viewport" content="width=device-width,initial-scale=1" />
<title>Say Hello</title> <title>Say Hello</title>
<link rel="icon" type="image/png" href="../favicon.png" /> <link rel="icon" type="image/png" href="../favicon.png" />
<link rel="stylesheet" href="https://pyscript.net/latest/pyscript.css" /> <link
rel="stylesheet"
href="https://pyscript.net/latest/pyscript.css"
/>
<script defer src="https://pyscript.net/latest/pyscript.js"></script> <script defer src="https://pyscript.net/latest/pyscript.js"></script>
</head> </head>
<body> <body>
<py-script> <py-script>
from js import handTrack, requestAnimationFrame from js import handTrack, requestAnimationFrame
from pyodide import create_once_callable from pyodide import create_once_callable
import asyncio import asyncio
context = canvas.element.getContext("2d") context = canvas.element.getContext("2d")
isVideo = False isVideo = False
model = None model = None
modelParams = { modelParams = {
"flipHorizontal": True, # flip e.g for video "flipHorizontal": True, # flip e.g for video
"maxNumBoxes": 20, # maximum number of boxes to detect "maxNumBoxes": 20, # maximum number of boxes to detect
"iouThreshold": 0.5, # ioU threshold for non-max suppression "iouThreshold": 0.5, # ioU threshold for non-max suppression
"scoreThreshold": 0.6, # confidence threshold for predictions. "scoreThreshold": 0.6, # confidence threshold for predictions.
} }
def toggle_video(evt): def toggle_video(evt):
global isVideo global isVideo
if (not isVideo): if (not isVideo):
update_note.write("Starting video") update_note.write("Starting video")
pyscript.run_until_complete(start_video()) pyscript.run_until_complete(start_video())
else: else:
update_note.write("Stopping video") update_note.write("Stopping video")
handTrack.stopVideo(video.element) handTrack.stopVideo(video.element)
isVideo = False isVideo = False
update_note.write("Video stopped") update_note.write("Video stopped")
async def start_video(): async def start_video():
global isVideo global isVideo
update_note.write("Inside sstart video") update_note.write("Inside sstart video")
status = await handTrack.startVideo(video.element) status = await handTrack.startVideo(video.element)
console.log("video started", status) console.log("video started", status)
if status: if status:
update_note.write("Video started. Now tracking") update_note.write("Video started. Now tracking")
isVideo = True isVideo = True
console.log( "Calling RUN DETECTION") console.log( "Calling RUN DETECTION")
y = await run_detection() y = await run_detection()
else: else:
update_note.write( "Please enable video") update_note.write( "Please enable video")
def sync_run_detection(evt): def sync_run_detection(evt):
pyscript.run_until_complete(run_detection()) pyscript.run_until_complete(run_detection())
async def run_detection(): async def run_detection():
console.log("in RUN DETECTION: "); console.log("in RUN DETECTION: ");
global model global model
global isVideo global isVideo
console.log("...1") console.log("...1")
predictions = await model.detect(video.element) predictions = await model.detect(video.element)
console.log("done...1") console.log("done...1")
console.log("Predictions: ", predictions); console.log("Predictions: ", predictions);
model.renderPredictions(predictions, canvas.element, context, video.element); model.renderPredictions(predictions, canvas.element, context, video.element);
console.log("is Video?", isVideo) console.log("is Video?", isVideo)
if (isVideo): if (isVideo):
console.log("requestingAnimation!") console.log("requestingAnimation!")
await requestAnimationFrame(create_once_callable(sync_run_detection)); await requestAnimationFrame(create_once_callable(sync_run_detection));
console.log("...2") console.log("...2")
def run_detection_image(img): def run_detection_image(img):
console.log("in RUN DETECTION IMAGE", predictions); console.log("in RUN DETECTION IMAGE", predictions);
global model global model
def detect(predition): def detect(predition):
console.log("Predictions: ", predictions); console.log("Predictions: ", predictions);
model.renderPredictions(predictions, canvas, context, img); model.renderPredictions(predictions, canvas, context, img);
console.log("...3") console.log("...3")
model.detect(img).then(detect) model.detect(img).then(detect)
console.log("...4") console.log("...4")
def handle_model(lmodel): def handle_model(lmodel):
global model global model
model = lmodel model = lmodel
update_note.write("Loaded Model!") update_note.write("Loaded Model!")
async def start(): async def start():
console.log("creating x") console.log("creating x")
console.log("calling x") console.log("calling x")
model = await handTrack.load(modelParams)#.then(handle_model) model = await handTrack.load(modelParams)#.then(handle_model)
console.log("loaded model!") console.log("loaded model!")
console.log(model) console.log(model)
handle_model(model) handle_model(model)
print(dir(x)) print(dir(x))
print(x) print(x)
pyscript.run_until_complete(start()) pyscript.run_until_complete(start())
#}); #});
</py-script>
</py-script> <div class="mb10">
<button
<div class="mb10"> id="trackbutton"
<button id="trackbutton" class="bx--btn bx--btn--secondary" type="button" py-onClick="toggle_video()"> class="bx--btn bx--btn--secondary"
Toggle Video type="button"
</button> py-onClick="toggle_video()"
<button id="nextimagebutton" class="mt10 bx--btn bx--btn--secondary" type="button" disabled> >
Next Image Toggle Video
</button> </button>
<div id="update-note" py-mount class="updatenote mt10">loading model ..</div> <button
</div> id="nextimagebutton"
<div> class="mt10 bx--btn bx--btn--secondary"
<video autoplay="autoplay" id="myvideo" py-mount="video"></video> type="button"
<canvas id="canvas" py-mount class="border canvasbox"></canvas> disabled
</div> >
<script src="lib/handtrack.min.js"> </script> Next Image
</body> </button>
<div id="update-note" py-mount class="updatenote mt10">
loading model ..
</div>
</div>
<div>
<video autoplay="autoplay" id="myvideo" py-mount="video"></video>
<canvas id="canvas" py-mount class="border canvasbox"></canvas>
</div>
<script src="lib/handtrack.min.js"></script>
</body>
</html> </html>

View File

@@ -1,145 +1,157 @@
<!DOCTYPE html> <!doctype html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" /> <meta name="viewport" content="width=device-width,initial-scale=1" />
<title>Mario</title> <title>Mario</title>
<link rel="icon" type="image/png" href="../favicon.png" /> <link rel="icon" type="image/png" href="../favicon.png" />
<link rel="stylesheet" href="https://pyscript.net/latest/pyscript.css" /> <link
rel="stylesheet"
href="https://pyscript.net/latest/pyscript.css"
/>
<script defer src="https://pyscript.net/latest/pyscript.js"></script> <script defer src="https://pyscript.net/latest/pyscript.js"></script>
</head> </head>
<body> <body>
<script type="text/javascript" src="js/util.js"></script> <script type="text/javascript" src="js/util.js"></script>
<script type="text/javascript" src="js/input.js"></script> <script type="text/javascript" src="js/input.js"></script>
<script type="text/javascript" src="js/resources.js"></script> <script type="text/javascript" src="js/resources.js"></script>
<script type="text/javascript" src="js/sprite.js"></script> <script type="text/javascript" src="js/sprite.js"></script>
<script type="text/javascript" src="js/entity.js"></script> <script type="text/javascript" src="js/entity.js"></script>
<script type="text/javascript" src="js/pipe.js"></script> <script type="text/javascript" src="js/pipe.js"></script>
<script type="text/javascript" src="js/mushroom.js"></script> <script type="text/javascript" src="js/mushroom.js"></script>
<script type="text/javascript" src="js/fireflower.js"></script> <script type="text/javascript" src="js/fireflower.js"></script>
<script type="text/javascript" src="js/star.js"></script> <script type="text/javascript" src="js/star.js"></script>
<script type="text/javascript" src="js/fireball.js"></script> <script type="text/javascript" src="js/fireball.js"></script>
<script type="text/javascript" src="js/coin.js"></script> <script type="text/javascript" src="js/coin.js"></script>
<script type="text/javascript" src="js/bcoin.js"></script> <script type="text/javascript" src="js/bcoin.js"></script>
<script type="text/javascript" src="js/goomba.js"></script> <script type="text/javascript" src="js/goomba.js"></script>
<script type="text/javascript" src="js/koopa.js"></script> <script type="text/javascript" src="js/koopa.js"></script>
<script type="text/javascript" src="js/floor.js"></script> <script type="text/javascript" src="js/floor.js"></script>
<script type="text/javascript" src="js/block.js"></script> <script type="text/javascript" src="js/block.js"></script>
<script type="text/javascript" src="js/rubble.js"></script> <script type="text/javascript" src="js/rubble.js"></script>
<script type="text/javascript" src="js/prop.js"></script> <script type="text/javascript" src="js/prop.js"></script>
<script type="text/javascript" src="js/player.js"></script> <script type="text/javascript" src="js/player.js"></script>
<script type="text/javascript" src="js/flag.js"></script> <script type="text/javascript" src="js/flag.js"></script>
<script type="text/javascript" src="js/levels/level.js"></script> <script type="text/javascript" src="js/levels/level.js"></script>
<script type="text/javascript" src="js/levels/11.js"></script> <script type="text/javascript" src="js/levels/11.js"></script>
<script type="text/javascript" src="js/levels/11tunnel.js"></script> <script type="text/javascript" src="js/levels/11tunnel.js"></script>
<script type="text/javascript" src="js/game.js"></script> <script type="text/javascript" src="js/game.js"></script>
<py-script> <py-script>
from js import handTrack, setTimeout, requestAnimationFrame, player from js import handTrack, setTimeout, requestAnimationFrame, player
from pyodide import create_once_callable from pyodide import create_once_callable
import asyncio import asyncio
context = canvas.element.getContext("2d") context = canvas.element.getContext("2d")
isVideo = False isVideo = False
model = None model = None
last_position = 0 last_position = 0
direction = "stop" direction = "stop"
modelParams = { modelParams = {
"flipHorizontal": True, # flip e.g for video "flipHorizontal": True, # flip e.g for video
"maxNumBoxes": 20, # maximum number of boxes to detect "maxNumBoxes": 20, # maximum number of boxes to detect
"iouThreshold": 0.5, # ioU threshold for non-max suppression "iouThreshold": 0.5, # ioU threshold for non-max suppression
"scoreThreshold": 0.6, # confidence threshold for predictions. "scoreThreshold": 0.6, # confidence threshold for predictions.
} }
def toggle_video(evt): def toggle_video(evt):
global isVideo global isVideo
player.jump() player.jump()
if (not isVideo): if (not isVideo):
update_note.write("Starting video") update_note.write("Starting video")
pyscript.run_until_complete(start_video()) pyscript.run_until_complete(start_video())
else: else:
update_note.write("Stopping video") update_note.write("Stopping video")
handTrack.stopVideo(video.element) handTrack.stopVideo(video.element)
isVideo = False isVideo = False
update_note.write("Video stopped") update_note.write("Video stopped")
async def start_video(): async def start_video():
global isVideo global isVideo
update_note.write("Inside start video") update_note.write("Inside start video")
status = await handTrack.startVideo(video.element) status = await handTrack.startVideo(video.element)
console.log("video started", status) console.log("video started", status)
if status: if status:
update_note.write("Video started. Now tracking") update_note.write("Video started. Now tracking")
isVideo = True isVideo = True
console.log( "Calling RUN DETECTION") console.log( "Calling RUN DETECTION")
y = await run_detection() y = await run_detection()
else: else:
update_note.write( "Please enable video") update_note.write( "Please enable video")
def sync_run_detection(evt): def sync_run_detection(evt):
pyscript.run_until_complete(run_detection()) pyscript.run_until_complete(run_detection())
async def run_detection(): async def run_detection():
global model global model
global isVideo global isVideo
global last_position global last_position
global direction global direction
predictions = await model.detect(video.element) predictions = await model.detect(video.element)
model.renderPredictions(predictions, canvas.element, context, video.element); model.renderPredictions(predictions, canvas.element, context, video.element);
if predictions: if predictions:
curr_position = predictions[0].bbox[0] + (predictions[0].bbox[2] / 2) curr_position = predictions[0].bbox[0] + (predictions[0].bbox[2] / 2)
delta = last_position - curr_position delta = last_position - curr_position
last_position = curr_position last_position = curr_position
#console.log(delta, curr_position, last_position) #console.log(delta, curr_position, last_position)
if abs(delta) < 2: if abs(delta) < 2:
direction = "stop" direction = "stop"
elif delta > 0: elif delta > 0:
direction = "left" direction = "left"
else: else:
direction = "right" direction = "right"
for prediction in predictions: for prediction in predictions:
if prediction.label == 'open': if prediction.label == 'open':
player.jump() player.jump()
elif prediction.label == 'close': elif prediction.label == 'close':
player.crouch() player.crouch()
if (isVideo): if (isVideo):
await requestAnimationFrame(create_once_callable(sync_run_detection)); await requestAnimationFrame(create_once_callable(sync_run_detection));
def handle_model(lmodel): def handle_model(lmodel):
global model global model
model = lmodel model = lmodel
update_note.write("Loaded Model!") update_note.write("Loaded Model!")
async def start(): async def start():
model = await handTrack.load(modelParams)#.then(handle_model) model = await handTrack.load(modelParams)#.then(handle_model)
handle_model(model) handle_model(model)
pyscript.run_until_complete(start()) pyscript.run_until_complete(start())
</py-script>
</py-script> <div class="mb10">
<p>
<div class="mb10"> Use < > to move, ↓ to crouch and x to jump. If video is enabled,
<p>Use < > to move, ↓ to crouch and x to jump. If video is enabled, say hi to jump as well! </p> say hi to jump as well!
<button id="trackbutton" class="bx--btn bx--btn--secondary" type="button" py-onClick="toggle_video()"> </p>
Start Video <button
</button> id="trackbutton"
<div id="update-note" py-mount class="updatenote mt10">loading model ..</div> class="bx--btn bx--btn--secondary"
</div> type="button"
<div> py-onClick="toggle_video()"
<video autoplay="autoplay" id="myvideo" py-mount="video"></video> >
<canvas id="canvas" py-mount class="border canvasbox"></canvas> Start Video
</div> </button>
<script src="../handtrack/lib/handtrack.min.js"> </script> <div id="update-note" py-mount class="updatenote mt10">
</body> loading model ..
</div>
</div>
<div>
<video autoplay="autoplay" id="myvideo" py-mount="video"></video>
<canvas id="canvas" py-mount class="border canvasbox"></canvas>
</div>
<script src="../handtrack/lib/handtrack.min.js"></script>
</body>
</html> </html>

View File

@@ -1,20 +1,20 @@
channels: channels:
- defaults - defaults
- conda-forge - conda-forge
- microsoft - microsoft
dependencies: dependencies:
- python=3.9 - python=3.9
- pip - pip
- pytest=7 - pytest=7
- nodejs=16 - nodejs=16
- black - black
- isort - isort
- codespell - codespell
- pre-commit - pre-commit
- pillow - pillow
- numpy - numpy
- markdown - markdown
- pip: - pip:
- playwright - playwright
- pytest-playwright - pytest-playwright
- pytest-xdist - pytest-xdist