Skip to content

Moves Python code out of interpreter file #207

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

Merged
merged 18 commits into from
May 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions pyscriptjs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ fmt: fmt-py fmt-ts
@echo "Format completed"

.PHONY: fmt-check
fmt-check: fmt-ts-check fmt-py
fmt-check: fmt-ts-check fmt-py-check
@echo "Format check completed"

.PHONY: fmt-ts
Expand All @@ -69,7 +69,8 @@ fmt-ts-check:

.PHONY: fmt-py
fmt-py:
$(conda_run) black -l 88 .
$(conda_run) black --skip-string-normalization .
$(conda_run) isort --profile black .

.PHONY: fmt-py-check
fmt-py-check:
Expand Down
1 change: 1 addition & 0 deletions pyscriptjs/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ dependencies:
- black
- isort
- codespell
- pre-commit
1 change: 0 additions & 1 deletion pyscriptjs/examples/micrograd_ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ def loss(batch_size=None):
plt.ylim(yy.min(), yy.max())

finish = datetime.datetime.now()
# print(f"It took {(finish-start).seconds} seconds to run this code.")
print_div(f"It took {(finish-start).seconds} seconds to run this code.")

plt
Expand Down
102 changes: 51 additions & 51 deletions pyscriptjs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 12 additions & 12 deletions pyscriptjs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "svelte-app",
"version": "1.0.0",
"name": "pyscript",
"version": "0.0.1",
"scripts": {
"build": "NODE_ENV=production rollup -c",
"dev": "rollup -c -w",
Expand All @@ -15,36 +15,36 @@
"devDependencies": {
"@rollup/plugin-commonjs": "^17.0.0",
"@rollup/plugin-node-resolve": "^11.0.0",
"@rollup/plugin-typescript": "^8.1.0",
"@rollup/plugin-typescript": "^8.3.2",
"@tsconfig/svelte": "^1.0.0",
"@typescript-eslint/eslint-plugin": "^5.20.0",
"@typescript-eslint/parser": "^5.20.0",
"autoprefixer": "^10.2.3",
"autoprefixer": "^10.4.7",
"eslint": "^8.14.0",
"eslint-plugin-svelte3": "^3.4.1",
"postcss": "^8.2.4",
"postcss": "^8.4.13",
"prettier": "^2.6.2",
"prettier-plugin-svelte": "^2.7.0",
"rollup": "^2.3.4",
"rollup": "^2.71.1",
"rollup-plugin-css-only": "^3.1.0",
"rollup-plugin-livereload": "^2.0.0",
"rollup-plugin-serve": "^1.1.0",
"rollup-plugin-svelte": "^7.0.0",
"rollup-plugin-terser": "^7.0.0",
"svelte": "^3.0.0",
"svelte": "^3.48.0",
"svelte-check": "^1.0.0",
"svelte-preprocess": "^4.6.3",
"svelte-preprocess": "^4.10.6",
"tailwindcss": "^2.0.2",
"tslib": "^2.0.0",
"typescript": "^4.1.3"
"tslib": "^2.4.0",
"typescript": "^4.6.4"
},
"dependencies": {
"@codemirror/basic-setup": "^0.19.1",
"@codemirror/lang-python": "^0.19.4",
"@codemirror/lang-python": "^0.19.5",
"@codemirror/state": "^0.19.9",
"@codemirror/theme-one-dark": "^0.19.1",
"@fortawesome/free-solid-svg-icons": "^6.0.0",
"codemirror": "^5.65.2",
"codemirror": "^5.65.3",
"js-yaml": "^4.1.0",
"sirv-cli": "^1.0.0",
"svelte-fa": "^2.4.0",
Expand Down
40 changes: 39 additions & 1 deletion pyscriptjs/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,43 @@ import { terser } from "rollup-plugin-terser";
import sveltePreprocess from "svelte-preprocess";
import typescript from "@rollup/plugin-typescript";
import css from "rollup-plugin-css-only";
import serve from 'rollup-plugin-serve'
import serve from 'rollup-plugin-serve';

import path from "path";
import fs from "fs";

function copyPythonFiles(from, to, overwrite = false) {
return {
name: 'copy-files',
generateBundle() {
const log = msg => console.log('\x1b[36m%s\x1b[0m', msg)
log(`copy files: ${from} → ${to}`)

// create folder if it doesn't exist
if (!fs.existsSync(to)){
log(`Destination folder ${to} doesn't exist. Creating...`)
fs.mkdirSync(to);
}

fs.readdirSync(from).forEach(file => {
const fromFile = `${from}/${file}`
const toFile = `${to}/${file}`
if (fromFile.endsWith(`.py`)){
log(`----> ${fromFile} → ${toFile}`)
if (fs.existsSync(toFile) && !overwrite){
log(`skipping ${fromFile} → ${toFile}`)
return
}else{
fs.copyFileSync(
path.resolve(fromFile),
path.resolve(toFile)
);
}
}
})
}
}
}

const production = !process.env.ROLLUP_WATCH || (process.env.NODE_ENV === "production");

Expand Down Expand Up @@ -68,6 +104,8 @@ export default {
sourceMap: !production,
inlineSources: !production,
}),
// Copy all the python files from source to the build folder
copyPythonFiles("./src/", "./examples/build", true),
!production && serve(),
!production && livereload("public"),
production && terser(),
Expand Down
9 changes: 1 addition & 8 deletions pyscriptjs/src/App.svelte
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
<script lang="ts">
import Tailwind from './Tailwind.svelte';
import { loadInterpreter } from './interpreter';
import {
initializers,
loadedEnvironments,
mode,
postInitializers,
pyodideLoaded,
scriptsQueue,
} from './stores';
import { initializers, loadedEnvironments, mode, postInitializers, pyodideLoaded, scriptsQueue } from './stores';

let pyodideReadyPromise;

Expand Down
Loading