-
Notifications
You must be signed in to change notification settings - Fork 0
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
17 changed files
with
1,683 additions
and
0 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,14 @@ | ||
name: Deploy to GitHub Pages | ||
|
||
permissions: | ||
contents: write | ||
pages: write | ||
|
||
on: | ||
push: | ||
branches: [ "main", "master" ] | ||
workflow_dispatch: | ||
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
steps: [uses: fastai/workflows/quarto-ghp@master] |
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,7 @@ | ||
name: CI | ||
on: [workflow_dispatch, pull_request, push] | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: [uses: fastai/workflows/nbdev-ci@master] |
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,151 @@ | ||
_docs/ | ||
_proc/ | ||
|
||
*.bak | ||
.gitattributes | ||
.last_checked | ||
.gitconfig | ||
*.bak | ||
*.log | ||
*~ | ||
~* | ||
_tmp* | ||
tmp* | ||
tags | ||
*.pkg | ||
|
||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
env/ | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
.hypothesis/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# pyenv | ||
.python-version | ||
|
||
# celery beat schedule file | ||
celerybeat-schedule | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# dotenv | ||
.env | ||
|
||
# virtualenv | ||
.venv | ||
venv/ | ||
ENV/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
|
||
.vscode | ||
*.swp | ||
|
||
# osx generated files | ||
.DS_Store | ||
.DS_Store? | ||
.Trashes | ||
ehthumbs.db | ||
Thumbs.db | ||
.idea | ||
|
||
# pytest | ||
.pytest_cache | ||
|
||
# tools/trust-doc-nbs | ||
docs_src/.last_checked | ||
|
||
# symlinks to fastai | ||
docs_src/fastai | ||
tools/fastai | ||
|
||
# link checker | ||
checklink/cookies.txt | ||
|
||
# .gitconfig is now autogenerated | ||
.gitconfig | ||
|
||
# Quarto installer | ||
.deb | ||
.pkg | ||
|
||
# Quarto | ||
.quarto |
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 @@ | ||
include settings.ini | ||
include LICENSE | ||
include CONTRIBUTING.md | ||
include README.md | ||
recursive-exclude * __pycache__ |
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,145 @@ | ||
# testcell | ||
|
||
<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! --> | ||
|
||
**TL;DR**: `%%testcell` prevents your testing cells from affecting the | ||
global namespace. | ||
|
||
The Python cell magic `%%testcell` executes a cell without *polluting* | ||
the notebook’s global variables. This is useful whenever you want to | ||
test your code without having any of the local variables escape that | ||
cell. | ||
|
||
What’s happening under the hood is that your cell code, before being | ||
executed, is wrapped in a temporary function that will be deleted after | ||
execution. To give you the feeling of “seamless integration” the last | ||
line is optionally wrapped with a `display` statement if needed. | ||
|
||
**WARNING:** this don’t protect you from *the side effects of your code* | ||
like deleting a file or mutating the state of a global variable. | ||
|
||
## Install | ||
|
||
``` sh | ||
pip install testcell | ||
``` | ||
|
||
## How to use | ||
|
||
just import it with `import testcell` and then use the `%%testcell` cell | ||
magic. | ||
|
||
``` python | ||
%%testcell | ||
a = "'a' is not polluting global scope" | ||
a | ||
``` | ||
|
||
"'a' is not polluting global scope" | ||
|
||
``` python | ||
assert 'a' not in locals() | ||
``` | ||
|
||
What is happening under the hood is that `%%testcell` wraps your cell’s | ||
code with a function, execute it and then deletes it. Adding the | ||
`verbose` keywork will print which code will be executed. | ||
|
||
``` python | ||
%%testcell verbose | ||
a = "'a' is not polluting global scope" | ||
a | ||
``` | ||
|
||
|
||
### BEGIN | ||
def _test_cell_(): | ||
#| echo: false | ||
a = "'a' is not polluting global scope" | ||
display(a) | ||
try: | ||
_test_cell_() | ||
finally: | ||
del _test_cell_ | ||
### END | ||
|
||
"'a' is not polluting global scope" | ||
|
||
If you’re just interested in seeing what will be executed, but actually | ||
not executing it, you ca use `dryrun` option: | ||
|
||
``` python | ||
%%testcell dryrun | ||
a = "'a' is not polluting global scope" | ||
a | ||
``` | ||
|
||
|
||
### BEGIN | ||
def _test_cell_(): | ||
#| echo: false | ||
a = "'a' is not polluting global scope" | ||
display(a) | ||
try: | ||
_test_cell_() | ||
finally: | ||
del _test_cell_ | ||
### END | ||
|
||
On top of *wrapping* your cell’s code, it will optinally add a | ||
`display(...)` call on your last cell’s row, trying to emulate what a | ||
real cell usually does. If you explicitly add a semicolon `;` in the | ||
end, this output will be suppressed. | ||
|
||
``` python | ||
%%testcell verbose | ||
a = "'a' is not polluting global scope" | ||
a; | ||
``` | ||
|
||
|
||
### BEGIN | ||
def _test_cell_(): | ||
#| echo: false | ||
a = "'a' is not polluting global scope" | ||
a; | ||
try: | ||
_test_cell_() | ||
finally: | ||
del _test_cell_ | ||
### END | ||
|
||
There are more cases where `display(...)` is avoided: \* `display`: if | ||
this is already present on the last line. \* `print`: even in this case | ||
no print is preserved and no other display call is added. \* | ||
`# comment...#`: these are preserved | ||
|
||
``` python | ||
%%testcell verbose | ||
a = "'a' is not polluting global scope" | ||
print(a) | ||
``` | ||
|
||
|
||
### BEGIN | ||
def _test_cell_(): | ||
#| echo: false | ||
a = "'a' is not polluting global scope" | ||
print(a) | ||
try: | ||
_test_cell_() | ||
finally: | ||
del _test_cell_ | ||
### END | ||
'a' is not polluting global scope | ||
|
||
**IMPORTANT**: this is *just wrapping your cell* and so it’s still | ||
running on your main kernel. If you modify variables that has been | ||
created outside of this cell (aka: if you have side effects) this will | ||
not protect you. | ||
|
||
## TODO: | ||
|
||
- Install as a plugin to enable it by default like other cell’s magic. | ||
- Eval possibility to run code on a new kernel to reduce even more | ||
possible side effects. |
Oops, something went wrong.