├── docs ├── .gitignore ├── Gemfile ├── sidebar.json ├── _data │ ├── topnav.yml │ └── sidebars │ │ └── home_sidebar.yml ├── sitemap.xml ├── feed.xml ├── _config.yml ├── index.html └── core.html ├── simple_doexport ├── __init__.py ├── _nbdev.py └── core.py ├── MANIFEST.in ├── README.md ├── .devcontainer.json ├── Makefile ├── docker-compose.yml ├── .github └── workflows │ └── main.yml ├── index.ipynb ├── .gitignore ├── CONTRIBUTING.md ├── settings.ini ├── setup.py ├── 00_core.ipynb └── LICENSE /docs/.gitignore: -------------------------------------------------------------------------------- 1 | _site/ 2 | -------------------------------------------------------------------------------- /simple_doexport/__init__.py: -------------------------------------------------------------------------------- 1 | __version__ = "0.0.1" 2 | -------------------------------------------------------------------------------- /docs/Gemfile: -------------------------------------------------------------------------------- 1 | source "https://rubygems.org" 2 | 3 | gem "jekyll", ">= 3.7" 4 | gem "jekyll-remote-theme" 5 | -------------------------------------------------------------------------------- /docs/sidebar.json: -------------------------------------------------------------------------------- 1 | { 2 | "simple_doexport": { 3 | "Overview": "/", 4 | "Export stata_kernel notebook": "core.html" 5 | } 6 | } -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include settings.ini 2 | include LICENSE 3 | include CONTRIBUTING.md 4 | include README.md 5 | recursive-exclude * __pycache__ 6 | -------------------------------------------------------------------------------- /docs/_data/topnav.yml: -------------------------------------------------------------------------------- 1 | topnav: 2 | - title: Topnav 3 | items: 4 | - title: github 5 | external_url: https://github.com/{user}/{lib_name}/tree/{branch}/ 6 | 7 | #Topnav dropdowns 8 | topnav_dropdowns: 9 | - title: Topnav dropdowns 10 | folders: -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Simple Jupyter .do export 2 | > Export a stata_kernel Jupyter notebook to a Stata .do file 3 | 4 | 5 | [Under construction] 6 | 7 | ## Install 8 | 9 | `pip install simple_doexport` 10 | 11 | ## How to use 12 | 13 | [Under construction] 14 | 15 | ```python 16 | 1+1 17 | ``` 18 | 19 | 20 | 21 | 22 | 2 23 | 24 | 25 | -------------------------------------------------------------------------------- /simple_doexport/_nbdev.py: -------------------------------------------------------------------------------- 1 | # AUTOGENERATED BY NBDEV! DO NOT EDIT! 2 | 3 | __all__ = ["index", "modules", "custom_doc_links", "git_url"] 4 | 5 | index = {"read_nb": "00_core.ipynb", 6 | "notebook2do": "00_core.ipynb", 7 | "simple_doexport": "00_core.ipynb"} 8 | 9 | modules = ["core.py"] 10 | 11 | doc_url = "https://hugetim.github.io/simple_doexport/" 12 | 13 | git_url = "https://github.com/hugetim/simple_doexport/tree/master/" 14 | 15 | def custom_doc_links(name): return None 16 | -------------------------------------------------------------------------------- /docs/_data/sidebars/home_sidebar.yml: -------------------------------------------------------------------------------- 1 | 2 | ################################################# 3 | ### THIS FILE WAS AUTOGENERATED! DO NOT EDIT! ### 4 | ################################################# 5 | # Instead edit ../../sidebar.json 6 | entries: 7 | - folders: 8 | - folderitems: 9 | - output: web,pdf 10 | title: Overview 11 | url: / 12 | - output: web,pdf 13 | title: Export stata_kernel notebook 14 | url: core.html 15 | output: web 16 | title: simple_doexport 17 | output: web 18 | title: Sidebar 19 | -------------------------------------------------------------------------------- /.devcontainer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nbdev_template-codespaces", 3 | "dockerComposeFile": "docker-compose.yml", 4 | "service": "watcher", 5 | "settings": {"terminal.integrated.shell.linux": "/bin/bash"}, 6 | "mounts": [ "source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind" ], 7 | "forwardPorts": [4000, 8080], 8 | "appPort": [4000, 8080], 9 | "extensions": ["ms-python.python", 10 | "ms-azuretools.vscode-docker"], 11 | "runServices": ["notebook", "jekyll", "watcher"], 12 | "postStartCommand": "pip install -e ." 13 | } 14 | -------------------------------------------------------------------------------- /docs/sitemap.xml: -------------------------------------------------------------------------------- 1 | --- 2 | layout: none 3 | search: exclude 4 | --- 5 | 6 | 7 | 8 | {% for post in site.posts %} 9 | {% unless post.search == "exclude" %} 10 | 11 | {{site.url}}{{post.url}} 12 | 13 | {% endunless %} 14 | {% endfor %} 15 | 16 | 17 | {% for page in site.pages %} 18 | {% unless page.search == "exclude" %} 19 | 20 | {{site.url}}{{ page.url}} 21 | 22 | {% endunless %} 23 | {% endfor %} 24 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .ONESHELL: 2 | SHELL := /bin/bash 3 | SRC = $(wildcard ./*.ipynb) 4 | 5 | all: {lib_name} docs 6 | 7 | {lib_name}: $(SRC) 8 | nbdev_build_lib 9 | touch {lib_name} 10 | 11 | sync: 12 | nbdev_update_lib 13 | 14 | docs_serve: docs 15 | cd docs && bundle exec jekyll serve 16 | 17 | docs: $(SRC) 18 | nbdev_build_docs 19 | touch docs 20 | 21 | test: 22 | nbdev_test_nbs 23 | 24 | release: pypi conda_release 25 | nbdev_bump_version 26 | 27 | conda_release: 28 | fastrelease_conda_package 29 | 30 | pypi: dist 31 | twine upload --repository pypi dist/* 32 | 33 | dist: clean 34 | python setup.py sdist bdist_wheel 35 | 36 | clean: 37 | rm -rf dist -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3" 2 | services: 3 | fastai: &fastai 4 | restart: unless-stopped 5 | working_dir: /data 6 | image: fastai/codespaces 7 | logging: 8 | driver: json-file 9 | options: 10 | max-size: 50m 11 | stdin_open: true 12 | tty: true 13 | volumes: 14 | - .:/data/ 15 | 16 | notebook: 17 | <<: *fastai 18 | command: bash -c "pip install -e . && jupyter notebook --allow-root --no-browser --ip=0.0.0.0 --port=8080 --NotebookApp.token='' --NotebookApp.password=''" 19 | ports: 20 | - "8080:8080" 21 | 22 | watcher: 23 | <<: *fastai 24 | command: watchmedo shell-command --command nbdev_build_docs --pattern *.ipynb --recursive --drop 25 | network_mode: host # for GitHub Codespaces https://github.com/features/codespaces/ 26 | 27 | jekyll: 28 | <<: *fastai 29 | ports: 30 | - "4000:4000" 31 | command: > 32 | bash -c "pip install . 33 | && nbdev_build_docs && cd docs 34 | && bundle i 35 | && chmod -R u+rwx . && bundle exec jekyll serve --host 0.0.0.0" 36 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: [push, pull_request] 3 | jobs: 4 | build: 5 | runs-on: ubuntu-latest 6 | steps: 7 | - uses: actions/checkout@v1 8 | - uses: actions/setup-python@v1 9 | with: 10 | python-version: '3.6' 11 | architecture: 'x64' 12 | - name: Install the library 13 | run: | 14 | pip install nbdev jupyter 15 | pip install -e . 16 | - name: Read all notebooks 17 | run: | 18 | nbdev_read_nbs 19 | - name: Check if all notebooks are cleaned 20 | run: | 21 | echo "Check we are starting with clean git checkout" 22 | if [ -n "$(git status -uno -s)" ]; then echo "git status is not clean"; false; fi 23 | echo "Trying to strip out notebooks" 24 | nbdev_clean_nbs 25 | echo "Check that strip out was unnecessary" 26 | git status -s # display the status to see which nbs need cleaning up 27 | if [ -n "$(git status -uno -s)" ]; then echo -e "!!! Detected unstripped out notebooks\n!!!Remember to run nbdev_install_git_hooks"; false; fi 28 | - name: Check if there is no diff library/notebooks 29 | run: | 30 | if [ -n "$(nbdev_diff_nbs)" ]; then echo -e "!!! Detected difference between the notebooks and the library"; false; fi 31 | - name: Run tests 32 | run: | 33 | nbdev_test_nbs 34 | -------------------------------------------------------------------------------- /docs/feed.xml: -------------------------------------------------------------------------------- 1 | --- 2 | search: exclude 3 | layout: none 4 | --- 5 | 6 | 7 | 8 | 9 | {{ site.title | xml_escape }} 10 | {{ site.description | xml_escape }} 11 | {{ site.url }}/ 12 | 13 | {{ site.time | date_to_rfc822 }} 14 | {{ site.time | date_to_rfc822 }} 15 | Jekyll v{{ jekyll.version }} 16 | {% for post in site.posts limit:10 %} 17 | 18 | {{ post.title | xml_escape }} 19 | {{ post.content | xml_escape }} 20 | {{ post.date | date_to_rfc822 }} 21 | {{ post.url | prepend: site.url }} 22 | {{ post.url | prepend: site.url }} 23 | {% for tag in post.tags %} 24 | {{ tag | xml_escape }} 25 | {% endfor %} 26 | {% for tag in page.tags %} 27 | {{ cat | xml_escape }} 28 | {% endfor %} 29 | 30 | {% endfor %} 31 | 32 | 33 | -------------------------------------------------------------------------------- /simple_doexport/core.py: -------------------------------------------------------------------------------- 1 | # AUTOGENERATED! DO NOT EDIT! File to edit: 00_core.ipynb (unless otherwise specified). 2 | 3 | __all__ = ['read_nb', 'notebook2do', 'simple_doexport'] 4 | 5 | # Cell 6 | from nbdev.imports import * 7 | from fastcore.script import * 8 | from fastcore.foundation import * 9 | #from keyword import iskeyword 10 | import nbformat 11 | 12 | # Cell 13 | def read_nb(fname): 14 | "Read the notebook in `fname`." 15 | with open(Path(fname),'r', encoding='utf8') as f: return nbformat.reads(f.read(), as_version=4) 16 | 17 | # Cell 18 | def notebook2do(fname): 19 | "Create a module file for `fname`." 20 | fname = Path(fname) 21 | nb = read_nb(fname) 22 | fname_out = f'{fname.stem}.do' 23 | with open(fname_out, 'w') as f: 24 | f.write('\n') 25 | cells = [c for c in nb['cells'] if c['cell_type'] == 'code'] 26 | for i,c in enumerate(cells): 27 | code = c['source'] 28 | if i+1 != c['execution_count']: 29 | print(f"Warning: execution count, {c['execution_count']}, differs from cell number, {i+1}.") 30 | with open(fname_out, 'a', encoding='utf8') as f: 31 | f.write(f'**# [{i+1}]:\n') 32 | f.write(code) 33 | f.write('\n\n') 34 | 35 | # Cell 36 | @call_parse 37 | def simple_doexport(fname:Param("A stata_kernel notebook name", str)): 38 | "Export notebooks matching `fname` to Stata .do files" 39 | notebook2do(fname=fname) -------------------------------------------------------------------------------- /docs/_config.yml: -------------------------------------------------------------------------------- 1 | repository: hugetim/simple_doexport 2 | output: web 3 | topnav_title: simple_doexport 4 | site_title: simple_doexport 5 | company_name: Tim Huegerich 6 | description: Export a stata_kernel Jupyter notebook to a Stata .do file 7 | # Set to false to disable KaTeX math 8 | use_math: true 9 | # Add Google analytics id if you have one and want to use it here 10 | google_analytics: 11 | # See http://nbdev.fast.ai/search for help with adding Search 12 | google_search: 13 | 14 | host: 127.0.0.1 15 | # the preview server used. Leave as is. 16 | port: 4000 17 | # the port where the preview is rendered. 18 | 19 | exclude: 20 | - .idea/ 21 | - .gitignore 22 | - vendor 23 | 24 | exclude: [vendor] 25 | 26 | highlighter: rouge 27 | markdown: kramdown 28 | kramdown: 29 | input: GFM 30 | auto_ids: true 31 | hard_wrap: false 32 | syntax_highlighter: rouge 33 | 34 | collections: 35 | tooltips: 36 | output: false 37 | 38 | defaults: 39 | - 40 | scope: 41 | path: "" 42 | type: "pages" 43 | values: 44 | layout: "page" 45 | comments: true 46 | search: true 47 | sidebar: home_sidebar 48 | topnav: topnav 49 | - 50 | scope: 51 | path: "" 52 | type: "tooltips" 53 | values: 54 | layout: "page" 55 | comments: true 56 | search: true 57 | tooltip: true 58 | 59 | sidebars: 60 | - home_sidebar 61 | 62 | plugins: 63 | - jekyll-remote-theme 64 | 65 | remote_theme: fastai/nbdev-jekyll-theme 66 | baseurl: /simple_doexport/ -------------------------------------------------------------------------------- /index.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": null, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "#hide\n", 10 | "from simple_doexport.core import *" 11 | ] 12 | }, 13 | { 14 | "cell_type": "markdown", 15 | "metadata": {}, 16 | "source": [ 17 | "# Simple Jupyter .do export\n", 18 | "\n", 19 | "> Export a stata_kernel Jupyter notebook to a Stata .do file" 20 | ] 21 | }, 22 | { 23 | "cell_type": "markdown", 24 | "metadata": {}, 25 | "source": [ 26 | "[Under construction]" 27 | ] 28 | }, 29 | { 30 | "cell_type": "markdown", 31 | "metadata": {}, 32 | "source": [ 33 | "## Install" 34 | ] 35 | }, 36 | { 37 | "cell_type": "markdown", 38 | "metadata": {}, 39 | "source": [ 40 | "`pip install simple_doexport`" 41 | ] 42 | }, 43 | { 44 | "cell_type": "markdown", 45 | "metadata": {}, 46 | "source": [ 47 | "## How to use" 48 | ] 49 | }, 50 | { 51 | "cell_type": "markdown", 52 | "metadata": {}, 53 | "source": [ 54 | "[Under construction]" 55 | ] 56 | }, 57 | { 58 | "cell_type": "code", 59 | "execution_count": null, 60 | "metadata": {}, 61 | "outputs": [ 62 | { 63 | "data": { 64 | "text/plain": [ 65 | "2" 66 | ] 67 | }, 68 | "execution_count": null, 69 | "metadata": {}, 70 | "output_type": "execute_result" 71 | } 72 | ], 73 | "source": [ 74 | "1+1" 75 | ] 76 | }, 77 | { 78 | "cell_type": "code", 79 | "execution_count": null, 80 | "metadata": {}, 81 | "outputs": [], 82 | "source": [] 83 | } 84 | ], 85 | "metadata": { 86 | "kernelspec": { 87 | "display_name": "Python 3", 88 | "language": "python", 89 | "name": "python3" 90 | } 91 | }, 92 | "nbformat": 4, 93 | "nbformat_minor": 2 94 | } 95 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .jekyll-cache/ 2 | Gemfile.lock 3 | *.bak 4 | .gitattributes 5 | .last_checked 6 | .gitconfig 7 | *.bak 8 | *.log 9 | *~ 10 | ~* 11 | _tmp* 12 | tmp* 13 | tags 14 | 15 | # Byte-compiled / optimized / DLL files 16 | __pycache__/ 17 | *.py[cod] 18 | *$py.class 19 | 20 | # C extensions 21 | *.so 22 | 23 | # Distribution / packaging 24 | .Python 25 | env/ 26 | build/ 27 | develop-eggs/ 28 | dist/ 29 | downloads/ 30 | eggs/ 31 | .eggs/ 32 | lib/ 33 | lib64/ 34 | parts/ 35 | sdist/ 36 | var/ 37 | wheels/ 38 | *.egg-info/ 39 | .installed.cfg 40 | *.egg 41 | 42 | # PyInstaller 43 | # Usually these files are written by a python script from a template 44 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 45 | *.manifest 46 | *.spec 47 | 48 | # Installer logs 49 | pip-log.txt 50 | pip-delete-this-directory.txt 51 | 52 | # Unit test / coverage reports 53 | htmlcov/ 54 | .tox/ 55 | .coverage 56 | .coverage.* 57 | .cache 58 | nosetests.xml 59 | coverage.xml 60 | *.cover 61 | .hypothesis/ 62 | 63 | # Translations 64 | *.mo 65 | *.pot 66 | 67 | # Django stuff: 68 | *.log 69 | local_settings.py 70 | 71 | # Flask stuff: 72 | instance/ 73 | .webassets-cache 74 | 75 | # Scrapy stuff: 76 | .scrapy 77 | 78 | # Sphinx documentation 79 | docs/_build/ 80 | 81 | # PyBuilder 82 | target/ 83 | 84 | # Jupyter Notebook 85 | .ipynb_checkpoints 86 | 87 | # pyenv 88 | .python-version 89 | 90 | # celery beat schedule file 91 | celerybeat-schedule 92 | 93 | # SageMath parsed files 94 | *.sage.py 95 | 96 | # dotenv 97 | .env 98 | 99 | # virtualenv 100 | .venv 101 | venv/ 102 | ENV/ 103 | 104 | # Spyder project settings 105 | .spyderproject 106 | .spyproject 107 | 108 | # Rope project settings 109 | .ropeproject 110 | 111 | # mkdocs documentation 112 | /site 113 | 114 | # mypy 115 | .mypy_cache/ 116 | 117 | .vscode 118 | *.swp 119 | 120 | # osx generated files 121 | .DS_Store 122 | .DS_Store? 123 | .Trashes 124 | ehthumbs.db 125 | Thumbs.db 126 | .idea 127 | 128 | # pytest 129 | .pytest_cache 130 | 131 | # tools/trust-doc-nbs 132 | docs_src/.last_checked 133 | 134 | # symlinks to fastai 135 | docs_src/fastai 136 | tools/fastai 137 | 138 | # link checker 139 | checklink/cookies.txt 140 | 141 | # .gitconfig is now autogenerated 142 | .gitconfig 143 | 144 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to contribute 2 | 3 | ## How to get started 4 | 5 | Before anything else, please install the git hooks that run automatic scripts during each commit and merge to strip the notebooks of superfluous metadata (and avoid merge conflicts). After cloning the repository, run the following command inside it: 6 | ``` 7 | nbdev_install_git_hooks 8 | ``` 9 | 10 | ## Did you find a bug? 11 | 12 | * Ensure the bug was not already reported by searching on GitHub under Issues. 13 | * If you're unable to find an open issue addressing the problem, open a new one. Be sure to include a title and clear description, as much relevant information as possible, and a code sample or an executable test case demonstrating the expected behavior that is not occurring. 14 | * Be sure to add the complete error messages. 15 | 16 | #### Did you write a patch that fixes a bug? 17 | 18 | * Open a new GitHub pull request with the patch. 19 | * Ensure that your PR includes a test that fails without your patch, and pass with it. 20 | * Ensure the PR description clearly describes the problem and solution. Include the relevant issue number if applicable. 21 | 22 | ## PR submission guidelines 23 | 24 | * Keep each PR focused. While it's more convenient, do not combine several unrelated fixes together. Create as many branches as needing to keep each PR focused. 25 | * Do not mix style changes/fixes with "functional" changes. It's very difficult to review such PRs and it most likely get rejected. 26 | * Do not add/remove vertical whitespace. Preserve the original style of the file you edit as much as you can. 27 | * Do not turn an already submitted PR into your development playground. If after you submitted PR, you discovered that more work is needed - close the PR, do the required work and then submit a new PR. Otherwise each of your commits requires attention from maintainers of the project. 28 | * If, however, you submitted a PR and received a request for changes, you should proceed with commits inside that PR, so that the maintainer can see the incremental fixes and won't need to review the whole PR again. In the exception case where you realize it'll take many many commits to complete the requests, then it's probably best to close the PR, do the work and then submit it again. Use common sense where you'd choose one way over another. 29 | 30 | ## Do you want to contribute to the documentation? 31 | 32 | * Docs are automatically created from the notebooks in the nbs folder. 33 | 34 | -------------------------------------------------------------------------------- /settings.ini: -------------------------------------------------------------------------------- 1 | [DEFAULT] 2 | # All sections below are required unless otherwise specified 3 | host = github 4 | lib_name = simple_doexport 5 | # For Enterprise Git add variable repo_name and company name 6 | repo_name = simple_doexport 7 | # company_name = nike 8 | 9 | user = hugetim 10 | description = Export a stata_kernel Jupyter notebook to a Stata .do file 11 | keywords = Stata stata_kernel jupyter 12 | author = Tim Huegerich 13 | author_email = hugetim@gmail.com 14 | copyright = Tim Huegerich 15 | branch = master 16 | version = 0.0.1 17 | min_python = 3.6 18 | audience = Developers 19 | language = English 20 | # Set to True if you want to create a more fancy sidebar.json than the default 21 | custom_sidebar = False 22 | # Add licenses and see current list in `setup.py` 23 | license = apache2 24 | # From 1-7: Planning Pre-Alpha Alpha Beta Production Mature Inactive 25 | status = 2 26 | 27 | # Optional. Same format as setuptools requirements 28 | requirements = nbdev 29 | # Optional. Same format as setuptools console_scripts 30 | console_scripts = simple_doexport=simple_doexport.core:simple_doexport 31 | # Optional. Same format as setuptools dependency-links 32 | # dep_links = 33 | 34 | ### 35 | # You probably won't need to change anything under here, 36 | # unless you have some special requirements 37 | ### 38 | 39 | # Change to, e.g. "nbs", to put your notebooks in nbs dir instead of repo root 40 | nbs_path = . 41 | doc_path = docs 42 | 43 | # Whether to look for library notebooks recursively in the `nbs_path` dir 44 | recursive = False 45 | 46 | # Anything shown as '%(...)s' is substituted with that setting automatically 47 | doc_host = https://%(user)s.github.io 48 | #For Enterprise Git pages use: 49 | #doc_host = https://pages.github.%(company_name)s.com. 50 | 51 | 52 | doc_baseurl = /%(lib_name)s/ 53 | # For Enterprise Github pages docs use: 54 | # doc_baseurl = /%(repo_name)s/%(lib_name)s/ 55 | 56 | git_url = https://github.com/%(user)s/%(lib_name)s/tree/%(branch)s/ 57 | # For Enterprise Github use: 58 | #git_url = https://github.%(company_name)s.com/%(repo_name)s/%(lib_name)s/tree/%(branch)s/ 59 | 60 | 61 | 62 | lib_path = %(lib_name)s 63 | title = %(lib_name)s 64 | 65 | #Optional advanced parameters 66 | #Monospace docstings: adds
 tags around the doc strings, preserving newlines/indentation.
67 | #monospace_docstrings = False
68 | #Test flags: introduce here the test flags you want to use separated by |
69 | #tst_flags = 
70 | #Custom sidebar: customize sidebar.json yourself for advanced sidebars (False/True)
71 | #custom_sidebar = 
72 | #Cell spacing: if you want cell blocks in code separated by more than one new line
73 | #cell_spacing = 
74 | #Custom jekyll styles: if you want more jekyll styles than tip/important/warning, set them here
75 | #jekyll_styles = note,warning,tip,important
76 | 


--------------------------------------------------------------------------------
/docs/index.html:
--------------------------------------------------------------------------------
  1 | ---
  2 | 
  3 | title: Simple Jupyter .do export
  4 | 
  5 | 
  6 | keywords: fastai
  7 | sidebar: home_sidebar
  8 | 
  9 | summary: "Export a stata_kernel Jupyter notebook to a Stata .do file"
 10 | description: "Export a stata_kernel Jupyter notebook to a Stata .do file"
 11 | nb_path: "index.ipynb"
 12 | ---
 13 | 
 22 | 
 23 | 
24 | 25 | {% raw %} 26 | 27 |
28 | 29 |
30 | {% endraw %} 31 | 32 |
33 |
34 |

[Under construction]

35 | 36 |
37 |
38 |
39 |
40 |
41 |

Install

42 |
43 |
44 |
45 |
46 |
47 |

pip install simple_doexport

48 | 49 |
50 |
51 |
52 |
53 |
54 |

How to use

55 |
56 |
57 |
58 |
59 |
60 |

[Under construction]

61 | 62 |
63 |
64 |
65 | {% raw %} 66 | 67 |
68 |
69 | 70 |
71 |
72 |
1+1
 73 | 
74 | 75 |
76 |
77 |
78 | 79 |
80 |
81 | 82 |
83 | 84 | 85 | 86 |
87 |
2
88 |
89 | 90 |
91 | 92 |
93 |
94 | 95 |
96 | {% endraw %} 97 | 98 |
99 | 100 | 101 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from pkg_resources import parse_version 2 | from configparser import ConfigParser 3 | import setuptools,re,sys 4 | assert parse_version(setuptools.__version__)>=parse_version('36.2') 5 | 6 | # note: all settings are in settings.ini; edit there, not here 7 | config = ConfigParser(delimiters=['=']) 8 | config.read('settings.ini') 9 | cfg = config['DEFAULT'] 10 | 11 | cfg_keys = 'version description keywords author author_email'.split() 12 | expected = cfg_keys + "lib_name user branch license status min_python audience language".split() 13 | for o in expected: assert o in cfg, "missing expected setting: {}".format(o) 14 | setup_cfg = {o:cfg[o] for o in cfg_keys} 15 | 16 | if len(sys.argv)>1 and sys.argv[1]=='version': 17 | print(setup_cfg['version']) 18 | exit() 19 | 20 | licenses = { 21 | 'apache2': ('Apache Software License 2.0','OSI Approved :: Apache Software License'), 22 | 'mit': ('MIT License', 'OSI Approved :: MIT License'), 23 | 'gpl2': ('GNU General Public License v2', 'OSI Approved :: GNU General Public License v2 (GPLv2)'), 24 | 'gpl3': ('GNU General Public License v3', 'OSI Approved :: GNU General Public License v3 (GPLv3)'), 25 | 'bsd3': ('BSD License', 'OSI Approved :: BSD License'), 26 | } 27 | statuses = [ '1 - Planning', '2 - Pre-Alpha', '3 - Alpha', 28 | '4 - Beta', '5 - Production/Stable', '6 - Mature', '7 - Inactive' ] 29 | py_versions = '2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 3.0 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8'.split() 30 | 31 | lic = licenses.get(cfg['license'].lower(), (cfg['license'], None)) 32 | min_python = cfg['min_python'] 33 | 34 | requirements = ['pip', 'packaging'] 35 | if cfg.get('requirements'): requirements += cfg.get('requirements','').split() 36 | if cfg.get('pip_requirements'): requirements += cfg.get('pip_requirements','').split() 37 | dev_requirements = (cfg.get('dev_requirements') or '').split() 38 | 39 | long_description = open('README.md').read() 40 | # ![png](docs/images/output_13_0.png) 41 | for ext in ['png', 'svg']: 42 | long_description = re.sub(r'!\['+ext+'\]\((.*)\)', '!['+ext+']('+'https://raw.githubusercontent.com/{}/{}'.format(cfg['user'],cfg['lib_name'])+'/'+cfg['branch']+'/\\1)', long_description) 43 | long_description = re.sub(r'src=\"(.*)\.'+ext+'\"', 'src=\"https://raw.githubusercontent.com/{}/{}'.format(cfg['user'],cfg['lib_name'])+'/'+cfg['branch']+'/\\1.'+ext+'\"', long_description) 44 | 45 | setuptools.setup( 46 | name = cfg['lib_name'], 47 | license = lic[0], 48 | classifiers = [ 49 | 'Development Status :: ' + statuses[int(cfg['status'])], 50 | 'Intended Audience :: ' + cfg['audience'].title(), 51 | 'Natural Language :: ' + cfg['language'].title(), 52 | ] + ['Programming Language :: Python :: '+o for o in py_versions[py_versions.index(min_python):]] + (['License :: ' + lic[1] ] if lic[1] else []), 53 | url = cfg['git_url'], 54 | packages = setuptools.find_packages(), 55 | include_package_data = True, 56 | install_requires = requirements, 57 | extras_require={ 'dev': dev_requirements }, 58 | python_requires = '>=' + cfg['min_python'], 59 | long_description = long_description, 60 | long_description_content_type = 'text/markdown', 61 | zip_safe = False, 62 | entry_points = { 'console_scripts': cfg.get('console_scripts','').split() }, 63 | **setup_cfg) 64 | 65 | -------------------------------------------------------------------------------- /00_core.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": null, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "# default_exp core" 10 | ] 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "metadata": {}, 15 | "source": [ 16 | "# Export stata_kernel notebook\n", 17 | "\n", 18 | "> Export a stata_kernel Jupyter notebook to a Stata .do file" 19 | ] 20 | }, 21 | { 22 | "cell_type": "code", 23 | "execution_count": null, 24 | "metadata": {}, 25 | "outputs": [], 26 | "source": [ 27 | "#hide\n", 28 | "from nbdev.showdoc import *" 29 | ] 30 | }, 31 | { 32 | "cell_type": "markdown", 33 | "metadata": {}, 34 | "source": [ 35 | "## Basics copied from nbdev\n", 36 | "https://github.com/fastai/nbdev/blob/master/nbs/00_export.ipynb" 37 | ] 38 | }, 39 | { 40 | "cell_type": "code", 41 | "execution_count": null, 42 | "metadata": {}, 43 | "outputs": [], 44 | "source": [ 45 | "#export\n", 46 | "from nbdev.imports import *\n", 47 | "from fastcore.script import *\n", 48 | "from fastcore.foundation import *\n", 49 | "#from keyword import iskeyword\n", 50 | "import nbformat" 51 | ] 52 | }, 53 | { 54 | "cell_type": "code", 55 | "execution_count": null, 56 | "metadata": {}, 57 | "outputs": [], 58 | "source": [ 59 | "#export\n", 60 | "def read_nb(fname):\n", 61 | " \"Read the notebook in `fname`.\"\n", 62 | " with open(Path(fname),'r', encoding='utf8') as f: return nbformat.reads(f.read(), as_version=4)" 63 | ] 64 | }, 65 | { 66 | "cell_type": "markdown", 67 | "metadata": {}, 68 | "source": [ 69 | "## Simpler versions adapted from nbdev" 70 | ] 71 | }, 72 | { 73 | "cell_type": "code", 74 | "execution_count": null, 75 | "metadata": {}, 76 | "outputs": [], 77 | "source": [ 78 | "#export\n", 79 | "def notebook2do(fname):\n", 80 | " \"Create a module file for `fname`.\"\n", 81 | " fname = Path(fname)\n", 82 | " nb = read_nb(fname)\n", 83 | " fname_out = f'{fname.stem}.do'\n", 84 | " with open(fname_out, 'w') as f:\n", 85 | " f.write('\\n')\n", 86 | " cells = [c for c in nb['cells'] if c['cell_type'] == 'code']\n", 87 | " for i,c in enumerate(cells):\n", 88 | " code = c['source']\n", 89 | " if i+1 != c['execution_count']:\n", 90 | " print(f\"Warning: execution count, {c['execution_count']}, differs from cell number, {i+1}.\")\n", 91 | " with open(fname_out, 'a', encoding='utf8') as f:\n", 92 | " f.write(f'**# [{i+1}]:\\n')\n", 93 | " f.write(code)\n", 94 | " f.write('\\n\\n')" 95 | ] 96 | }, 97 | { 98 | "cell_type": "code", 99 | "execution_count": null, 100 | "metadata": {}, 101 | "outputs": [], 102 | "source": [ 103 | "#export\n", 104 | "@call_parse\n", 105 | "def simple_doexport(fname:Param(\"A stata_kernel notebook name\", str)):\n", 106 | " \"Export notebooks matching `fname` to Stata .do files\"\n", 107 | " notebook2do(fname=fname)" 108 | ] 109 | }, 110 | { 111 | "cell_type": "code", 112 | "execution_count": null, 113 | "metadata": {}, 114 | "outputs": [], 115 | "source": [ 116 | "from nbdev.export import notebook2script; notebook2script()" 117 | ] 118 | } 119 | ], 120 | "metadata": { 121 | "kernelspec": { 122 | "display_name": "Python 3", 123 | "language": "python", 124 | "name": "python3" 125 | } 126 | }, 127 | "nbformat": 4, 128 | "nbformat_minor": 2 129 | } 130 | -------------------------------------------------------------------------------- /docs/core.html: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | title: Export stata_kernel notebook 4 | 5 | 6 | keywords: fastai 7 | sidebar: home_sidebar 8 | 9 | summary: "Export a stata_kernel Jupyter notebook to a Stata .do file" 10 | description: "Export a stata_kernel Jupyter notebook to a Stata .do file" 11 | nb_path: "00_core.ipynb" 12 | --- 13 | 22 | 23 |
24 | 25 | {% raw %} 26 | 27 |
28 | 29 |
30 | {% endraw %} 31 | 32 |
33 | 37 |
38 |
39 | {% raw %} 40 | 41 |
42 | 43 |
44 | {% endraw %} 45 | 46 | {% raw %} 47 | 48 |
49 | 50 |
51 |
52 | 53 |
54 | 55 | 56 |
57 |

read_nb[source]

read_nb(fname)

58 |
59 |

Read the notebook in fname.

60 | 61 |
62 | 63 |
64 | 65 |
66 |
67 | 68 |
69 | {% endraw %} 70 | 71 | {% raw %} 72 | 73 |
74 | 75 |
76 | {% endraw %} 77 | 78 |
79 |
80 |

Simpler versions adapted from nbdev

81 |
82 |
83 |
84 | {% raw %} 85 | 86 |
87 | 88 |
89 |
90 | 91 |
92 | 93 | 94 |
95 |

notebook2do[source]

notebook2do(fname)

96 |
97 |

Create a module file for fname.

98 | 99 |
100 | 101 |
102 | 103 |
104 |
105 | 106 |
107 | {% endraw %} 108 | 109 | {% raw %} 110 | 111 |
112 | 113 |
114 | {% endraw %} 115 | 116 | {% raw %} 117 | 118 |
119 | 120 |
121 |
122 | 123 |
124 | 125 | 126 |
127 |

simple_doexport[source]

simple_doexport(fname:"A stata_kernel notebook name")

128 |
129 |

Export notebooks matching fname to Stata .do files

130 | 131 |
132 | 133 |
134 | 135 |
136 |
137 | 138 |
139 | {% endraw %} 140 | 141 | {% raw %} 142 | 143 |
144 | 145 |
146 | {% endraw %} 147 | 148 | {% raw %} 149 | 150 |
151 |
152 | 153 |
154 |
155 |
from nbdev.export import notebook2script; notebook2script()
156 | 
157 | 158 |
159 |
160 |
161 | 162 |
163 | {% endraw %} 164 | 165 |
166 | 167 | 168 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------