{ "cells": [ { "cell_type": "code", "execution_count": null, "id": "f67bdcff-02fd-4351-9e0e-1f3d64b5031d", "metadata": {}, "outputs": [], "source": [ "#|default_exp shortcuts" ] }, { "cell_type": "markdown", "id": "33baf27d-7b5d-4f71-9ca2-829a61ecf3ef", "metadata": {}, "source": [ "# shortcuts\n", "> Shortcuts for common operations you need to perform with nbdev" ] }, { "cell_type": "code", "execution_count": null, "id": "29a4d0e7-f540-44f4-acfb-75aa1df33112", "metadata": {}, "outputs": [], "source": [ "#|export\n", "import sys, shutil\n", "from pkg_resources import iter_entry_points as ep\n", "from os import system\n", "from nbdev.read import get_config\n", "from nbdev.test import nbdev_test\n", "from nbdev.clean import nbdev_clean\n", "from nbdev.doclinks import nbdev_export\n", "from nbdev.cli import nbdev_quarto, nbdev_sidebar, nbdev_ghp_deploy, nbdev_bump_version\n", "\n", "BASE_QUARTO_URL='https://www.quarto.org/download/latest/'\n", "\n", "def _dir(): return get_config().path(\"lib_path\").parent\n", "def _c(f, *args, **kwargs): return f.__wrapped__(*args, **kwargs)" ] }, { "cell_type": "markdown", "id": "93c9a902-6980-4322-a9b1-f6ce1aabbe0a", "metadata": {}, "source": [ "## Installation" ] }, { "cell_type": "code", "execution_count": null, "id": "7580d48f-e10e-4bb0-937e-90645b5dfd08", "metadata": {}, "outputs": [], "source": [ "#|export\n", "def _install_linux():\n", " system(f'curl -LO {BASE_QUARTO_URL}quarto-linux-amd64.deb')\n", " system('sudo dpkg -i *64.deb && rm *64.deb')\n", " \n", "def _install_mac():\n", " system(f'curl -LO {BASE_QUARTO_URL}quarto-macos.pkg')\n", " system('open quarto-macos.pkg')\n", "\n", "def install_quarto():\n", " \"Install latest Quarto on macOS or Linux, prints instructions for Windows\"\n", " system('sudo echo \"...installing Quarto\"')\n", " if 'darwin' in sys.platform: _install_mac()\n", " elif 'linux' in sys.platform: _install_linux()\n", " else: print('Please visit https://quarto.org/docs/get-started/ to install quarto')\n", " \n", "def install():\n", " \"Install Quarto and the current library\"\n", " install_quarto()\n", " if (get_config().path('lib_path')/'__init__.py').exists():\n", " system(f'pip install -e \"{_dir()}[dev]\"')" ] }, { "cell_type": "markdown", "id": "8c9f7434", "metadata": {}, "source": [ "## Docs" ] }, { "cell_type": "markdown", "id": "1296f637-f7b3-4274-aad9-9ab6c1012b0f", "metadata": {}, "source": [ "### Generate Docs" ] }, { "cell_type": "code", "execution_count": null, "id": "fafaf455-46d0-4552-aec6-fb5dd1eaa1c9", "metadata": {}, "outputs": [], "source": [ "#|export\n", "def _quarto_installed(): return bool(shutil.which('quarto'))\n", "\n", "def docs(\n", " path:str=None, # Path to notebooks\n", " doc_path:str=None, # Path to output docs\n", " symlinks:bool=False, # Follow symlinks?\n", " folder_re:str=None, # Only enter folders matching regex\n", " skip_file_glob:str=None, # Skip files matching glob\n", " skip_file_re:str=None, # Skip files matching regex\n", " preview:bool=False # Preview the site instead of building it\n", "):\n", " \"Generate docs\"\n", " if not _quarto_installed(): install()\n", " nbdev_quarto.__wrapped__(path=path, doc_path=doc_path, symlinks=symlinks, folder_re=folder_re,\n", " skip_file_glob=skip_file_glob, skip_file_re=skip_file_re, preview=preview)" ] }, { "cell_type": "markdown", "id": "e2ea5ae5-f1a1-453d-bac5-0a4f6df1961c", "metadata": {}, "source": [ "### Preview Docs" ] }, { "cell_type": "code", "execution_count": null, "id": "035d0b04-e05e-408b-83da-587b27403579", "metadata": {}, "outputs": [], "source": [ "#|export\n", "def preview():\n", " \"Start a local docs webserver\"\n", " if not _quarto_installed(): install()\n", " _c(nbdev_sidebar)\n", " _c(nbdev_quarto, preview=True)" ] }, { "cell_type": "markdown", "id": "fdd5b4d7-e7d3-4b34-8a28-42f87264ec3d", "metadata": {}, "source": [ "### Deploy Docs" ] }, { "cell_type": "code", "execution_count": null, "id": "ee274766-15d1-4680-8e7a-4e057a8dfe06", "metadata": {}, "outputs": [], "source": [ "#|export \n", "def deploy():\n", " \"Deploy docs to GitHub Pages\"\n", " docs()\n", " _c(nbdev_ghp_deploy)" ] }, { "cell_type": "markdown", "id": "e4b55c19-efe7-4ccc-9908-1c96ae9e1cd8", "metadata": {}, "source": [ "## Publish Packages" ] }, { "cell_type": "code", "execution_count": null, "id": "530c1310-d2be-4839-8f61-05c38dd4135e", "metadata": {}, "outputs": [], "source": [ "#|export\n", "def _dist(): system(f'cd {_dir()} && rm -rf dist && python setup.py sdist bdist_wheel')\n", " \n", "def pypi(ver_bump=True):\n", " \"Create and upload Python package to PyPI\"\n", " _dist()\n", " system(f'twine upload --repository pypi {_dir()}/dist/*')\n", " if ver_bump: _c(nbdev_bump_version)\n", " \n", "def conda(ver_bump=True): \n", " \"Create and upload a conda package\"\n", " system(f'fastrelease_conda_package --mambabuild --upload_user fastai')\n", " if ver_bump: _c(nbdev_bump_version)\n", " \n", "def release():\n", " \"Release both conda and PyPI packages\"\n", " pypi(ver_bump=False)\n", " conda(ver_bump=False)\n", " _c(nbdev_bump_version)" ] }, { "cell_type": "markdown", "id": "c58161f4-8c6b-4302-9963-cee952ffcb52", "metadata": {}, "source": [ "## Other Shortcuts" ] }, { "cell_type": "code", "execution_count": null, "id": "8a44f6b9-f622-4893-9e11-8015f73cc259", "metadata": {}, "outputs": [], "source": [ "#|export\n", "def prepare():\n", " \"Export, test, and clean notebooks\"\n", " _c(nbdev_export)\n", " _c(nbdev_test)\n", " _c(nbdev_clean)" ] }, { "cell_type": "markdown", "id": "280e0d6d-6559-4fc3-9478-320ce5eff0dc", "metadata": {}, "source": [ "## Help\n", "\n", "Generate help for all console scripts" ] }, { "cell_type": "code", "execution_count": null, "id": "e34f6ff4-f85b-4805-b406-121279cc9246", "metadata": {}, "outputs": [], "source": [ "#|export\n", "def chelp():\n", " \"Show help for all console scripts\"\n", " for e in ep('console_scripts'): \n", " if e.module_name.startswith('nbdev'): \n", " nm = f'\\033[1m\\033[94m{e.name}\\033[0m'\n", " spc = ' ' * (40 - len(nm))\n", " print(f'{nm} {spc}{e.load().__doc__}')" ] }, { "cell_type": "code", "execution_count": null, "id": "b50d27fb-c343-47e2-a008-7ebdd02e1356", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[1m\u001b[94mnbdev_bump_version\u001b[0m Increment version in settings.ini by one\n", "\u001b[1m\u001b[94mnbdev_clean\u001b[0m Clean all notebooks in `fname` to avoid merge conflicts\n", "\u001b[1m\u001b[94mnbdev_conda\u001b[0m Create and upload a conda package\n", "\u001b[1m\u001b[94mnbdev_create_config\u001b[0m Create a config file\n", "\u001b[1m\u001b[94mnbdev_deploy\u001b[0m Deploy docs to GitHub Pages\n", "\u001b[1m\u001b[94mnbdev_docs\u001b[0m Generate docs\n", "\u001b[1m\u001b[94mnbdev_export\u001b[0m Export notebooks in `path` to Python modules\n", "\u001b[1m\u001b[94mnbdev_filter\u001b[0m A notebook filter for Quarto\n", "\u001b[1m\u001b[94mnbdev_fix\u001b[0m Create working notebook from conflicted notebook `nbname`\n", "\u001b[1m\u001b[94mnbdev_ghp_deploy\u001b[0m Deploy docs in `doc_path` from settings.ini to GitHub Pages\n", "\u001b[1m\u001b[94mnbdev_help\u001b[0m Show help for all console scripts\n", "\u001b[1m\u001b[94mnbdev_install\u001b[0m Install Quarto and the current library\n", "\u001b[1m\u001b[94mnbdev_install_hooks\u001b[0m Install git hooks to clean and trust notebooks automatically\n", "\u001b[1m\u001b[94mnbdev_install_quarto\u001b[0m Installs latest Quarto on macOS or Linux, prints instructions for Windows\n", "\u001b[1m\u001b[94mnbdev_migrate_directives\u001b[0m Convert all directives in `fname` from v1 to v2\n", "\u001b[1m\u001b[94mnbdev_new\u001b[0m Create a new project from the current git repo\n", "\u001b[1m\u001b[94mnbdev_prepare\u001b[0m Export, test, and clean notebooks\n", "\u001b[1m\u001b[94mnbdev_preview\u001b[0m Start a local docs webserver\n", "\u001b[1m\u001b[94mnbdev_pypi\u001b[0m Create and upload Python package to PyPI\n", "\u001b[1m\u001b[94mnbdev_quarto\u001b[0m Create Quarto docs and README.md\n", "\u001b[1m\u001b[94mnbdev_release\u001b[0m Release both conda and PyPI packages\n", "\u001b[1m\u001b[94mnbdev_sidebar\u001b[0m Create sidebar.yml\n", "\u001b[1m\u001b[94mnbdev_test\u001b[0m Test in parallel notebooks matching `fname`, passing along `flags`\n", "\u001b[1m\u001b[94mnbdev_trust\u001b[0m Trust notebooks matching `fname`\n", "\u001b[1m\u001b[94mnbdev_update\u001b[0m Propagate change in modules matching `fname` to notebooks that created them\n" ] } ], "source": [ "chelp()" ] }, { "cell_type": "markdown", "id": "7c59bd7a-c859-47c4-925e-a0dd7d2f4646", "metadata": {}, "source": [ "# Export -" ] }, { "cell_type": "code", "execution_count": null, "id": "3512ccd8-c0f3-42be-a949-f324b5b0d447", "metadata": {}, "outputs": [], "source": [ "#|hide\n", "from nbdev.doclinks import nbdev_export\n", "nbdev_export()" ] }, { "cell_type": "code", "execution_count": null, "id": "c90b28e0-3b33-4d02-b263-f6b40cfea0e1", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" } }, "nbformat": 4, "nbformat_minor": 5 }