-
Notifications
You must be signed in to change notification settings - Fork 2
JSON API, flask server #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bmaranville
wants to merge
69
commits into
python-periodictable:master
Choose a base branch
from
bmaranville:deduplicate-html
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
69 commits
Select commit
Hold shift + click to select a range
5b53f02
move creation of form object outside cgi_call
bmaranville 5bfa08a
adding pyodide version of calculator
bmaranville a716abb
remove debugging statement
bmaranville 058c936
make worker_ready message more distinct
bmaranville 1d5488f
fix call to cgi_call
bmaranville 2bfb988
adding service worker version of page
bmaranville 57e4173
adding message back to client(s) when service worker is ready
bmaranville bd45628
improve loading lifecycle for python code
bmaranville 62251d0
adding check for hard refresh - does a second soft reload to re-activ…
bmaranville 0ba99c9
use separate fetch command to make sure pyodide is ready
bmaranville e81baa3
udpate pyodide version
bmaranville fd68a34
Merge branch 'python-periodictable:master' into master
bmaranville 856f0d7
updates from upstream index.html
bmaranville aa97983
revert payload extraction from event
bmaranville 1d78352
wait for the worker to be ready
bmaranville 50ee09e
Merge remote-tracking branch 'upstream/master'
bmaranville 69f40fa
Merge remote-tracking branch 'origin/master' into pyodide
bmaranville 3439f40
make cgi a lazy import
bmaranville 0a00757
update pyodide version
bmaranville faea11d
update pyodide version
bmaranville 8e49aa8
adding new version that allows immediate interaction with the page
bmaranville 0c0d834
use module webworker
bmaranville d56564d
add workflow for deploying to gh-pages
bmaranville c5dca96
add script for getting static pyodide libraries we need
bmaranville 1c99490
use new script for getting pyodide
bmaranville e469fe9
use local pyodide
bmaranville 1ed74f5
use local nact.py
bmaranville c706e2c
add favicon.ico to site
bmaranville bdeb709
adding deploy script
bmaranville bd3fb8d
add helper file that contains full path to periodictable local wheel
bmaranville ab53c1a
use new deployment all-in-one script
bmaranville 325e3ce
use new manifest file to get full path to periodictable local wheel
bmaranville 98b9cc5
use unicode arrows in table headers instead of GIF from vendored theme
bmaranville a5cfdf4
need to export env variables for them to be picked up by deploy.sh
bmaranville 050e9ed
fix table sorting
bmaranville 7443d2d
use pip3 since legacy installs will use that
bmaranville 0f3c833
rename deploy script because there will be more than one
bmaranville c8ca32d
use renamed deploy script
bmaranville f3d0e48
remove unused page
bmaranville 395017f
remove another unused page
bmaranville 32e3e1d
adding shared css
bmaranville 28bd6e2
use shared css
bmaranville f07c4d1
capture errors and return to client, like is done in cgi interface
bmaranville 3ea73f1
move api connection to separate script, and move shared main app code…
bmaranville 1d8054d
adding main app code
bmaranville 8457a4c
index.html is the same as the pyodide version, except for API definition
bmaranville 6f7bbaa
add API for fetch interface (CGI)
bmaranville 49cbead
initialize API after page is done rendering
bmaranville b854322
renamed api script
bmaranville ffb7a4a
adding API for webworker (pyodide)
bmaranville f7b990f
use dict intput to api_call, convert cgi to dict
bmaranville 63ed18c
just pass JSON
bmaranville fd605fb
default index.html is webworker version (replaced in local servers)
bmaranville a1fe2e1
nact.py api_call takes a plain dict (JSON) now, no need to fake CGI f…
bmaranville 2714602
json dict always includes mass, even if empty, so handle that, and ex…
bmaranville 79d8bda
add regex replace to load the api_cgi.js API in the page, replacing a…
bmaranville d46b321
update readme for json API and flask server
bmaranville 4f6cd2e
remove server.py, replace with flask_server.py and cgi_server.py
bmaranville f59b588
use index_template, and render it with periodictable version and webw…
bmaranville 23d76c3
removing deprecated files
bmaranville dc050d9
adding flask server
bmaranville 422e5b6
update sample query
bmaranville 785bed8
replacing duplicate html with single index_template.html
bmaranville d1aa1d9
need css and all js scripts in deployment
bmaranville a25de2a
add pyodide build artifacts to .gitignore
bmaranville 76aa759
use macos-friendly sed invocation
bmaranville 4b718b1
add pyodide deploy and test instructions
bmaranville ea81f87
BSD (macos) and GNU-friendly invocation of tar
bmaranville ed65f78
need to nudge GNU tar with env variable that BSD ignores
bmaranville File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| name: Deploy static site to GitHub Pages | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - pyodide # Triggers the workflow on pushes to the pyodide branch | ||
| workflow_dispatch: # Allows manual triggering from the GitHub UI | ||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
| steps: | ||
| - name: Checkout your repository | ||
| uses: actions/checkout@v4 | ||
| # Add steps to build your static site (e.g., npm run build) | ||
| - name: Run deployment script | ||
| run: | | ||
| export PYODIDE_VERSION=0.29.3 | ||
| export TARGET_DIR=dist | ||
| ./deploy_calculator.sh | ||
| - name: Upload artifact | ||
| # The contents of the 'build' directory will be uploaded as an artifact | ||
| uses: actions/upload-pages-artifact@v4 | ||
| with: | ||
| path: 'dist/' # Change this to your build output directory (e.g., public, dist) | ||
|
|
||
| deploy: | ||
| # Add a dependency to the build job | ||
| needs: build | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| pages: write # Grants the GITHUB_TOKEN the necessary permissions to deploy to GitHub Pages | ||
| id-token: write # Required for OIDC authentication | ||
| environment: | ||
| name: github-pages | ||
| url: ${{ steps.deployment.outputs.page_url }} | ||
| steps: | ||
| - name: Deploy to GitHub Pages | ||
| id: deployment | ||
| uses: actions/deploy-pages@v4 # This action handles the deployment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| class FetchAPI { | ||
| response_callback = null; | ||
| url = null; | ||
|
|
||
| initialize (response_callback, ready_callback=() => {}, url="/api/calculate") { | ||
| this.response_callback = response_callback; | ||
| this.url = url; | ||
| ready_callback(); | ||
| } | ||
|
|
||
| submit(data) { | ||
| fetch(this.url, { | ||
| method: "POST", | ||
| body: JSON.stringify(data), | ||
| headers: { | ||
| 'Content-Type': 'application/json' | ||
| } | ||
| }) | ||
| .then(response => response.json()) | ||
| .then(json => this.response_callback(json)) | ||
| .catch(error => this.response_callback({'success':false,'detail':{'fetch error':error}})); | ||
| } | ||
| } | ||
|
|
||
| const API = new FetchAPI(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| class WebWorkerAPI { | ||
| response_callback = null; | ||
| ready_callback = null; | ||
| url = null; | ||
| pyodideWorker = null; | ||
|
|
||
| initialize (response_callback, ready_callback=() => {}, url="./webworker.js") { | ||
| this.response_callback = response_callback; | ||
| this.ready_callback = ready_callback; | ||
| this.url = url; | ||
| this.pyodideWorker = new Worker(this.url, {type: "module"}); | ||
| this.pyodideWorker.onmessage = (event) => { | ||
| if ('worker_ready' in event.data) { | ||
| this.ready_callback(); | ||
| } | ||
| else { | ||
| this.response_callback(event.data); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| submit(data) { | ||
| this.pyodideWorker.postMessage({ | ||
| data: data | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| const API = new WebWorkerAPI(); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need pyodide instructions. Something like: