diff --git a/.github/workflows/build-unstable.yml b/.github/workflows/build-unstable.yml index 73b0ba355f2..335dccd1e3e 100644 --- a/.github/workflows/build-unstable.yml +++ b/.github/workflows/build-unstable.yml @@ -20,7 +20,7 @@ on: jobs: BuildAndTest: - runs-on: ubuntu-latest + runs-on: ubuntu-latest-8core defaults: run: working-directory: pyscriptjs @@ -85,7 +85,7 @@ jobs: path: pyscriptjs/test_results if-no-files-found: error eslint: - runs-on: ubuntu-latest + runs-on: ubuntu-latest-8core defaults: run: working-directory: pyscriptjs @@ -118,7 +118,7 @@ jobs: run: npx eslint src -c .eslintrc.js Deploy: - runs-on: ubuntu-latest + runs-on: ubuntu-latest-8core needs: BuildAndTest if: github.ref == 'refs/heads/main' # Only deploy on merge into main permissions: diff --git a/.github/workflows/docs-release.yml b/.github/workflows/docs-release.yml index 2978d7a971b..3d34d40bfa4 100644 --- a/.github/workflows/docs-release.yml +++ b/.github/workflows/docs-release.yml @@ -6,7 +6,7 @@ on: jobs: build: - runs-on: ubuntu-latest + runs-on: ubuntu-latest-8core permissions: contents: read id-token: write diff --git a/.github/workflows/docs-review.yml b/.github/workflows/docs-review.yml index 37ba5b13678..5054d4e0899 100644 --- a/.github/workflows/docs-review.yml +++ b/.github/workflows/docs-review.yml @@ -19,7 +19,7 @@ concurrency: jobs: build: if: github.repository_owner == 'pyscript' - runs-on: ubuntu-latest + runs-on: ubuntu-latest-8core permissions: contents: read id-token: write diff --git a/.github/workflows/docs-unstable.yml b/.github/workflows/docs-unstable.yml index 0d093db5b78..9ad28948ce3 100644 --- a/.github/workflows/docs-unstable.yml +++ b/.github/workflows/docs-unstable.yml @@ -9,7 +9,7 @@ on: jobs: build: - runs-on: ubuntu-latest + runs-on: ubuntu-latest-8core permissions: contents: read id-token: write diff --git a/.github/workflows/next-build-snapshot.yml b/.github/workflows/next-build-snapshot.yml new file mode 100644 index 00000000000..b80e59eb240 --- /dev/null +++ b/.github/workflows/next-build-snapshot.yml @@ -0,0 +1,62 @@ +name: "Next Build Snapshot" + +on: + workflow_dispatch: + inputs: + snapshot_version: + description: "The calver version of this snapshot: 2022.09.1 or 2022.09.1.RC1" + type: string + required: true + +jobs: + next-build-snapshot: + runs-on: ubuntu-latest + permissions: + contents: read + id-token: write + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + ref: next + + - name: Install node + uses: actions/setup-node@v3 + with: + node-version: 18.x + + - name: Cache node modules + uses: actions/cache@v3 + env: + cache-name: cache-node-modules + with: + # npm cache files are stored in `~/.npm` on Linux/macOS + path: ~/.npm + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-build-${{ env.cache-name }}- + ${{ runner.os }}-build- + ${{ runner.os }}- + + - name: Install Dependencies + working-directory: ./pyscript.core + run: npm install + + - name: Build Pyscript.core + working-directory: ./pyscript.core + run: npm run build + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v1.6.1 + with: + aws-region: ${{ secrets.AWS_REGION }} + role-to-assume: ${{ secrets.AWS_OIDC_RUNNER_ROLE }} + + - name: Generate index.html in snapshot + working-directory: . + run: sed 's#_PATH_#https://pyscript.net/snapshots/${{ inputs.snapshot_version }}/#' ./public/index.html > ./pyscript.core/dist/index.html + + - name: Copy to Snapshot + working-directory: ./pyscript.core/dist + run: > + aws s3 sync . s3://pyscript.net/snapshots/${{ inputs.snapshot_version }}/ diff --git a/.github/workflows/prepare-release.yml b/.github/workflows/prepare-release.yml index 944eeef1100..bd0a4de7bd6 100644 --- a/.github/workflows/prepare-release.yml +++ b/.github/workflows/prepare-release.yml @@ -15,7 +15,7 @@ defaults: jobs: build: - runs-on: ubuntu-latest + runs-on: ubuntu-latest-8core steps: - name: Checkout uses: actions/checkout@v3 @@ -44,8 +44,20 @@ jobs: - name: Setup Environment run: make setup - - name: Build and Test - run: make test + - name: Build + run: make build + + - name: TypeScript Tests + run: make test-ts + + - name: Python Tests + run: make test-py + + - name: Integration Tests + run: make test-integration-parallel + + - name: Examples Tests + run: make test-examples - name: Zip build folder run: zip -r -q ./build.zip ./build diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index 304fc7592cc..f56a85fdcb9 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -14,7 +14,7 @@ defaults: jobs: build: - runs-on: ubuntu-latest + runs-on: ubuntu-latest-8core permissions: contents: read id-token: write @@ -46,8 +46,20 @@ jobs: - name: Setup Environment run: make setup - - name: Build and Test - run: make test + - name: Build + run: make build + + - name: TypeScript Tests + run: make test-ts + + - name: Python Tests + run: make test-py + + - name: Integration Tests + run: make test-integration-parallel + + - name: Examples Tests + run: make test-examples # Upload to S3 - name: Configure AWS credentials diff --git a/.github/workflows/publish-snapshot.yml b/.github/workflows/publish-snapshot.yml index e2ef5c982c3..daa12b373ac 100644 --- a/.github/workflows/publish-snapshot.yml +++ b/.github/workflows/publish-snapshot.yml @@ -11,7 +11,7 @@ on: jobs: snapshot: - runs-on: ubuntu-latest + runs-on: ubuntu-latest-8core permissions: contents: read id-token: write diff --git a/.github/workflows/sync-examples.yml b/.github/workflows/sync-examples.yml index d8ed32b8e22..deb56f638c2 100644 --- a/.github/workflows/sync-examples.yml +++ b/.github/workflows/sync-examples.yml @@ -6,7 +6,7 @@ on: jobs: build: - runs-on: ubuntu-latest + runs-on: ubuntu-latest-8core permissions: contents: read id-token: write diff --git a/.github/workflows/test-next.yml b/.github/workflows/test-next.yml new file mode 100644 index 00000000000..3bde948bd06 --- /dev/null +++ b/.github/workflows/test-next.yml @@ -0,0 +1,119 @@ +name: "[CI] Test Next" + +on: + push: # Only run on merges into main that modify files under pyscriptjs/ and examples/ + branches: + - next + paths: + - pyscript.core/** + - pyscriptjs/** + - examples/** + - .github/workflows/test-next.yml # Test that workflow works when changed + + pull_request: # Run on any PR that modifies files under pyscriptjs/ and examples/ + branches: + - next + paths: + - pyscript.core/** + - examples/** + - .github/workflows/test-next.yml # Test that workflow works when changed + workflow_dispatch: + +jobs: + BuildAndTest: + runs-on: ubuntu-latest-8core + env: + MINICONDA_PYTHON_VERSION: py38 + MINICONDA_VERSION: 4.11.0 + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + ref: next + + - name: Install node + uses: actions/setup-node@v3 + with: + node-version: 18.x + + - name: Cache node modules + uses: actions/cache@v3 + env: + cache-name: cache-node-modules + with: + # npm cache files are stored in `~/.npm` on Linux/macOS + path: ~/.npm + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-build-${{ env.cache-name }}- + ${{ runner.os }}-build- + ${{ runner.os }}- + + - name: setup Miniconda + uses: conda-incubator/setup-miniconda@v2 + + - name: Setup Environment + working-directory: ./pyscriptjs + run: make setup + + - name: Python Tests + working-directory: ./pyscriptjs + run: make test + + - name: Integration Tests + working-directory: ./pyscriptjs + run: make test-integration + #run: make test-integration-parallel + + - name: Examples Tests + working-directory: ./pyscriptjs + run: make test-examples + + - uses: actions/upload-artifact@v3 + with: + name: pyscript + path: | + pyscriptjs/build/ + if-no-files-found: error + retention-days: 7 + + - uses: actions/upload-artifact@v3 + if: success() || failure() + with: + name: test_results + path: pyscriptjs/test_results + if-no-files-found: error + eslint: + runs-on: ubuntu-latest-8core + defaults: + run: + working-directory: pyscriptjs + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + ref: next + + - name: Install node + uses: actions/setup-node@v3 + with: + node-version: 18.x + + - name: Cache node modules + uses: actions/cache@v3 + env: + cache-name: cache-node-modules + with: + # npm cache files are stored in `~/.npm` on Linux/macOS + path: ~/.npm + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-build-${{ env.cache-name }}- + ${{ runner.os }}-build- + ${{ runner.os }}- + + - name: npm install + run: npm install + + - name: Eslint + run: npx eslint src -c .eslintrc.js diff --git a/.github/workflows/test_report.yml b/.github/workflows/test_report.yml index dacbc8e7732..7ffca86bf32 100644 --- a/.github/workflows/test_report.yml +++ b/.github/workflows/test_report.yml @@ -6,7 +6,7 @@ on: - completed jobs: report: - runs-on: ubuntu-latest + runs-on: ubuntu-latest-8core steps: - uses: dorny/test-reporter@v1.6.0 with: diff --git a/LICENSE b/LICENSE index 261eeb9e9f8..e024c1dc997 100644 --- a/LICENSE +++ b/LICENSE @@ -186,7 +186,9 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright [yyyy] [name of copyright owner] + Copyright (c) 2022-present, PyScript Development Team + + Originated at Anaconda, Inc. in 2022 Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/docs/changelog.md b/docs/changelog.md index efc26b67474..67a08a17b4e 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -32,6 +32,7 @@ Features - Added a `stderr` attribute of `py-repl` tags to route `sys.stderr` to a DOM element with the given ID. ([#1106](https://github.com/pyscript/pyscript/pull/1106)) - Resored the `output-mode` attribute of `py-repl` tags. If `output-mode` == 'append', the DOM element where output is printed is _not_ cleared before writing new results. - Load code from the attribute src of py-repl and preload it into the corresponding py-repl tag by use the attribute `str` in your `py-repl` tag([#1292](https://github.com/pyscript/pyscript/pull/1292)) +- <py-repl> elements now have a `getPySrc()` method, which returns the code inside the REPL as a string.([#1516](https://github.com/pyscript/pyscript/pull/1292)) ### Plugins - Plugins may now implement the `beforePyReplExec()` and `afterPyReplExec()` hooks, which are called immediately before and after code in a `py-repl` tag is executed. ([#1106](https://github.com/pyscript/pyscript/pull/1106)) @@ -57,7 +58,7 @@ Docs - Add docs for event handlers -2023.01.1 +2023.03.1 ========= diff --git a/docs/reference/API/when.md b/docs/reference/API/when.md index aaf4f761b9b..ba5c5b0123b 100644 --- a/docs/reference/API/when.md +++ b/docs/reference/API/when.md @@ -6,6 +6,9 @@ The `@when` decorator attaches the decorated function or Callable as an event ha If the decorated function takes a single (non-self) argument, it will be passed the [Event object](https://developer.mozilla.org/en-US/docs/Web/API/Event) corresponding to the triggered event. If the function takes no (non-self) argument, it will be called with no arguments. +You will need to import `when` to get access to this feature: +`from pyscript import when` + ## Parameters `event_type` - A string representing the event type to match against. This can be any of the [https://developer.mozilla.org/en-US/docs/Web/Events#event_listing](https://developer.mozilla.org/en-US/docs/Web/Events) that HTML elements may emit, as appropriate to their element type. diff --git a/docs/reference/elements/py-repl.md b/docs/reference/elements/py-repl.md index 32d95021dd1..bee115f130d 100644 --- a/docs/reference/elements/py-repl.md +++ b/docs/reference/elements/py-repl.md @@ -28,6 +28,14 @@ The ID of an element in the DOM that `stderr` will be written to. Defaults to No ### `src` If a \ tag has the `src` attribute, during page initialization, resource in the `src` will be preloaded into the REPL. Please note that this will not run in advance. If there is content in the \ tag, it will be cleared and replaced with preloaded resource. +## Methods + +The following are methods that can be called on the \ element, from within Python or JavaScript + +### `getPySrc()` + +Returns the current code contents of the REPL as a string. + ## Examples ### `` element set to auto-generate diff --git a/docs/tutorials/getting-started.md b/docs/tutorials/getting-started.md index d0e17da0f69..a50bc66be2b 100644 --- a/docs/tutorials/getting-started.md +++ b/docs/tutorials/getting-started.md @@ -46,7 +46,7 @@ open an HTML by double-clicking it in your file explorer. In some situations, your browser may forbid loading remote resources like `pyscript.js` and `pyscript.css` when you open an HTML file directly. When this is the case, you may see your Python code in the text of the webpage, and the [browser developer console](https://balsamiq.com/support/faqs/browserconsole/) may show an error like *"Cross origin requests are only supported for HTTP."* The fix for this is to use a [simple local server](https://developer.mozilla.org/en-US/docs/Learn/Common_questions/Tools_and_setup/set_up_a_local_testing_server) to make your html file available to the browser. -If you have python installed on your system, you can use it's basic built-in server for this purpose via the command line. Change the current working directory of your terminal or command line to the folder where your HTML file is stored. From this folder, run `python -m http.server 8080 --bind 127.0.0.1` in your terminal or command line. With the server program running, point your browser to `http://localhost:8080` to view the contents of that folder. (If a file in that folder is called `index.html`, it will be displayed by default.) +If you have python installed on your system, you can use its basic built-in server for this purpose via the command line. Change the current working directory of your terminal or command line to the folder where your HTML file is stored. From this folder, run `python -m http.server 8080 --bind 127.0.0.1` in your terminal or command line. With the server program running, point your browser to `http://localhost:8080` to view the contents of that folder. (If a file in that folder is called `index.html`, it will be displayed by default.) ## A more complex example diff --git a/docs/tutorials/py-click.md b/docs/tutorials/py-click.md index 6cb52c2d125..23bda056979 100644 --- a/docs/tutorials/py-click.md +++ b/docs/tutorials/py-click.md @@ -1,6 +1,6 @@ # Handling click events -This tutorial will show you how to use the `py-click` attribute to handle mouse clicks on elements on your page. The `py-click` attribute is a special attribute that allows you to specify a Python function that will be called when the element is clicked. There are many other events such as py-mouseover, py-focus, py-input, py-keyress etc, which can be used as well. They are listed here [Attr-to-Event](../reference/API/attr_to_event.html) +This tutorial will show you how to use the `py-click` attribute to handle mouse clicks on elements on your page. The `py-click` attribute is a special attribute that allows you to specify a Python function that will be called when the element is clicked. There are many other events such as py-mouseover, py-focus, py-input, py-keyress etc, which can be used as well. They are listed here [Attr-to-Event](../reference/API/attr_to_event.md) ## Development setup diff --git a/examples/d3.html b/examples/d3.html index ef3e66f50e7..898c7ffd0f1 100644 --- a/examples/d3.html +++ b/examples/d3.html @@ -10,7 +10,7 @@ /> - +