Skip to content

Commit 6555a0a

Browse files
author
Eli Lamb
committed
first commit
0 parents  commit 6555a0a

14 files changed

+7255
-0
lines changed

.github/dependabot.yml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "npm"
4+
directory: "/"
5+
schedule:
6+
interval: "daily"

.github/workflows/codeql-analysis.yml

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# For most projects, this workflow file will not need changing; you simply need
2+
# to commit it to your repository.
3+
#
4+
# You may wish to alter this file to override the set of languages analyzed,
5+
# or to provide custom queries or build logic.
6+
#
7+
# ******** NOTE ********
8+
# We have attempted to detect the languages in your repository. Please check
9+
# the `language` matrix defined below to confirm you have the correct set of
10+
# supported CodeQL languages.
11+
#
12+
name: "CodeQL"
13+
14+
on:
15+
push:
16+
branches: [ main ]
17+
pull_request:
18+
# The branches below must be a subset of the branches above
19+
branches: [ main ]
20+
schedule:
21+
- cron: '21 3 * * 3'
22+
23+
jobs:
24+
analyze:
25+
name: Analyze
26+
runs-on: ubuntu-latest
27+
permissions:
28+
actions: read
29+
contents: read
30+
security-events: write
31+
32+
strategy:
33+
fail-fast: false
34+
matrix:
35+
language: [ 'javascript' ]
36+
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
37+
# Learn more:
38+
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
39+
40+
steps:
41+
- name: Checkout repository
42+
uses: actions/checkout@v2
43+
44+
# Initializes the CodeQL tools for scanning.
45+
- name: Initialize CodeQL
46+
uses: github/codeql-action/init@v1
47+
with:
48+
languages: ${{ matrix.language }}
49+
# If you wish to specify custom queries, you can do so here or in a config file.
50+
# By default, queries listed here will override any specified in a config file.
51+
# Prefix the list here with "+" to use these queries and those in the config file.
52+
# queries: ./path/to/local/query, your-org/your-repo/queries@main
53+
54+
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
55+
# If this step fails, then you should remove it and run the build manually (see below)
56+
- name: Autobuild
57+
uses: github/codeql-action/autobuild@v1
58+
59+
# ℹ️ Command-line programs to run using the OS shell.
60+
# 📚 https://git.io/JvXDl
61+
62+
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
63+
# and modify them (or add more) to build your code if your project
64+
# uses a compiled language
65+
66+
#- run: |
67+
# make bootstrap
68+
# make release
69+
70+
- name: Perform CodeQL Analysis
71+
uses: github/codeql-action/analyze@v1

.github/workflows/test.yml

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Tests
2+
"on":
3+
push:
4+
pull_request:
5+
types:
6+
- opened
7+
- synchronize
8+
- reopened
9+
10+
jobs:
11+
test:
12+
name: "Node.js v${{ matrix.node }}"
13+
runs-on: ubuntu-latest
14+
strategy:
15+
matrix:
16+
node:
17+
- 12
18+
- 14
19+
- 16
20+
steps:
21+
- uses: actions/setup-node@v1
22+
with:
23+
node-version: "${{ matrix.node }}"
24+
- uses: actions/checkout@v2
25+
- name: "Cache node_modules"
26+
uses: actions/cache@v2
27+
with:
28+
path: ~/.npm
29+
key: ${{ runner.os }}-node-v${{ matrix.node }}-${{ hashFiles('**/package-lock.json') }}
30+
restore-keys: |
31+
${{ runner.os }}-node-v${{ matrix.node }}-
32+
- name: Install Dependencies
33+
run: npm install
34+
- name: Run All Node.js Tests
35+
run: npm run test

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dist/
2+
node_modules/

.mocharc.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"extension": ["ts"],
3+
"spec": "src/**/*.test.ts",
4+
"require": "ts-node/register"
5+
}

LICENSE.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Eli Lamb
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# react-py
2+
3+
[![Build Status](https://img.shields.io/github/workflow/status/elilambnz/react-py/Tests?style=flat-square&label=Tests)](https://github.com/elilambnz/react-py/actions?query=workflow%3ATests+branch%3Amain)
4+
[![CodeQL](https://img.shields.io/github/workflow/status/elilambnz/react-py/CodeQL?style=flat-square&label=CodeQL)](https://github.com/elilambnz/react-py/actions?query=workflow%3ACodeQL+branch%3Amain)
5+
[![MIT License](https://img.shields.io/npm/l/react-py?style=flat-square)](https://github.com/elilambnz/react-py/blob/main/LICENSE.md)
6+
[![NPM Version](https://img.shields.io/npm/v/react-py?style=flat-square)](https://www.npmjs.com/package/react-py)
7+
[![NPM Bundle Size](https://img.shields.io/bundlephobia/min/react-py?style=flat-square)](https://bundlephobia.com/package/react-py)
8+
9+
Run python code directly in the browser.
10+
11+
## Getting Started
12+
13+
```
14+
npm install react-py
15+
```
16+
17+
```tsx
18+
import { useState } from "react";
19+
import { usePython, PythonProvider } from "react-py";
20+
21+
function App() {
22+
return (
23+
// Add the provider to your app
24+
<PythonProvider>
25+
<Codeblock />
26+
</PythonProvider>
27+
);
28+
}
29+
30+
function Codeblock() {
31+
const [input, setInput] = useState("");
32+
33+
// Use the usePython hook to run code and access both stdout and stderr
34+
const { runPython, stdout, stderr, isLoading } = usePython();
35+
36+
return (
37+
<>
38+
{isLoading ? <p>Loading...</p> : <p>Ready!</p>}
39+
<form>
40+
<textarea
41+
onChange={(e) => setInput(e.target.value)}
42+
placeholder="Enter your code here"
43+
/>
44+
<input
45+
type="submit"
46+
value="Submit"
47+
onClick={(e) => {
48+
e.preventDefault();
49+
runPython(input);
50+
}}
51+
/>
52+
</form>
53+
<p>Output</p>
54+
<pre>{String(stdout)}</pre>
55+
<p>Error</p>
56+
<pre>{stderr}</pre>
57+
</>
58+
);
59+
}
60+
61+
render(<App />, document.getElementById("root"));
62+
```
63+
64+
## License
65+
66+
_react-py_ is available under the MIT License.
67+
68+
## Contact
69+
70+
Eli Lamb - [elilambnz](https://github.com/elilambnz)
71+
James Ansley - [James-Ansley](https://github.com/James-Ansley)
72+
73+
## Acknowlegments
74+
75+
This project is heavily based on [Pyodide](https://pyodide.org/), a Python distribution for the browser and Node.js based on WebAssembly.

0 commit comments

Comments
 (0)