-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
149 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from pathlib import Path | ||
from tempfile import TemporaryDirectory | ||
import subprocess | ||
|
||
|
||
def convert_py_to_nb(python_str): | ||
''' | ||
Given Python code as a string, returns a notebook as a string. | ||
Calls jupytext as a subprocess: | ||
Not ideal, but only the CLI is documented well. | ||
''' | ||
with TemporaryDirectory() as temp_dir: | ||
temp_dir_path = Path(temp_dir) | ||
py_path = temp_dir_path / 'input.py' | ||
py_path.write_text(python_str) | ||
nb_path = temp_dir_path / 'output.ipynb' | ||
subprocess.run( | ||
['jupytext', | ||
'--to', 'ipynb', # Target format | ||
'--output', nb_path.absolute(), # Output | ||
py_path.absolute()], # Input | ||
check=True) | ||
return nb_path.read_text() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"id": "3cf946cc", | ||
"metadata": {}, | ||
"source": [ | ||
"Introduction" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "d5a25047", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"print(2+2)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "08581071", | ||
"metadata": {}, | ||
"source": [ | ||
"Conclusion" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"jupytext": { | ||
"cell_metadata_filter": "-all", | ||
"main_language": "python", | ||
"notebook_metadata_filter": "-all" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Introduction | ||
|
||
print(2+2) | ||
|
||
# Conclusion |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import re | ||
from pathlib import Path | ||
from dp_creator_ii.converters import convert_py_to_nb | ||
|
||
|
||
def test_convert_py_to_nb(): | ||
fixtures_path = Path('dp_creator_ii/tests/fixtures') | ||
python_str = (fixtures_path / 'fake.py').read_text() | ||
actual_nb_str = convert_py_to_nb(python_str) | ||
expected_nb_str = (fixtures_path / 'fake.ipynb').read_text() | ||
|
||
def norm_nb(nb_str): | ||
normed_nb_str = re.sub(r'"id": "[^"]+"', '"id": "12345678"', nb_str) | ||
return normed_nb_str | ||
|
||
normed_actual_nb_str = norm_nb(actual_nb_str) | ||
normed_expected_nb_str = norm_nb(expected_nb_str) | ||
assert normed_actual_nb_str == normed_expected_nb_str |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ dependencies = [ | |
"shiny", | ||
"shinywidgets", | ||
"opendp[polars]", | ||
"jupytext", | ||
] | ||
|
||
[project.scripts] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,29 @@ | ||
# After making changes here, run: | ||
# pip-compile requirements-dev.in | ||
# pip-compile requirements-dev.in && pip install -r requirements-dev.txt | ||
|
||
# Developer tools: | ||
pip-tools | ||
flit | ||
autoflake | ||
|
||
# opendp | ||
opendp[polars] | ||
# For Python 3.9: | ||
scipy<1.14 | ||
|
||
|
||
# testing: | ||
# Testing: | ||
pytest | ||
flake8 | ||
mypy | ||
coverage | ||
|
||
# shiny: | ||
|
||
|
||
# Everything below should also be listed in pyproject.toml: | ||
|
||
# OpenDP: | ||
opendp[polars] | ||
# For Python 3.9: | ||
scipy<1.14 | ||
|
||
# Conversion: | ||
jupytext | ||
|
||
# Shiny: | ||
shiny | ||
shinywidgets |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters