Skip to content

Commit e9c6630

Browse files
committed
Initial boiler plate structure for jsPython v2
1 parent d4cfc6d commit e9c6630

19 files changed

+97
-2800
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
# dependencies
1111
/node_modules
12+
/website/node_modules
1213

1314
# IDEs and editors
1415
/.idea

.vscode/launch.json

Lines changed: 0 additions & 15 deletions
This file was deleted.

.vscode/settings.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

LICENSE

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
BSD 3-Clause License
2+
3+
Copyright (c) 2019, FalconSoft Ltd
4+
All rights reserved.
5+
6+
Redistribution and use in source and binary forms, with or without
7+
modification, are permitted provided that the following conditions are met:
8+
9+
1. Redistributions of source code must retain the above copyright notice, this
10+
list of conditions and the following disclaimer.
11+
12+
2. Redistributions in binary form must reproduce the above copyright notice,
13+
this list of conditions and the following disclaimer in the documentation
14+
and/or other materials provided with the distribution.
15+
16+
3. Neither the name of the copyright holder nor the names of its
17+
contributors may be used to endorse or promote products derived from
18+
this software without specific prior written permission.
19+
20+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
JSPython is a javascript implementation of Python language that runs within web browser or NodeJS environment. It does not transpile/compile your code into JavaScript, instead, it provides an interactive interpreter that reads Python code and carries out their instructions. With JSPython you should be able to safely use or interact any JavaScript libraries or API with a nice Python language.
33

44
```py
5-
import Math
6-
75
arr = [4, 9, 16]
86

97
def sqrt(a):
@@ -21,19 +19,21 @@ Interactive [Worksheet Systems JSPython editor](https://run.worksheet.systems/re
2119

2220
## Why would you use it?
2321
You can easily embed `JSPython` into your web app and your end users will benefit from a Python like scripting facility to:
24-
* build data transformation and data analysis tasks
22+
* to build data transformation and data analysis tasks
2523
* allow users to configure a JS objects at run-time
2624
* run a comprehensive testing scenarios
2725
* experiment with your JS Libraries or features.
26+
* bring a SAFE run time script evaluation functions to your web app
27+
* bring Python language to NodeJS environment
2828

2929
## Features
3030
Our aim here is to provide a SAFE Python experience to Javascript or NodeJS users at run-time. So far, we implement a core set of Python feature which should be OK to start coding.
3131

3232
* **Syntax and code flow** Same as Python, In `JSPython` we use indentation to indicate a block of code. All flow features like `if - else`, `for`, `while` loops - along with `break` and `continue`
3333

34-
* **Objects, Arrays** `JSPython` allows you to work with JavaScript objects and arrays and you should be able to invoke their methods and properties as normal. So, all methods including prototype functions `push()`, `pop()`, `splice()` and [any more](ttps://www.w3schools.com/js/js_array_methods.asp) will work out of box.
34+
* **Objects, Arrays** `JSPython` allows you to work with JavaScript objects and arrays and you should be able to invoke their methods and properties as normal. So, all methods including prototype functions `push()`, `pop()`, `splice()` and [any more](https://www.w3schools.com/js/js_array_methods.asp) will work out of box.
3535

36-
* **JSON** JSPython interpreter recognises [json5](https://json5.org/) style format. So, you can assign your variable a valid JSON as
36+
* **JSON** JSPython allows you to work with JSON same way as you would in JavaScript or Python dictionaries
3737

3838
* **Functions** Functions def `def` `async def`, arrow functions `=>` - (including multiline arrow functions)
3939

@@ -54,13 +54,13 @@ Although we haven't implemented all the features available in Python yet. But, w
5454
Zero install !
5555
The most simple way to get started, without anything to install, is to use the distribution available online through jsDelivr. You can choose the latest stable release :
5656
```
57-
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/jspython@0.1.0/jspython.min.js">
57+
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/jspython-interpreter/dist/jspython-interpreter.min.js">
5858
</script>
5959
```
6060

6161
Or local install
6262
```
63-
npm install jspython
63+
npm install jspython-interpreter
6464
```
6565
Run JS Python from your Javascript App or web page.
6666
### Basic
@@ -87,4 +87,6 @@ Run JS Python from your Javascript App or web page.
8787
```
8888
Also, you can provide entire JS Object or even a library.
8989

90+
## License
91+
A permissive [BSD 3-Clause License](https://github.com/jspython-dev/jspython/blob/master/LICENSE) (c) FalconSoft Ltd.
9092

index.html

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22

33
<head>
44
<title>JSPython dev</title>
5-
<script src="./node_modules/json5/dist/index.min.js"></script>
65
<script src="./node_modules/ace-builds/src-noconflict/ace.js" type="text/javascript" charset="utf-8"></script>
7-
<script src="./lib/jspython.js"></script>
8-
<script src="./lib/assets/mode-jspython.js"></script>
6+
<script src="./dist/jspython-interpreter.js"></script>
7+
<script src="./dist/assets/mode-jspython.js"></script>
98
<style>
109
.container {
1110
height: 100%;
@@ -27,13 +26,12 @@
2726

2827
<body>
2928
<div class="container">
30-
<h4>PScript development console</h4>
29+
<h4>JSPython development console</h4>
3130
<div id="editor">
32-
x = [1,2,3,4,5,6,7,8,9]
33-
x
34-
.filter(i => i > 5)
35-
.join(",")
36-
</div>
31+
[
32+
[12, 42]
33+
[22, 88]
34+
]</div>
3735
<button onclick="runInterpreter()">Run</button>
3836
<textarea id="result"></textarea>
3937
</div>
@@ -43,17 +41,15 @@ <h4>PScript development console</h4>
4341
editor.setTheme("ace/theme/monokai");
4442
editor.session.setMode("ace/mode/python");
4543

46-
const jsPython = JSPython.jsPython;
44+
const jsPython = jspython.jsPython;
4745

4846
async function runInterpreter() {
4947

5048
const scripts = editor.getValue();
5149
try {
5250
const result = await jsPython()
53-
.addFunction('returnsPromise', a1 => new Promise((s, f) => { setTimeout(() => s(a1), 10) }))
54-
.addFunction('nullValue', () => { console.log(' ** invoked!!!'); return null })
55-
.evaluate(scripts);
56-
document.getElementById('result').value = typeof result === 'object' ? JSON.stringify(result) : result
51+
.evaluate(scripts, {str: "shdsd sd,sd d s ds d"});
52+
document.getElementById('result').value = typeof result === 'object' ? JSON.stringify(result, null, '\t') : result
5753
console.log('Result => ', result);
5854
} catch (err) {
5955
document.getElementById('result').value = err;

package.json

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
{
2-
"name": "@jspython-dev/jspython",
3-
"version": "0.0.1",
2+
"name": "jspython-interpreter",
3+
"version": "2.0.1",
44
"description": "JSPython is a javascript implementation of Python language that runs within web browser or NodeJS environment",
55
"keywords": [
66
"python",
77
"interpreter",
88
"evaluator",
99
"parser"
1010
],
11-
"main": "lib/jspython.umd.js",
12-
"module": "lib/jspython.esm.js",
13-
"typings": "lib/interpreter.d.ts",
11+
"main": "dist/jspython-interpreter.min.js",
12+
"module": "dist/jspython-interpreter.esm.js",
13+
"typings": "dist/interpreter.d.ts",
1414
"files": [
15-
"lib"
15+
"dist"
1616
],
1717
"scripts": {
1818
"test": "jest",
1919
"test:dev": "jest --watch",
2020
"test:dev:debug": "node --inspect-brk node_modules/.bin/jest --runInBand --watch",
21-
"build": "npx rollup -c && npm pack",
21+
"build": "npx rollup -c",
22+
"build:publish": "npx rollup -c && npm publish",
2223
"dev": "npx rollup --config rollup.config.dev.js --watch"
2324
},
2425
"repository": {
@@ -28,27 +29,24 @@
2829
"author": {
2930
"name": "Pavlo Paska - [email protected]"
3031
},
31-
"license": "MIT",
32+
"license": "BSD 3-Clause",
3233
"bugs": {
3334
"url": "https://github.com/jspython-dev/jspython/issues"
3435
},
35-
"homepage": "https://github.com/jspython-dev/jspython#readme",
36-
"dependencies": {
37-
"@types/json5": "0.0.30",
38-
"json5": "^2.1.1"
39-
},
36+
"homepage": "https://jspython.dev",
37+
"dependencies": {},
4038
"devDependencies": {
41-
"@types/jest": "^24.0.22",
42-
"ace-builds": "^1.4.7",
43-
"jest": "^24.9.0",
44-
"rollup": "^1.26.3",
45-
"rollup-plugin-copy": "^3.1.0",
46-
"rollup-plugin-livereload": "^1.0.4",
47-
"rollup-plugin-serve": "^1.0.1",
48-
"rollup-plugin-typescript2": "^0.25.2",
49-
"rollup-plugin-uglify": "^6.0.3",
50-
"ts-jest": "^24.1.0",
51-
"tslib": "^1.10.0",
52-
"typescript": "^3.7.2"
39+
"@types/jest": "^26.0.15",
40+
"ace-builds": "^1.4.12",
41+
"jest": "^26.6.3",
42+
"rollup": "^2.33.3",
43+
"rollup-plugin-copy": "^3.3.0",
44+
"rollup-plugin-livereload": "^2.0.0",
45+
"rollup-plugin-serve": "^1.1.0",
46+
"rollup-plugin-typescript2": "^0.29.0",
47+
"rollup-plugin-uglify": "^6.0.4",
48+
"ts-jest": "^26.4.4",
49+
"tslib": "^2.0.3",
50+
"typescript": "^4.1.2"
5351
}
5452
}

rollup.config.dev.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,19 @@ export default {
66

77
input: 'src/interpreter.ts',
88
output: {
9-
name: 'JSPython',
10-
file: 'lib/jspython.js',
9+
name: 'jspython',
10+
file: 'dist/jspython-interpreter.js',
1111
format: 'umd',
1212
sourcemap: true,
13-
globals: {'json5': 'JSON5'}
13+
globals: {}
1414
},
15-
external: [
16-
'json5'
17-
],
15+
external: [],
1816
plugins: [
1917
typescript({
2018
abortOnError: false
2119
}),
2220
serve({contentBase: '', open: true}),
23-
livereload('lib')
21+
livereload('dist')
2422
],
2523
watch: {
2624
exclude: ['node_modules/**'],

rollup.config.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,24 @@ const input = 'src/interpreter.ts';
77

88
export default [{
99
input,
10-
output: { file: pkg.main, name: 'JSPython', format: 'umd', sourcemap: true, compact: true, globals: {'json5': 'JSON5'} },
11-
external: [
12-
'json5'
13-
],
10+
output: { file: pkg.main, name: 'jspython', format: 'umd', sourcemap: true, compact: true },
11+
external: [],
1412
treeshake: true,
1513
plugins: [
1614
typescript({
1715
clean: true
1816
}),
1917
copy({
2018
targets: [
21-
{ src: 'src/assets', dest: 'lib' }
19+
{ src: 'src/assets', dest: 'dist' }
2220
]
2321
}),
2422
uglify()
2523
]
2624
}, {
2725
input,
2826
output: { file: pkg.module, format: 'esm', sourcemap: true, compact: true },
29-
external: [
30-
'json5'
31-
],
27+
external: [],
3228
plugins: [
3329
typescript({
3430
clean: true

src/assets/mode-jspython.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
77
var PythonHighlightRules = function() {
88

99
var keywords = (
10-
"async|def|if|return|and|or|while|for|in|break|continue|else"
10+
"async|def|if|return|and|or|while|for|in|break|continue|else|from|import"
1111
);
1212

1313
var builtinConstants = (

src/eval/common.ts

Lines changed: 0 additions & 55 deletions
This file was deleted.

0 commit comments

Comments
 (0)