Skip to content
This repository has been archived by the owner on Jan 27, 2022. It is now read-only.

feat: Add Execution Engines #132

Merged
merged 79 commits into from
Sep 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
3825093
feat: Add Parameter schema
beneboy Aug 9, 2019
288c9b3
chore(Typescript): Remove old files before generating new
nokome Aug 12, 2019
0976a98
fix(Code): Refactor code related classes
nokome Aug 12, 2019
90981df
chore(Typescript): Add warning regarding schema title
nokome Aug 12, 2019
31a8772
feat(Parameter): Add schema schemas
nokome Aug 12, 2019
71c956a
tests(Typescript): Run `schema.build` before any tests
nokome Aug 12, 2019
fc8ec1e
test(JSON Schema): Refactor when schemas are generated
nokome Aug 12, 2019
f2846fe
test(Typescript): Fix type guards and binding tests
nokome Aug 12, 2019
e56cbe0
chore(Typescript): Linting
nokome Aug 12, 2019
ca6dfdc
docs(*): Refactor to use codeFragment
nokome Aug 12, 2019
ef6240e
feat: Add Python command line executor
beneboy Aug 13, 2019
307b85b
fix: Fixed behaviour of ConstantSchema and EnumSchema in python executor
beneboy Aug 13, 2019
68a72ae
feat: Added first draft of JavaScript executor
beneboy Aug 13, 2019
e15c620
chore: Refactor JS executor into functions only and add some docs
beneboy Aug 13, 2019
3b5c77f
chore: Split Python document parsing out from Executor class
beneboy Aug 14, 2019
58dd65c
feat: Converting Pandas DataFrames to Datatables in Python JSON output
beneboy Aug 14, 2019
59766d3
feat: Converting matplotlib figures to ImageObjects during Py execution
beneboy Aug 15, 2019
0d7dc52
chore: Refactor Python execution to use AST
beneboy Aug 15, 2019
c07e77c
refactor(SchemaTypes): rename to avoid conflict with Schema type
nokome Aug 15, 2019
21aab2a
chore: Refactor JS executor to use AST to execute subsequent statements
beneboy Aug 15, 2019
117a43e
fix(R): Add include tag so collation order is correct
nokome Aug 16, 2019
99b7ca9
feat(R): Add compilation of CodeChunks
nokome Aug 16, 2019
8970663
feat(CodeChunk): Add more properties to CodeChunk
nokome Aug 16, 2019
a23f7a6
fix(R): Correct Datatable functions for new schema
nokome Aug 16, 2019
decee96
fix(R): Fix and improve generated bindings
nokome Aug 16, 2019
ef49094
chore(R): Ignore Makefile
nokome Aug 16, 2019
08f16fe
chore(R): Address warnings from R CMD check
nokome Aug 16, 2019
73615e9
chore(R): Add utility functions
nokome Aug 16, 2019
25491ea
test(R): Add tests for compile_code_chunk
nokome Aug 16, 2019
b960640
chore(R): Add tests for `alters` property
nokome Aug 17, 2019
5c55d4e
test(R): More tests for compile_code_chunk
nokome Aug 17, 2019
a48d7cc
chore(R): Package housekeeping
nokome Aug 17, 2019
5bbfa04
feat: Extracting features from CodeChunks
beneboy Aug 18, 2019
daaef97
chore: Add Function, Variabe and CodeError schema
beneboy Aug 20, 2019
5051eb9
fix: Treating typed variables as declarations and other as assigns
beneboy Aug 20, 2019
5fee303
chore: Rebuilt R types
beneboy Aug 20, 2019
41fa3a2
chore(R): Linting
nokome Aug 20, 2019
05c8872
fix: TS generation of function function and type usage in CodeError
beneboy Aug 20, 2019
f5504d5
feat: Added parsing of alters and error capturing
beneboy Aug 20, 2019
efafab3
chore: Made code error setting code more DRY
beneboy Aug 20, 2019
9e8fdff
chore: Add exception trace to CodeError
beneboy Aug 20, 2019
82eca11
chore: Added code duration recording to CodeChunk/Python
beneboy Aug 20, 2019
a977a67
feat(Js/WIP): Parsing of CodeChunk properties
beneboy Aug 21, 2019
e646315
feat: Added parsing of If, While etc to JS interpreter
beneboy Aug 21, 2019
3c977a0
feat: Added 'repeats' and 'extends' properties for Parameter
beneboy Aug 22, 2019
eddb67a
chore(Py/WIP): Refactor parser to be recursive and handle more types
beneboy Aug 22, 2019
98422ca
feat(Py): Added Exception parsing
beneboy Aug 22, 2019
1d7007d
feat(Py): Added Python args/kwargs parsing
beneboy Aug 22, 2019
d84ecab
feat(JS): Added parsing of try/except
beneboy Aug 22, 2019
2c75755
feat(Js): Catching exceptions during parsing/execution
beneboy Aug 22, 2019
1cc28b0
feat(Js): Adding timing of CodeChunk execution
beneboy Aug 22, 2019
82285ec
fix(Py): Fixed Execution timing to include entire CodeChunk
beneboy Aug 22, 2019
a6575b5
feat(Js): Added Handling of for statements
beneboy Aug 22, 2019
4dbfc69
feat(Js): Capturing files read by readFile/readFileSync and open
beneboy Aug 25, 2019
3104fff
chore(Py/WIP): Started on unit tests for CodeChunk feature parsing
beneboy Aug 26, 2019
c57cc2f
test(Py): CodeChunkParser test complete
beneboy Aug 27, 2019
ce29a04
test(Py): Initial test for DocumentCompiler
beneboy Aug 27, 2019
ab64813
test(Py): Added Interpreter tests
beneboy Aug 28, 2019
e633951
test(Py): General execute_article testing
beneboy Aug 28, 2019
a699a1a
test(Js): Added codeChunkParser tests
beneboy Aug 29, 2019
2a6a4ab
test(Js): Added tests for CLI parameter parsing
beneboy Aug 30, 2019
5ee7933
chore: Rename executor.ts to interpreter.ts
beneboy Aug 30, 2019
0aaa57b
chore: Added documentation for TS interpreter functions
beneboy Aug 31, 2019
9dce943
feat(Py): Added checking for empty string semaphore in imports
beneboy Aug 31, 2019
829dc22
feat(JS): Added checking for empty string semaphore in imports
beneboy Aug 31, 2019
fd58968
chore(Py): Added comments throughout interpreter.py
beneboy Aug 31, 2019
e8bf41c
docs: Added instructions for running py interpreter in dev
beneboy Aug 31, 2019
1b223eb
chore(Makefile): Revert change in Makefile recipe
nokome Aug 28, 2019
01c8f37
fix: Refactor after rebasing
beneboy Aug 31, 2019
40e0ecd
test(R & Python): Update snapshots
nokome Sep 1, 2019
ae46543
chore(Python): Add tox to requirements
nokome Sep 1, 2019
c033752
chore(Python): Linting
nokome Sep 1, 2019
1d8518e
chore(R): Linting
nokome Sep 1, 2019
3cdb265
test(R): Fix compile test
nokome Sep 1, 2019
7ecb5de
chore: Fix Python linting
beneboy Sep 2, 2019
09d0978
chore: Fix Python type linting
beneboy Sep 2, 2019
8d48383
chore(*): Linting
nokome Sep 2, 2019
1f390d7
chore: Fix Python linting
beneboy Sep 2, 2019
52e25d0
ci: Installing package to get requirements under travis
beneboy Sep 2, 2019
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ py/coverage.xml
*.out.*
/ts/types.ts
.Rproj.user
py/htmlcov
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ matrix:

install:
- make -C py setup
- make -C py install

script:
- make -C py lint
Expand Down
48 changes: 48 additions & 0 deletions package-lock.json

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

6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"@stencila/dev-config": "^1.1.3",
"@stencila/encoda": "^0.61.2",
"@stencila/logga": "^1.2.1",
"@types/astring": "^1.3.0",
"@types/fs-extra": "^8.0.0",
"@types/jest": "^24.0.15",
"@types/js-yaml": "^3.12.1",
Expand All @@ -46,6 +47,7 @@
"ajv": "^6.10.2",
"better-ajv-errors": "^0.6.4",
"browser-sync": "^2.26.7",
"del": "^5.0.0",
"fs-extra": "^8.1.0",
"globby": "^10.0.1",
"husky": "^3.0.1",
Expand Down Expand Up @@ -125,5 +127,9 @@
"release": {
"extends": "@stencila/semantic-release-config",
"message": "chore(release): ${nextRelease.version}\n\n${nextRelease.notes}"
},
"dependencies": {
"astring": "^1.4.1",
"meriyah": "^1.6.10"
}
}
2 changes: 1 addition & 1 deletion py/.coveragerc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[run]
[execute_document]
omit =
*/stencila/schema/types.py
9 changes: 6 additions & 3 deletions py/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ all: setup clean regen lint test build
setup:
pip3 install --upgrade -r requirements-dev.txt

install:
python3 setup.py install

regen:
npm run build:py

lint:
pylint stencila/schema
mypy stencila/schema
pylint stencila/schema --max-line-length=120
mypy stencila/schema --ignore-missing-imports

test:
tox
Expand All @@ -17,4 +20,4 @@ build:
python3 setup.py sdist bdist_wheel

clean:
rm -rf build .coverage coverage.xml *.egg-info .tox **/__pycache__
rm -rf build .coverage htmlcov coverage.xml *.egg-info .tox **/__pycache__
42 changes: 42 additions & 0 deletions py/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,45 @@ serialized = """{"type": "Heading", "content": ["Heading Text"], "depth": 2}"""

h2 = from_json(serialized)
```

## Interpreter

This library can also be used to interpret executable documents. Once installed it can be used like this:

```bash
$ python3 -m stencila.schema execute <inputfile> <outputfile> [parameters]
```

`inputfile` and/or `outputfile` can be set to `-` to read from stdin and/or write to stdout (respectively).

`[parameters]` is a list of parameters to pass to the document –- these will differ based on what the document defines.
They can be passed either by `--parameter_name=parameter_value` or `--parameter_name parameter_value`. Each parameter
must be named.

### Usage in Development

There are three options to run the interpreter without installing this package (which can be useful when developing).

#### setup.py develop

Run `python3 setup.py develop` which will link this library into your site packages directory. You can then execute
documents with the above Interpreter command.

#### Run interpreter.py directly

You can run the `interpreter.py` script directly, the arguments are the same as running as a module in the example
above except the first `execute` argument is omitted:

```bash
$ python3 schema/py/stencila/schema/interpreter.py <inputfile> <outputfile> [parameters]
```

### cd into stencila directory

You can run the interpreter as a module by changing into the `stencila` directory first, and then ommitting the
`stencila` namespace:

```bash
$ cd schema/py/stencila
$ python3 -m schema execute <inputfile> <outputfile> [parameters]
```
3 changes: 2 additions & 1 deletion py/requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
twine
mypy
pylint
tox
tox-travis
twine
4 changes: 3 additions & 1 deletion py/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ def run(self):
python_requires='>=3.6.0',
url='https://github.com/stencila/schema',
packages=['stencila.schema'],
install_requires=[],
install_requires=[
'astor==0.8.0'
],
extras_require={},
include_package_data=True,
license='Apache-2.0',
Expand Down
35 changes: 35 additions & 0 deletions py/stencila/schema/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""
__main__.py can be executed (once this library is installed) like this:

python3 -m stencila.schema execute <inputfile> <outputfile> [parameters]

See READEME.md for more information.

Warning: `eval` and `exec` are used to run code in the document. Don't execute documents that you haven't verified
yourself.
"""

import logging
from sys import argv, stderr, stdout

from .interpreter import execute_from_cli


def cli_execute():
"""Execute an executable document, delegating to the execute_from_cli function."""
execute_from_cli(argv[2:])


def main():
"""The main entry point to this module, read the first CLI arg and call out to the corresponding function."""
command = argv[1] if len(argv) > 1 else ''

if command == 'execute':
logging.basicConfig(stream=stdout, level=logging.DEBUG)
cli_execute()
else:
stderr.write('Unknown command "{}"\n'.format(command))


if __name__ == '__main__':
main()
Loading