yw_core
Core elements of YesWorkflow in Python.
Installation
git clone <url>
cd yw_core
pip install .
An example using a Python notebook with 3 code cells
Here is the example Python notebook that will be used as the running example to explain the CLI and Python API.
# cell 1
x = 1
# cell 2
func(x)
# cell 3
x
CLI
Usage: yw [OPTIONS]
Options:
-f, --filepath TEXT Path of a Python notebook to extract YesWorkflow
annotations [required]
-u, --upper Extract upper estimate of cell I/O sets for YesWorkflow
annotations
--help Show this message and exit.
Lower estimate
yw -f YOUR_PYTHON_NOTEBOOK_PATH
Expected output for lower estimate:
# @BEGIN cell-1
# @OUT x
# @END cell-1
# @BEGIN cell-2
# @IN x
# @END cell-2
# @BEGIN cell-3
# @IN x
# @END cell-3
Upper estimate
yw -f YOUR_PYTHON_NOTEBOOK_PATH -u
Expected output for upper estimate:
# @BEGIN cell-1
# @OUT x
# @END cell-1
# @BEGIN cell-2
# @IN x
# @OUT x @AS x-1
# @END cell-2
# @BEGIN cell-3
# @IN x @AS x-1
# @END cell-3
Python API
Lower estimate
from yw_core.yw_core import extract_code_cells, extract_records, records2annotations
code_cells = extract_code_cells("YOUR_PYTHON_NOTEBOOK_PATH")
records = extract_records(code_cells, is_upper_estimate=False)
annotations = records2annotations(records)
Expected outputs for lower estimate:
code_cells = ['x = 1', 'func(x)', 'x']
records = [
{'inputs': set(), 'output_candidates': {'x'}, 'refers_code': set(), 'defines_code': set(), 'alias_stmt': None, 'alias_vars': set(), 'outputs': {'x'}},
{'inputs': {'x'}, 'output_candidates': set(), 'refers_code': set(), 'defines_code': set(), 'alias_stmt': None, 'alias_vars': set(), 'outputs': set()},
{'inputs': {'x'}, 'output_candidates': set(), 'refers_code': set(), 'defines_code': set(), 'alias_stmt': None, 'alias_vars': set(), 'outputs': set()}
]
annotations = '# @BEGIN cell-1\n# @OUT x\n# @END cell-1\n\n# @BEGIN cell-2\n# @IN x\n# @END cell-2\n\n# @BEGIN cell-3\n# @IN x\n# @END cell-3'
Upper estimate
from yw_core.yw_core import extract_code_cells, extract_records, records2annotations
code_cells = extract_code_cells("YOUR_PYTHON_NOTEBOOK_PATH")
records = extract_records(code_cells, is_upper_estimate=True)
annotations = records2annotations(records)
Expected outputs for upper estimate:
code_cells = ['x = 1', 'func(x)', 'x']
records = [
{'inputs': set(), 'output_candidates': {'x'}, 'refers_code': set(), 'defines_code': set(), 'alias_stmt': None, 'alias_vars': set(), 'outputs': {'x'}},
{'inputs': {'x'}, 'output_candidates': {'x'}, 'refers_code': set(), 'defines_code': set(), 'alias_stmt': None, 'alias_vars': set(), 'outputs': {'x-1'}},
{'inputs': {'x-1'}, 'output_candidates': set(), 'refers_code': set(), 'defines_code': set(), 'alias_stmt': None, 'alias_vars': set(), 'outputs': set()}
]
annotations = '# @BEGIN cell-1\n# @OUT x\n# @END cell-1\n\n# @BEGIN cell-2\n# @IN x\n# @OUT x @AS x-1\n# @END cell-2\n\n# @BEGIN cell-3\n# @IN x @AS x-1\n# @END cell-3'
Tests
We use tox to run Python unit test (pytest):
# If you the tox package is not installed
pip install tox
# Run unit test
tox
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
yw_core-0.1.0.tar.gz
(12.4 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file yw_core-0.1.0.tar.gz.
File metadata
- Download URL: yw_core-0.1.0.tar.gz
- Upload date:
- Size: 12.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.1.0 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
10e72bcb8ab56a8644ff9275a1a8ed421cf04eb9b9dec2e21723ac3097d8ae4b
|
|
| MD5 |
24aa5634dc3871e56c4485768404155f
|
|
| BLAKE2b-256 |
32978ee49e06afcc4b3bd16bbda3f4cebb4fbdf13f5bdf50028fc9fc7588d509
|
File details
Details for the file yw_core-0.1.0-py3-none-any.whl.
File metadata
- Download URL: yw_core-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.1.0 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ab2519c130006d51aa53c34630570355ebb4a6b8044ec6588d4ff69fc081cbbd
|
|
| MD5 |
fff51c542b4911d8bab4a93bbdf3a128
|
|
| BLAKE2b-256 |
3583e837426ff470a7e8512a201cb8c13a8649e23cf5d249f7a9c49d45660b5d
|