Conventions for writing code in the notebook.
Project description
pidgin
is a collection of IPython magics for creating computable essays.
if __name__ == '__main__':
%load_ext pidgin
Markdown Mode
%pidgin markdown
---
With `pidgin.markdown`, code cells accept markdown. Any indented code blocks are executed.
foo = 42
print(f"foo is {foo}")
> Accepting the `pidgin.markdown` convetion means the author agrees to indent all their code at least once; and sometimes more in nested lists.
---
With pidgin.markdown
, code cells accept markdown. Any indented code blocks are executed.
foo = 42
print(f"foo is {foo}")
Accepting the
pidgin.markdown
convetion means the author agrees to indent all their code at least once; and sometimes more in nested lists.
foo is 42
Template Mode
With templates real data can be inserted into the computational essay. An author should desire their notebook restart and run all during template mode.
%pidgin template
Skipping the first line suppresses the markdown output.
---
In template mode, `jinja2` may be invoked to template markdown and code. We already know that `foo` is 42, but can test that assertion with
assert foo is {{foo}} is 42
{% for i in range(3) %}print({{i}})
{% endfor %}
---
In template mode, jinja2
may be invoked to template markdown and code. We already know that foo
is 42, but can test that assertion with
assert foo is 42 is 42
print(0)
print(1)
print(2)
0
1
2
# Turning off magics
%pidgin --off template markdown
Turning off magics
%pidgin --off template markdown
Yaml
Start code with ---
%pidgin conventions
---
a: 42
assert a == 42
Graphviz
Start code with graph
or digraph
!conda install -y graphviz
graph { {Ipython Julia R}--Jupyter}
File "<ipython-input-9-1661b3d05729>", line 1
graph { {Ipython Julia R}--Jupyter}
^
SyntaxError: invalid syntax
Notebooks as source
pidgin uses notebooks as source; line numbers are retained so that the notebook source produces semi-sane tracebacks.
from pidgin import markdown, template, conventions
The pidgin loader allows an author to import notebooks directly as source. This means all of the pidgin documents are importable.
%%pidgin markdown template conventions
import readme
assert all(file.__file__.endswith('.ipynb') for file in (markdown, template, conventions))
Everything Should Compute
Convert a document into other formats; Restart, Run All, nbconvert
.
%%pidgin markdown template
Use pidgin a cell magic to temporarily employ any convetions.
if __name__ == '__main__':
!jupyter nbconvert --to markdown readme.ipynb
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pidgin-0.0.1.tar.gz
.
File metadata
- Download URL: pidgin-0.0.1.tar.gz
- Upload date:
- Size: 10.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7da890dfc843d41c76542063c551ab81d4de9ba8af44d7d917efb7612721a3a5 |
|
MD5 | d7b8b21111c15bdc49128a43bc59c3c4 |
|
BLAKE2b-256 | 1b95c6ac236ce3d9e3a3f174db1c161b4c7acab53baad7c2aaf129b4fe8d7b81 |
File details
Details for the file pidgin-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: pidgin-0.0.1-py3-none-any.whl
- Upload date:
- Size: 17.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fcd84acaca8e13f8489d0c66b25868c144f4c102b60fb995fd20d542013b3a74 |
|
MD5 | c03fee31b823ae8b82652e9f6d275dfb |
|
BLAKE2b-256 | 7419ee91d430425c3fba62dbcba0cb7e9d37f61c3075e19313cb27bf7adc67f3 |