bare-script 5.0.4__tar.gz → 5.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {bare_script-5.0.4/src/bare_script.egg-info → bare_script-5.1.0}/PKG-INFO +22 -22
- {bare_script-5.0.4 → bare_script-5.1.0}/README.md +21 -21
- {bare_script-5.0.4 → bare_script-5.1.0}/setup.cfg +1 -1
- {bare_script-5.0.4 → bare_script-5.1.0}/src/bare_script/__init__.py +5 -13
- {bare_script-5.0.4 → bare_script-5.1.0}/src/bare_script/bare.py +4 -6
- {bare_script-5.0.4 → bare_script-5.1.0}/src/bare_script/include.py +51 -0
- bare_script-5.1.0/src/bare_script/include_source.py +5344 -0
- {bare_script-5.0.4 → bare_script-5.1.0}/src/bare_script/library.py +0 -18
- {bare_script-5.0.4 → bare_script-5.1.0}/src/bare_script/runtime.py +215 -37
- {bare_script-5.0.4 → bare_script-5.1.0}/src/bare_script/runtime_c.c +82 -46
- {bare_script-5.0.4 → bare_script-5.1.0}/src/bare_script/value.py +25 -33
- {bare_script-5.0.4 → bare_script-5.1.0/src/bare_script.egg-info}/PKG-INFO +22 -22
- {bare_script-5.0.4 → bare_script-5.1.0}/src/bare_script.egg-info/SOURCES.txt +0 -3
- bare_script-5.0.4/src/bare_script/include_source.py +0 -12042
- bare_script-5.0.4/src/bare_script/lint.py +0 -234
- bare_script-5.0.4/src/bare_script/model.py +0 -319
- bare_script-5.0.4/src/bare_script/parser.py +0 -885
- {bare_script-5.0.4 → bare_script-5.1.0}/LICENSE +0 -0
- {bare_script-5.0.4 → bare_script-5.1.0}/pyproject.toml +0 -0
- {bare_script-5.0.4 → bare_script-5.1.0}/setup.py +0 -0
- {bare_script-5.0.4 → bare_script-5.1.0}/src/bare_script/__main__.py +0 -0
- {bare_script-5.0.4 → bare_script-5.1.0}/src/bare_script/options.py +0 -0
- {bare_script-5.0.4 → bare_script-5.1.0}/src/bare_script.egg-info/dependency_links.txt +0 -0
- {bare_script-5.0.4 → bare_script-5.1.0}/src/bare_script.egg-info/entry_points.txt +0 -0
- {bare_script-5.0.4 → bare_script-5.1.0}/src/bare_script.egg-info/requires.txt +0 -0
- {bare_script-5.0.4 → bare_script-5.1.0}/src/bare_script.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: bare-script
|
|
3
|
-
Version: 5.0
|
|
3
|
+
Version: 5.1.0
|
|
4
4
|
Summary: bare-script
|
|
5
5
|
Home-page: https://github.com/craigahobbs/bare-script
|
|
6
6
|
Author: Craig A. Hobbs
|
|
@@ -55,16 +55,16 @@ confident that BareScript will execute the same regardless of the underlying run
|
|
|
55
55
|
## Executing BareScript Scripts
|
|
56
56
|
|
|
57
57
|
To execute a BareScript script, parse the script using the
|
|
58
|
-
[
|
|
58
|
+
[barescript_parse_script](https://craigahobbs.github.io/bare-script-py/scripts.html#barescript-parse-script)
|
|
59
59
|
function. Then execute the script using the
|
|
60
60
|
[execute_script](https://craigahobbs.github.io/bare-script-py/scripts.html#execute-script)
|
|
61
61
|
function. For example:
|
|
62
62
|
|
|
63
63
|
``` python
|
|
64
|
-
from bare_script import
|
|
64
|
+
from bare_script import barescript_parse_script, execute_script
|
|
65
65
|
|
|
66
66
|
# Parse the script
|
|
67
|
-
script =
|
|
67
|
+
script = barescript_parse_script('''\
|
|
68
68
|
# Double a number
|
|
69
69
|
function double(n):
|
|
70
70
|
return n * 2
|
|
@@ -99,10 +99,10 @@ functions.
|
|
|
99
99
|
``` python
|
|
100
100
|
import urllib.request
|
|
101
101
|
|
|
102
|
-
from bare_script import execute_script, fetch_http
|
|
102
|
+
from bare_script import barescript_parse_script, execute_script, fetch_http
|
|
103
103
|
|
|
104
104
|
# Parse the script
|
|
105
|
-
script =
|
|
105
|
+
script = barescript_parse_script('''\
|
|
106
106
|
# Fetch the BareScript builtin library documentation JSON
|
|
107
107
|
docs = jsonParse(systemFetch('https://craigahobbs.github.io/bare-script-py/library/library-builtin.json'))
|
|
108
108
|
|
|
@@ -126,7 +126,7 @@ The BareScript Library has 108 builtin functions
|
|
|
126
126
|
To evaluate a
|
|
127
127
|
[BareScript expression](https://craigahobbs.github.io/bare-script-py/language/#expressions),
|
|
128
128
|
parse the expression using the
|
|
129
|
-
[
|
|
129
|
+
[barescript_parse_expression](https://craigahobbs.github.io/bare-script-py/expressions.html#barescript-parse-expression)
|
|
130
130
|
function. Then evaluate the expression using the
|
|
131
131
|
[evaluate_expression](https://craigahobbs.github.io/bare-script-py/expressions.html#evaluate-expression)
|
|
132
132
|
function.
|
|
@@ -138,10 +138,10 @@ a set of built-in, spreadsheet-like functions.
|
|
|
138
138
|
For example:
|
|
139
139
|
|
|
140
140
|
``` python
|
|
141
|
-
from bare_script import
|
|
141
|
+
from bare_script import barescript_parse_expression, evaluate_expression
|
|
142
142
|
|
|
143
143
|
# Parse the expression
|
|
144
|
-
expr =
|
|
144
|
+
expr = barescript_parse_expression('2 * max(a, b, c)')
|
|
145
145
|
|
|
146
146
|
# Evaluate the expression
|
|
147
147
|
variables = {'a': 1, 'b': 2, 'c': 3}
|
|
@@ -251,21 +251,21 @@ without a native Python equivalent are omitted.
|
|
|
251
251
|
|
|
252
252
|
| Test | Language | Time (ms) | Multiple |
|
|
253
253
|
| ---------------- | ---------------- | --------: | -------: |
|
|
254
|
-
| mandelbrot | Python |
|
|
255
|
-
| | BareScript (PyC) |
|
|
256
|
-
| | BareScript (Py) |
|
|
257
|
-
| schemaValidate | Python | 21.
|
|
258
|
-
| | BareScript (PyC) |
|
|
259
|
-
| | BareScript (Py) |
|
|
254
|
+
| mandelbrot | Python | 4720.8 | |
|
|
255
|
+
| | BareScript (PyC) | 10800.0 | 2.3x |
|
|
256
|
+
| | BareScript (Py) | 334100.0 | 70.8x |
|
|
257
|
+
| schemaValidate | Python | 21.0 | |
|
|
258
|
+
| | BareScript (PyC) | 101.6 | 4.8x |
|
|
259
|
+
| | BareScript (Py) | 1404.8 | 67.0x |
|
|
260
260
|
| urlEncode | Python | 1.1 | |
|
|
261
|
-
| | BareScript (PyC) | 5.
|
|
262
|
-
| | BareScript (Py) |
|
|
263
|
-
| schemaParse | Python | 17.
|
|
264
|
-
| | BareScript (PyC) |
|
|
265
|
-
| | BareScript (Py) |
|
|
261
|
+
| | BareScript (PyC) | 5.6 | 5.3x |
|
|
262
|
+
| | BareScript (Py) | 39.1 | 37.1x |
|
|
263
|
+
| schemaParse | Python | 17.1 | |
|
|
264
|
+
| | BareScript (PyC) | 120.4 | 7.1x |
|
|
265
|
+
| | BareScript (Py) | 882.4 | 51.7x |
|
|
266
266
|
| urlDecode | Python | 1.2 | |
|
|
267
|
-
| | BareScript (PyC) |
|
|
268
|
-
| | BareScript (Py) |
|
|
267
|
+
| | BareScript (PyC) | 13.1 | 10.8x |
|
|
268
|
+
| | BareScript (Py) | 68.5 | 56.6x |
|
|
269
269
|
|
|
270
270
|
|
|
271
271
|
## Using BareScript with an AI Assistant
|
|
@@ -31,16 +31,16 @@ confident that BareScript will execute the same regardless of the underlying run
|
|
|
31
31
|
## Executing BareScript Scripts
|
|
32
32
|
|
|
33
33
|
To execute a BareScript script, parse the script using the
|
|
34
|
-
[
|
|
34
|
+
[barescript_parse_script](https://craigahobbs.github.io/bare-script-py/scripts.html#barescript-parse-script)
|
|
35
35
|
function. Then execute the script using the
|
|
36
36
|
[execute_script](https://craigahobbs.github.io/bare-script-py/scripts.html#execute-script)
|
|
37
37
|
function. For example:
|
|
38
38
|
|
|
39
39
|
``` python
|
|
40
|
-
from bare_script import
|
|
40
|
+
from bare_script import barescript_parse_script, execute_script
|
|
41
41
|
|
|
42
42
|
# Parse the script
|
|
43
|
-
script =
|
|
43
|
+
script = barescript_parse_script('''\
|
|
44
44
|
# Double a number
|
|
45
45
|
function double(n):
|
|
46
46
|
return n * 2
|
|
@@ -75,10 +75,10 @@ functions.
|
|
|
75
75
|
``` python
|
|
76
76
|
import urllib.request
|
|
77
77
|
|
|
78
|
-
from bare_script import execute_script, fetch_http
|
|
78
|
+
from bare_script import barescript_parse_script, execute_script, fetch_http
|
|
79
79
|
|
|
80
80
|
# Parse the script
|
|
81
|
-
script =
|
|
81
|
+
script = barescript_parse_script('''\
|
|
82
82
|
# Fetch the BareScript builtin library documentation JSON
|
|
83
83
|
docs = jsonParse(systemFetch('https://craigahobbs.github.io/bare-script-py/library/library-builtin.json'))
|
|
84
84
|
|
|
@@ -102,7 +102,7 @@ The BareScript Library has 108 builtin functions
|
|
|
102
102
|
To evaluate a
|
|
103
103
|
[BareScript expression](https://craigahobbs.github.io/bare-script-py/language/#expressions),
|
|
104
104
|
parse the expression using the
|
|
105
|
-
[
|
|
105
|
+
[barescript_parse_expression](https://craigahobbs.github.io/bare-script-py/expressions.html#barescript-parse-expression)
|
|
106
106
|
function. Then evaluate the expression using the
|
|
107
107
|
[evaluate_expression](https://craigahobbs.github.io/bare-script-py/expressions.html#evaluate-expression)
|
|
108
108
|
function.
|
|
@@ -114,10 +114,10 @@ a set of built-in, spreadsheet-like functions.
|
|
|
114
114
|
For example:
|
|
115
115
|
|
|
116
116
|
``` python
|
|
117
|
-
from bare_script import
|
|
117
|
+
from bare_script import barescript_parse_expression, evaluate_expression
|
|
118
118
|
|
|
119
119
|
# Parse the expression
|
|
120
|
-
expr =
|
|
120
|
+
expr = barescript_parse_expression('2 * max(a, b, c)')
|
|
121
121
|
|
|
122
122
|
# Evaluate the expression
|
|
123
123
|
variables = {'a': 1, 'b': 2, 'c': 3}
|
|
@@ -227,21 +227,21 @@ without a native Python equivalent are omitted.
|
|
|
227
227
|
|
|
228
228
|
| Test | Language | Time (ms) | Multiple |
|
|
229
229
|
| ---------------- | ---------------- | --------: | -------: |
|
|
230
|
-
| mandelbrot | Python |
|
|
231
|
-
| | BareScript (PyC) |
|
|
232
|
-
| | BareScript (Py) |
|
|
233
|
-
| schemaValidate | Python | 21.
|
|
234
|
-
| | BareScript (PyC) |
|
|
235
|
-
| | BareScript (Py) |
|
|
230
|
+
| mandelbrot | Python | 4720.8 | |
|
|
231
|
+
| | BareScript (PyC) | 10800.0 | 2.3x |
|
|
232
|
+
| | BareScript (Py) | 334100.0 | 70.8x |
|
|
233
|
+
| schemaValidate | Python | 21.0 | |
|
|
234
|
+
| | BareScript (PyC) | 101.6 | 4.8x |
|
|
235
|
+
| | BareScript (Py) | 1404.8 | 67.0x |
|
|
236
236
|
| urlEncode | Python | 1.1 | |
|
|
237
|
-
| | BareScript (PyC) | 5.
|
|
238
|
-
| | BareScript (Py) |
|
|
239
|
-
| schemaParse | Python | 17.
|
|
240
|
-
| | BareScript (PyC) |
|
|
241
|
-
| | BareScript (Py) |
|
|
237
|
+
| | BareScript (PyC) | 5.6 | 5.3x |
|
|
238
|
+
| | BareScript (Py) | 39.1 | 37.1x |
|
|
239
|
+
| schemaParse | Python | 17.1 | |
|
|
240
|
+
| | BareScript (PyC) | 120.4 | 7.1x |
|
|
241
|
+
| | BareScript (Py) | 882.4 | 51.7x |
|
|
242
242
|
| urlDecode | Python | 1.2 | |
|
|
243
|
-
| | BareScript (PyC) |
|
|
244
|
-
| | BareScript (Py) |
|
|
243
|
+
| | BareScript (PyC) | 13.1 | 10.8x |
|
|
244
|
+
| | BareScript (Py) | 68.5 | 56.6x |
|
|
245
245
|
|
|
246
246
|
|
|
247
247
|
## Using BareScript with an AI Assistant
|
|
@@ -7,13 +7,6 @@ bare-script package
|
|
|
7
7
|
|
|
8
8
|
import os
|
|
9
9
|
|
|
10
|
-
from .lint import \
|
|
11
|
-
lint_script
|
|
12
|
-
|
|
13
|
-
from .model import \
|
|
14
|
-
validate_expression, \
|
|
15
|
-
validate_script
|
|
16
|
-
|
|
17
10
|
from .options import \
|
|
18
11
|
fetch_http, \
|
|
19
12
|
fetch_read_only, \
|
|
@@ -21,13 +14,12 @@ from .options import \
|
|
|
21
14
|
log_stdout, \
|
|
22
15
|
url_file_relative
|
|
23
16
|
|
|
24
|
-
from .parser import \
|
|
25
|
-
BareScriptParserError, \
|
|
26
|
-
parse_expression, \
|
|
27
|
-
parse_script
|
|
28
|
-
|
|
29
17
|
from .runtime import \
|
|
30
|
-
|
|
18
|
+
BareScriptParserError, \
|
|
19
|
+
BareScriptRuntimeError, \
|
|
20
|
+
barescript_lint_script, \
|
|
21
|
+
barescript_parse_expression, \
|
|
22
|
+
barescript_parse_script
|
|
31
23
|
|
|
32
24
|
if not os.environ.get('BARESCRIPT_RUNTIME_PY'): # pragma: no cover
|
|
33
25
|
try:
|
|
@@ -11,10 +11,8 @@ import os
|
|
|
11
11
|
import sys
|
|
12
12
|
import time
|
|
13
13
|
|
|
14
|
-
from .lint import lint_script
|
|
15
14
|
from .options import fetch_read_write, log_stdout, url_file_relative
|
|
16
|
-
from .
|
|
17
|
-
from .runtime import SYSTEM_GLOBAL_INCLUDES_NAME
|
|
15
|
+
from .runtime import SYSTEM_GLOBAL_INCLUDES_NAME, barescript_lint_script, barescript_parse_expression, barescript_parse_script
|
|
18
16
|
from .value import value_boolean
|
|
19
17
|
if not os.environ.get('BARESCRIPT_RUNTIME_PY'): # pragma: no cover
|
|
20
18
|
try:
|
|
@@ -56,7 +54,7 @@ def main(argv=None):
|
|
|
56
54
|
# Evaluate the global variable expression arguments
|
|
57
55
|
globals_ = {}
|
|
58
56
|
for var_name, var_expr in args.var:
|
|
59
|
-
globals_[var_name] = evaluate_expression(
|
|
57
|
+
globals_[var_name] = evaluate_expression(barescript_parse_expression(var_expr))
|
|
60
58
|
|
|
61
59
|
# Get the scripts to run
|
|
62
60
|
scripts = args.scripts
|
|
@@ -102,7 +100,7 @@ def main(argv=None):
|
|
|
102
100
|
script_source = script_value
|
|
103
101
|
|
|
104
102
|
# Parse the script source
|
|
105
|
-
script =
|
|
103
|
+
script = barescript_parse_script(script_source, 1, script_name)
|
|
106
104
|
|
|
107
105
|
# Execute?
|
|
108
106
|
static_globals = None
|
|
@@ -138,7 +136,7 @@ def main(argv=None):
|
|
|
138
136
|
|
|
139
137
|
# Run the bare-script linter?
|
|
140
138
|
if args.static and ix_script >= ix_user_script:
|
|
141
|
-
warnings =
|
|
139
|
+
warnings = barescript_lint_script(script, static_globals)
|
|
142
140
|
if not warnings:
|
|
143
141
|
print(f'BareScript static analysis "{script_name}" ... OK')
|
|
144
142
|
else:
|
|
@@ -22,6 +22,7 @@ execute_script(
|
|
|
22
22
|
{
|
|
23
23
|
'statements': [
|
|
24
24
|
{'include': {'includes': [
|
|
25
|
+
{'url': 'barescriptModel.bare', 'system': True},
|
|
25
26
|
{'url': 'data.bare', 'system': True},
|
|
26
27
|
{'url': 'dataLineChart.bare', 'system': True},
|
|
27
28
|
{'url': 'dataTable.bare', 'system': True},
|
|
@@ -69,6 +70,56 @@ def _include_options():
|
|
|
69
70
|
return {'globals': _INCLUDE_GLOBALS}
|
|
70
71
|
|
|
71
72
|
|
|
73
|
+
#
|
|
74
|
+
# barescriptModel.bare
|
|
75
|
+
#
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def barescript_type_model():
|
|
79
|
+
"""
|
|
80
|
+
Get the BareScript type model
|
|
81
|
+
|
|
82
|
+
:return: The BareScript `type model <https://craigahobbs.github.io/bare-script/model/>`__
|
|
83
|
+
:rtype: dict
|
|
84
|
+
"""
|
|
85
|
+
|
|
86
|
+
return _INCLUDE_GLOBALS['barescriptTypeModel']([], _include_options())
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def barescript_validate_expression(expr):
|
|
90
|
+
"""
|
|
91
|
+
Validate an expression model
|
|
92
|
+
|
|
93
|
+
:param expr: The `expression model <https://craigahobbs.github.io/bare-script/model/#var.vName='Expression'>`__
|
|
94
|
+
:type expr: dict
|
|
95
|
+
:return: The validated expression model
|
|
96
|
+
:rtype: dict
|
|
97
|
+
:raises SchemaValidationError: A validation error occurred
|
|
98
|
+
"""
|
|
99
|
+
|
|
100
|
+
result = _INCLUDE_GLOBALS['barescriptValidateExpressionEx']([expr], _include_options())
|
|
101
|
+
if 'error' in result:
|
|
102
|
+
raise SchemaValidationError(result['error'], result['memberFqn'])
|
|
103
|
+
return result['result']
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def barescript_validate_script(script):
|
|
107
|
+
"""
|
|
108
|
+
Validate a BareScript model
|
|
109
|
+
|
|
110
|
+
:param script: The `BareScript model <https://craigahobbs.github.io/bare-script/model/#var.vName='BareScript'>`__
|
|
111
|
+
:type script: dict
|
|
112
|
+
:return: The validated BareScript model
|
|
113
|
+
:rtype: dict
|
|
114
|
+
:raises SchemaValidationError: A validation error occurred
|
|
115
|
+
"""
|
|
116
|
+
|
|
117
|
+
result = _INCLUDE_GLOBALS['barescriptValidateScriptEx']([script], _include_options())
|
|
118
|
+
if 'error' in result:
|
|
119
|
+
raise SchemaValidationError(result['error'], result['memberFqn'])
|
|
120
|
+
return result['result']
|
|
121
|
+
|
|
122
|
+
|
|
72
123
|
#
|
|
73
124
|
# data.bare
|
|
74
125
|
#
|