Skip to content

Commit

Permalink
format repo
Browse files Browse the repository at this point in the history
  • Loading branch information
bugzpodder committed Oct 29, 2023
1 parent 7d2ba64 commit a6014c8
Show file tree
Hide file tree
Showing 12 changed files with 83 additions and 55 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/black.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ jobs:
with:
options: "--check --verbose"
src: "./src"
version: "23.9.1"
version: "23.9.1"
4 changes: 2 additions & 2 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
# Trigger the workflow every time you push to the `main` branch
# Using a different branch name? Replace `main` with your branch’s name
push:
branches: [ main ]
branches: [main]
# Allows you to run this workflow manually from the Actions tab on GitHub.
workflow_dispatch:

Expand Down Expand Up @@ -37,4 +37,4 @@ jobs:
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v1
uses: actions/deploy-pages@v1
2 changes: 1 addition & 1 deletion .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ jobs:
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Apply formatting changes
branch: ${{ github.head_ref }}
branch: ${{ github.head_ref }}
40 changes: 20 additions & 20 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
name: Playwright Tests
on:
push:
branches: [ main ]
branches: [main]
pull_request:
branches: [ main ]
branches: [main]
jobs:
test:
timeout-minutes: 60
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
- name: Install dependencies
run: yarn install
- name: Build pysandbox
run: yarn build
- name: Install chromium
run: yarn playwright install chromium
- name: Run Playwright tests
run: yarn test
- uses: actions/upload-artifact@v3
if: always()
with:
name: playwright-report
path: playwright-report/
retention-days: 30
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
- name: Install dependencies
run: yarn install
- name: Build pysandbox
run: yarn build
- name: Install chromium
run: yarn playwright install chromium
- name: Run Playwright tests
run: yarn test
- uses: actions/upload-artifact@v3
if: always()
with:
name: playwright-report
path: playwright-report/
retention-days: 30
25 changes: 25 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Release & Publish to NPM
on: workflow_dispatch
jobs:
release:
runs-on: ubuntu-20.04
steps:
- name: Checkout source code
uses: actions/checkout@v2
- name: Install the dependancies
run: npm ci
- name: Initialise the NPM config
run: npm config set //registry.npmjs.org/:_authToken $NPM_TOKEN
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Initialize Git user
run: |
git config --global user.email "[email protected]"
git config --global user.name "Release Workflow"
- name: Log git status
run: git status
- name: Run release
run: npm run release --ci
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@ For installation and usage instructions see [user docs](https://bugzpodder.githu

## Introduction

PySandbox is a library that helps developers create client-side Python-powered web applications. It is inspired by [PyScript](https://github.com/pyscript/pyscript) and built on top of [Pyodide](https://github.com/pyodide/pyodide) and [Polyscript](https://github.com/pyscript/polyscript).
PySandbox is a library that helps developers create client-side Python-powered web applications. It is inspired by [PyScript](https://github.com/pyscript/pyscript) and built on top of [Pyodide](https://github.com/pyodide/pyodide) and [Polyscript](https://github.com/pyscript/polyscript).

The main features of PySandbox are:
- Exports simple JS classes that can be used in any JS framework or html page.
- Web Worker ready. If your site is cross origin isolated, Web Workers can be used to execute python code.
- Restricted mode. Enabling this mode will disallow python scripts access to js.document.
- Custom modules support. You can define your own modules that are accessible in the codeblock.
- Input/Output support. You can easily pass data in and out of the python code blocks and display images and/or adding 3rd party JS integration.
- Helper methods for formatting code, find imports and installing modules in Pyodide.

- Exports simple JS classes that can be used in any JS framework or html page.
- Web Worker ready. If your site is cross origin isolated, Web Workers can be used to execute python code.
- Restricted mode. Enabling this mode will disallow python scripts access to js.document.
- Custom modules support. You can define your own modules that are accessible in the codeblock.
- Input/Output support. You can easily pass data in and out of the python code blocks and display images and/or adding 3rd party JS integration.
- Helper methods for formatting code, find imports and installing modules in Pyodide.

## Contributing

Project bootstraped with `tsup` and `esbuild`. `Node.js 16.x/18.x` is recommended for development.
Project bootstraped with `tsup` and `esbuild`. `Node.js 16.x/18.x` is recommended for development.

`yarn dev` to make changes and make development build

`yarn serve` to serve `/examples` for testing your changes

`yarn format` & `yarn format:py` to run code formatting

`/docs` contains documentation. Run `yarn format` in docs to format changes.
`/docs` contains documentation. Run `yarn format` in docs to format changes.
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"build": "astro build",
"preview": "astro preview",
"astro": "astro",
"format": "prettier -w src src/**/*.astro"
"format": "prettier -w src src/**/*.astro *.mjs *.js *.json"
},
"dependencies": {
"@astrojs/starlight": "^0.10.0",
Expand Down
6 changes: 3 additions & 3 deletions docs/prettier.config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/** @type {import("prettier").Config} */
export default {
plugins: ['prettier-plugin-astro'],
plugins: ["prettier-plugin-astro"],
overrides: [
{
files: '*.astro',
files: "*.astro",
options: {
parser: 'astro',
parser: "astro",
},
},
],
Expand Down
2 changes: 1 addition & 1 deletion docs/src/content/docs/guides/comparison.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ Pyodide does not setup web workers out of the box. If you site is [crossOriginIs

## PyScript

[PyScript](https://pyscript.net/) is great for configuring a single html page to run python code as well as providing acess to DOM through its `pyweb` API. `PyScript` adopts a RPC pattern by letting Python code manipulate the DOM and react to events, while `PySandbox` is intended to be a traditional REST backend. If you are using a JS web-framework (e.g. a React-based framework) to build your web application, you may find `PySandbox` easier to use with its pure JS invocation without needing to rely on `<script type="py">` and `<py-script>` tags.
[PyScript](https://pyscript.net/) is great for configuring a single html page to run python code as well as providing acess to DOM through its `pyweb` API. `PyScript` adopts a RPC pattern by letting Python code manipulate the DOM and react to events, while `PySandbox` is intended to be a traditional REST backend. If you are using a JS web-framework (e.g. a React-based framework) to build your web application, you may find `PySandbox` easier to use with its pure JS invocation without needing to rely on `<script type="py">` and `<py-script>` tags.
2 changes: 1 addition & 1 deletion docs/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"extends": "astro/tsconfigs/strict"
}
}
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@
"build": "tsup",
"dev": "tsup --watch",
"format:js": "prettier -w src",
"format:py": "black src",
"format": "yarn format:js && yarn format:py",
"format:py": "black src serve.py",
"format:scripts": "prettier -w .github/workflows *.mjs *.ts *.md",
"format": "yarn format:js && yarn format:py && yarn format:scripts",
"serve": "python serve.py",
"prepare": "husky install",
"prepublish": "yarn build",
Expand Down
30 changes: 16 additions & 14 deletions serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,29 @@
import socketserver
import sys


class Handler(SimpleHTTPRequestHandler):
extensions_map = {
'': 'application/octet-stream',
'.css': 'text/css',
'.html': 'text/html',
'.jpg': 'image/jpg',
'.js': 'application/x-javascript',
'.json': 'application/json',
'.manifest': 'text/cache-manifest',
'.png': 'image/png',
'.wasm': 'application/wasm',
'.xml': 'application/xml',
"": "application/octet-stream",
".css": "text/css",
".html": "text/html",
".jpg": "image/jpg",
".js": "application/x-javascript",
".json": "application/json",
".manifest": "text/cache-manifest",
".png": "image/png",
".wasm": "application/wasm",
".xml": "application/xml",
}

def end_headers(self):
self.send_header('Access-Control-Allow-Origin', '*')
self.send_header('Cross-Origin-Embedder-Policy', 'require-corp')
self.send_header('Cross-Origin-Opener-Policy', 'same-origin')
self.send_header("Access-Control-Allow-Origin", "*")
self.send_header("Cross-Origin-Embedder-Policy", "require-corp")
self.send_header("Cross-Origin-Opener-Policy", "same-origin")
SimpleHTTPRequestHandler.end_headers(self)

if __name__ == '__main__':

if __name__ == "__main__":
port = int(sys.argv[1]) if len(sys.argv) > 1 else 8000
with socketserver.TCPServer(("localhost", port), Handler) as httpd:
print("Serving on port", port)
Expand Down

0 comments on commit a6014c8

Please sign in to comment.