Skip to content

Commit

Permalink
feat: add ignored_paths option
Browse files Browse the repository at this point in the history
  • Loading branch information
lucas-bremond committed Jan 5, 2024
1 parent 81d4d33 commit 905c26e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/jupytext/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ class JupytextConfiguration(Configurable):
config=True,
)

ignored_paths = Union(
[List(Unicode()), Unicode()],
help="A list of paths that should be ignored when saving notebooks",
config=True,
)

def set_default_format_options(self, format_options, read=False):
"""Set default format option"""
if self.default_notebook_metadata_filter:
Expand Down Expand Up @@ -402,6 +408,8 @@ def load_jupytext_configuration_file(config_file, stream=None):
config.formats = short_form_multiple_formats(config.formats)
if isinstance(config.notebook_extensions, str):
config.notebook_extensions = config.notebook_extensions.split(",")
if isinstance(config.ignored_paths, str):
config.ignored_paths = config.ignored_paths.split(",")
return config


Expand Down
10 changes: 10 additions & 0 deletions src/jupytext/contentsmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,16 @@ def save(self, model, path=""):
nbk = model["content"]
try:
config = self.get_config(path)

if any(path.startswith(ignored_path) for ignored_path in config.ignored_paths):
# Remove Jupytext metadata (if any)
try:
del model["content"]["metadata"]["jupytext"]
except KeyError:
pass

return self.super.save(model, path)

jupytext_formats = notebook_formats(nbk, config, path)
self.update_paired_notebooks(path, jupytext_formats)

Expand Down

0 comments on commit 905c26e

Please sign in to comment.