From 1a48c72548d76bc99263a47cbfbcabf2be34514a Mon Sep 17 00:00:00 2001 From: Hamel Husain Date: Thu, 12 Sep 2024 17:38:21 -0700 Subject: [PATCH] add skip_procs --- nbdev/config.py | 1 + nbdev/processors.py | 3 +- nbs/api/01_config.ipynb | 12 +----- nbs/api/10_processors.ipynb | 3 +- nbs/explanations/config.ipynb | 70 ++++++++++++++++++----------------- 5 files changed, 44 insertions(+), 45 deletions(-) diff --git a/nbdev/config.py b/nbdev/config.py index e065f7351..16de3a049 100644 --- a/nbdev/config.py +++ b/nbdev/config.py @@ -63,6 +63,7 @@ def _apply_defaults( clear_all:bool_arg=False, # Remove all cell metadata and cell outputs? cell_number:bool_arg=True, # Add cell number to the exported file put_version_in_init:bool_arg=True, # Add the version to the main __init__.py in nbdev_export + skip_procs:str='', # A list of processors that you want to skip ): "Apply default settings where missing in `cfg`." if getattr(cfg,'repo',None) is None: diff --git a/nbdev/processors.py b/nbdev/processors.py index a55c0204c..9d5f9b97f 100644 --- a/nbdev/processors.py +++ b/nbdev/processors.py @@ -282,7 +282,8 @@ def base_procs(self): def procs(self): "Processors for export" - return self.base_procs() + self.xtra_procs() + skip_procs = get_config().get('skip_procs', '').split() + return L(self.base_procs()).filter(lambda x: x.__name__ not in skip_procs) + self.xtra_procs() def nb_proc(self, nb): "Get an `NBProcessor` with these processors" diff --git a/nbs/api/01_config.ipynb b/nbs/api/01_config.ipynb index d5e44facb..72a115170 100644 --- a/nbs/api/01_config.ipynb +++ b/nbs/api/01_config.ipynb @@ -153,6 +153,7 @@ " clear_all:bool_arg=False, # Remove all cell metadata and cell outputs?\n", " cell_number:bool_arg=True, # Add cell number to the exported file\n", " put_version_in_init:bool_arg=True, # Add the version to the main __init__.py in nbdev_export\n", + " skip_procs:str='', # A list of processors that you want to skip\n", "):\n", " \"Apply default settings where missing in `cfg`.\"\n", " if getattr(cfg,'repo',None) is None:\n", @@ -195,16 +196,7 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/home/dienhoa/miniconda3/envs/se/lib/python3.9/site-packages/ghapi/core.py:102: UserWarning: Neither GITHUB_TOKEN nor GITHUB_JWT_TOKEN found: running as unauthenticated\n", - " else: warn('Neither GITHUB_TOKEN nor GITHUB_JWT_TOKEN found: running as unauthenticated')\n" - ] - } - ], + "outputs": [], "source": [ "#|hide\n", "if os.getenv('GITHUB_ACTIONS') != 'true': # GITHUB_TOKEN in actions has limited scope.\n", diff --git a/nbs/api/10_processors.ipynb b/nbs/api/10_processors.ipynb index 1dc554925..b69068248 100644 --- a/nbs/api/10_processors.ipynb +++ b/nbs/api/10_processors.ipynb @@ -779,7 +779,8 @@ "\n", " def procs(self):\n", " \"Processors for export\"\n", - " return self.base_procs() + self.xtra_procs()\n", + " skip_procs = get_config().get('skip_procs', '').split()\n", + " return L(self.base_procs()).filter(lambda x: x.__name__ not in skip_procs) + self.xtra_procs()\n", " \n", " def nb_proc(self, nb):\n", " \"Get an `NBProcessor` with these processors\"\n", diff --git a/nbs/explanations/config.ipynb b/nbs/explanations/config.ipynb index 2bb3e05cc..664684c16 100644 --- a/nbs/explanations/config.ipynb +++ b/nbs/explanations/config.ipynb @@ -41,14 +41,14 @@ "text": [ "[DEFAULT]\r\n", "lib_name = nbdev\r\n", + "repo = nbdev\r\n", "description = Create delightful software with Jupyter Notebooks\r\n", "copyright = 2020 onwards, Jeremy Howard\r\n", "keywords = nbdev fastai jupyter notebook export\r\n", "user = fastai\r\n", "author = Jeremy Howard and Hamel Husain\r\n", "author_email = j@fast.ai\r\n", - "branch = master\r\n", - "min_python = 3.7\r\n" + "branch = master\r\n" ] } ], @@ -75,39 +75,43 @@ "text/markdown": [ "| | **Type** | **Default** | **Details** |\n", "| -- | -------- | ----------- | ----------- |\n", - "| user | str | | Repo username |\n", - "| author | str | | Package author's name |\n", - "| author_email | str | | Package author's email address |\n", - "| description | str | | Short summary of the package |\n", + "| repo | str | None | Repo name |\n", + "| branch | str | None | Repo default branch |\n", + "| user | str | None | Repo username |\n", + "| author | str | None | Package author's name |\n", + "| author_email | str | None | Package author's email address |\n", + "| description | str | None | Short summary of the package |\n", "| path | str | . | Path to create config file |\n", "| cfg_name | str | settings.ini | Name of config file to create |\n", - "| lib_name | str | None | Package name, defaults to local repo folder name passed to `apply_defaults` |\n", - "| branch | str | master | Repo default branch passed to `apply_defaults` |\n", - "| git_url | str | https://github.com/%(user)s/%(lib_name)s | Repo URL passed to `apply_defaults` |\n", - "| custom_sidebar | bool_arg | False | Use a custom sidebar.yml? passed to `apply_defaults` |\n", - "| nbs_path | str | . | Path to notebooks passed to `apply_defaults` |\n", - "| lib_path | str | %(lib_name)s | Path to package root passed to `apply_defaults` |\n", - "| doc_path | str | _docs | Path to rendered docs passed to `apply_defaults` |\n", - "| tst_flags | str | | Test flags passed to `apply_defaults` |\n", - "| version | str | 0.0.1 | Version of this release passed to `apply_defaults` |\n", - "| doc_host | str | https://%(user)s.github.io | Hostname for docs passed to `apply_defaults` |\n", - "| doc_baseurl | str | /%(lib_name)s | Base URL for docs passed to `apply_defaults` |\n", - "| keywords | str | nbdev jupyter notebook python | Package keywords passed to `apply_defaults` |\n", - "| license | str | apache2 | License for the package passed to `apply_defaults` |\n", - "| copyright | str | None | Copyright for the package, defaults to '`current_year` onwards, `author`' passed to `apply_defaults` |\n", - "| status | str | 3 | Development status PyPI classifier passed to `apply_defaults` |\n", - "| min_python | str | 3.7 | Minimum Python version PyPI classifier passed to `apply_defaults` |\n", - "| audience | str | Developers | Intended audience PyPI classifier passed to `apply_defaults` |\n", - "| language | str | English | Language PyPI classifier passed to `apply_defaults` |\n", - "| recursive | bool_arg | False | Include subfolders in notebook globs? passed to `apply_defaults` |\n", - "| black_formatting | bool_arg | False | Format libraries with black? passed to `apply_defaults` |\n", - "| readme_nb | str | index.ipynb | Notebook to export as repo readme passed to `apply_defaults` |\n", - "| title | str | %(lib_name)s | Quarto website title passed to `apply_defaults` |\n", - "| allowed_metadata_keys | str | | Preserve the list of keys in the main notebook metadata passed to `apply_defaults` |\n", - "| allowed_cell_metadata_keys | str | | Preserve the list of keys in cell level metadata passed to `apply_defaults` |\n", - "| jupyter_hooks | bool | True | Run Jupyter hooks? passed to `apply_defaults` |\n", - "| clean_ids | bool | True | Remove ids from plaintext reprs? passed to `apply_defaults` |\n", - "| custom_quarto_yml | bool | False | Use a custom _quarto.yml? passed to `apply_defaults` |" + "| lib_name | str | %(repo)s | Package name |\n", + "| git_url | str | https://github.com/%(user)s/%(repo)s | Repo URL |\n", + "| custom_sidebar | bool_arg | False | Use a custom sidebar.yml? |\n", + "| nbs_path | Path | nbs | Path to notebooks |\n", + "| lib_path | Path | None | Path to package root (default: `repo` with `-` replaced by `_`) |\n", + "| doc_path | Path | _docs | Path to rendered docs |\n", + "| tst_flags | str | notest | Test flags |\n", + "| version | str | 0.0.1 | Version of this release |\n", + "| doc_host | str | https://%(user)s.github.io | Hostname for docs |\n", + "| doc_baseurl | str | /%(repo)s | Base URL for docs |\n", + "| keywords | str | nbdev jupyter notebook python | Package keywords |\n", + "| license | str | apache2 | License for the package |\n", + "| copyright | str | None | Copyright for the package, defaults to '`current_year` onwards, `author`' |\n", + "| status | str | 3 | Development status PyPI classifier |\n", + "| min_python | str | 3.7 | Minimum Python version PyPI classifier |\n", + "| audience | str | Developers | Intended audience PyPI classifier |\n", + "| language | str | English | Language PyPI classifier |\n", + "| recursive | bool_arg | True | Include subfolders in notebook globs? |\n", + "| black_formatting | bool_arg | False | Format libraries with black? |\n", + "| readme_nb | str | index.ipynb | Notebook to export as repo readme |\n", + "| title | str | %(lib_name)s | Quarto website title |\n", + "| allowed_metadata_keys | str | | Preserve the list of keys in the main notebook metadata |\n", + "| allowed_cell_metadata_keys | str | | Preserve the list of keys in cell level metadata |\n", + "| jupyter_hooks | bool_arg | False | Run Jupyter hooks? |\n", + "| clean_ids | bool_arg | True | Remove ids from plaintext reprs? |\n", + "| clear_all | bool_arg | False | Remove all cell metadata and cell outputs? |\n", + "| cell_number | bool_arg | True | Add cell number to the exported file |\n", + "| put_version_in_init | bool_arg | True | Add the version to the main __init__.py in nbdev_export |\n", + "| skip_procs | str | | A list of processors that you want to skip |" ], "text/plain": [ ""