Skip to content

Commit

Permalink
new feature jupytext-config unset-default-viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
parmentelat authored and mwouts committed Aug 26, 2023
1 parent 275317f commit 38c41ca
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
22 changes: 20 additions & 2 deletions jupytext/jupytext_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,33 @@ def fill_parser(self, subparser):
subparser.add_argument(
"doctype",
nargs="*",
help=f"the document types to be associated with the notebook editor. "
f"Defaults to {' '.join(LabConfig.DOCTYPES)}",
help=f"the document types to be associated with the notebook editor; "
f"defaults to {' '.join(LabConfig.DOCTYPES)}",
)


class UnsetDefaultViewer(SubCommand):
def __init__(self):
super().__init__("unset-default-viewer", "Unset default viewers for JupyterLab")

def main(self, args):
LabConfig().read().unset_default_viewers(args.doctype).write()
return 0

def fill_parser(self, subparser):
subparser.add_argument(
"doctype",
nargs="*",
help=f"the document types for which the default viewer will be unset; "
f"defaults to {' '.join(LabConfig.DOCTYPES)}",
)


# create the subcommands
SUBCOMMANDS = [
ListDefaultViewer(),
SetDefaultViewer(),
UnsetDefaultViewer(),
]


Expand Down
15 changes: 15 additions & 0 deletions jupytext/labconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,21 @@ def set_default_viewer(self, doctype):
if doctype not in viewers:
viewers[doctype] = "Jupytext Notebook"

def unset_default_viewers(self, doctypes=None):
if not doctypes:
doctypes = self.DOCTYPES
for doctype in doctypes:
self.unset_default_viewer(doctype)
return self

def unset_default_viewer(self, doctype):
viewers = self.config.get("@jupyterlab/docmanager-extension:plugin", {}).get(
"defaultViewers", {}
)
if doctype not in viewers:
return
del viewers[doctype]

def write(self) -> bool:
"""
write the labconfig settings file
Expand Down

0 comments on commit 38c41ca

Please sign in to comment.