| 1 | """ |
| 2 | the code for |
| 3 | jupytext-config set-default-viewer |
| 4 | and related subcommands |
| 5 | """ |
| 6 | |
| 7 | import sysscip-python python python-stdlib 3.11 sys/__init__: |
| 8 | from argparsescip-python python python-stdlib 3.11 argparse/__init__: import ArgumentParserscip-python python python-stdlib 3.11 argparse/ArgumentParser# |
| 9 | from pathlibscip-python python python-stdlib 3.11 pathlib/__init__: import Pathscip-python python python-stdlib 3.11 pathlib/Path# |
| 10 | |
| 11 | import jupyter_core.pathsscip-python python jupyter_core 5.9.1 `jupyter_core.paths`/__init__: as jupyter_core_paths |
| 12 | |
| 13 | from .labconfigscip-python python jupytext 1.16.4 labconfig/__init__: import LabConfigscip-python python jupytext 1.16.4 `src.jupytext_config.labconfig`/LabConfig# |
| 14 | |
| 15 | |
| 16 | class SubCommandscip-python python jupytext 1.16.4 `src.jupytext_config.jupytext_config`/SubCommand#: |
| 17 | """ |
| 18 | a subcommand for jupytext-config |
| 19 | """ |
| 20 | |
| 21 | def __init__scip-python python jupytext 1.16.4 `src.jupytext_config.jupytext_config`/SubCommand#__init__().(selfscip-python python jupytext 1.16.4 `src.jupytext_config.jupytext_config`/SubCommand#__init__().(self), namescip-python python jupytext 1.16.4 `src.jupytext_config.jupytext_config`/SubCommand#__init__().(name), helpscip-python python jupytext 1.16.4 `src.jupytext_config.jupytext_config`/SubCommand#__init__().(help)): |
| 22 | selfscip-python python jupytext 1.16.4 `src.jupytext_config.jupytext_config`/SubCommand#__init__().(self).namescip-python python jupytext 1.16.4 `src.jupytext_config.jupytext_config`/SubCommand#name. = namescip-python python jupytext 1.16.4 `src.jupytext_config.jupytext_config`/SubCommand#__init__().(name) |
| 23 | selfscip-python python jupytext 1.16.4 `src.jupytext_config.jupytext_config`/SubCommand#__init__().(self).helpscip-python python jupytext 1.16.4 `src.jupytext_config.jupytext_config`/SubCommand#help. = helpscip-python python jupytext 1.16.4 `src.jupytext_config.jupytext_config`/SubCommand#__init__().(help) |
| 24 | |
| 25 | def mainscip-python python jupytext 1.16.4 `src.jupytext_config.jupytext_config`/SubCommand#main().(selfscip-python python jupytext 1.16.4 `src.jupytext_config.jupytext_config`/SubCommand#main().(self), argsscip-python python jupytext 1.16.4 `src.jupytext_config.jupytext_config`/SubCommand#main().(args)): |
| 26 | """ |
| 27 | return 0 if all goes well |
| 28 | """ |
| 29 | raise NotImplementedErrorscip-python python python-stdlib 3.11 builtins/NotImplementedError#() # pragma: no cover |
| 30 | |
| 31 | |
| 32 | class ListDefaultViewerscip-python python jupytext 1.16.4 `src.jupytext_config.jupytext_config`/ListDefaultViewer#(SubCommandscip-python python jupytext 1.16.4 `src.jupytext_config.jupytext_config`/SubCommand#): |
| 33 | def __init__scip-python python jupytext 1.16.4 `src.jupytext_config.jupytext_config`/ListDefaultViewer#__init__().(selfscip-python python jupytext 1.16.4 `src.jupytext_config.jupytext_config`/ListDefaultViewer#__init__().(self)): |
| 34 | superscip-python python python-stdlib 3.11 builtins/super#().__init__scip-python python jupytext 1.16.4 `src.jupytext_config.jupytext_config`/SubCommand#__init__().("list-default-viewer", "Display current settings in labconfig") |
| 35 | |
| 36 | def mainscip-python python jupytext 1.16.4 `src.jupytext_config.jupytext_config`/ListDefaultViewer#main().(selfscip-python python jupytext 1.16.4 `src.jupytext_config.jupytext_config`/ListDefaultViewer#main().(self), argsscip-python python jupytext 1.16.4 `src.jupytext_config.jupytext_config`/ListDefaultViewer#main().(args)): |
| 37 | LabConfigscip-python python jupytext 1.16.4 `src.jupytext_config.labconfig`/LabConfig#(settings_filescip-python python jupytext 1.16.4 `src.jupytext_config.labconfig`/LabConfig#__init__().(settings_file)=argsscip-python python jupytext 1.16.4 `src.jupytext_config.jupytext_config`/ListDefaultViewer#main().(args).settings_file).readscip-python python jupytext 1.16.4 `src.jupytext_config.labconfig`/LabConfig#read().().list_default_viewerscip-python python jupytext 1.16.4 `src.jupytext_config.labconfig`/LabConfig#list_default_viewer().() |
| 38 | return 0 |
| 39 | |
| 40 | def fill_parserscip-python python jupytext 1.16.4 `src.jupytext_config.jupytext_config`/ListDefaultViewer#fill_parser().(selfscip-python python jupytext 1.16.4 `src.jupytext_config.jupytext_config`/ListDefaultViewer#fill_parser().(self), subparserscip-python python jupytext 1.16.4 `src.jupytext_config.jupytext_config`/ListDefaultViewer#fill_parser().(subparser)): |
| 41 | pass |
| 42 | |
| 43 | |
| 44 | class SetDefaultViewerscip-python python jupytext 1.16.4 `src.jupytext_config.jupytext_config`/SetDefaultViewer#(SubCommandscip-python python jupytext 1.16.4 `src.jupytext_config.jupytext_config`/SubCommand#): |
| 45 | def __init__scip-python python jupytext 1.16.4 `src.jupytext_config.jupytext_config`/SetDefaultViewer#__init__().(selfscip-python python jupytext 1.16.4 `src.jupytext_config.jupytext_config`/SetDefaultViewer#__init__().(self)): |
| 46 | superscip-python python python-stdlib 3.11 builtins/super#().__init__scip-python python jupytext 1.16.4 `src.jupytext_config.jupytext_config`/SubCommand#__init__().("set-default-viewer", "Set default viewers for JupyterLab") |
| 47 | |
| 48 | def mainscip-python python jupytext 1.16.4 `src.jupytext_config.jupytext_config`/SetDefaultViewer#main().(selfscip-python python jupytext 1.16.4 `src.jupytext_config.jupytext_config`/SetDefaultViewer#main().(self), argsscip-python python jupytext 1.16.4 `src.jupytext_config.jupytext_config`/SetDefaultViewer#main().(args)): |
| 49 | LabConfigscip-python python jupytext 1.16.4 `src.jupytext_config.labconfig`/LabConfig#(settings_filescip-python python jupytext 1.16.4 `src.jupytext_config.labconfig`/LabConfig#__init__().(settings_file)=argsscip-python python jupytext 1.16.4 `src.jupytext_config.jupytext_config`/SetDefaultViewer#main().(args).settings_file).readscip-python python jupytext 1.16.4 `src.jupytext_config.labconfig`/LabConfig#read().().set_default_viewersscip-python python jupytext 1.16.4 `src.jupytext_config.labconfig`/LabConfig#set_default_viewers().( |
| 50 | argsscip-python python jupytext 1.16.4 `src.jupytext_config.jupytext_config`/SetDefaultViewer#main().(args).doctype |
| 51 | ).writescip-python python jupytext 1.16.4 `src.jupytext_config.labconfig`/LabConfig#write().() |
| 52 | return 0 |
| 53 | |
| 54 | def fill_parserscip-python python jupytext 1.16.4 `src.jupytext_config.jupytext_config`/SetDefaultViewer#fill_parser().(selfscip-python python jupytext 1.16.4 `src.jupytext_config.jupytext_config`/SetDefaultViewer#fill_parser().(self), subparserscip-python python jupytext 1.16.4 `src.jupytext_config.jupytext_config`/SetDefaultViewer#fill_parser().(subparser)): |
| 55 | subparserscip-python python jupytext 1.16.4 `src.jupytext_config.jupytext_config`/SetDefaultViewer#fill_parser().(subparser).add_argument( |
| 56 | "doctype", |
| 57 | nargs="*", |
| 58 | help=f"the document types to be associated with the notebook editor; " |
| 59 | f"defaults to {' '.joinscip-python python python-stdlib 3.11 builtins/str#join().(LabConfigscip-python python jupytext 1.16.4 `src.jupytext_config.labconfig`/LabConfig#.DOCTYPESscip-python python jupytext 1.16.4 `src.jupytext_config.labconfig`/LabConfig#DOCTYPES.)}", |
| 60 | ) |
| 61 | |
| 62 | |
| 63 | class UnsetDefaultViewerscip-python python jupytext 1.16.4 `src.jupytext_config.jupytext_config`/UnsetDefaultViewer#(SubCommandscip-python python jupytext 1.16.4 `src.jupytext_config.jupytext_config`/SubCommand#): |
| 64 | def __init__scip-python python jupytext 1.16.4 `src.jupytext_config.jupytext_config`/UnsetDefaultViewer#__init__().(selfscip-python python jupytext 1.16.4 `src.jupytext_config.jupytext_config`/UnsetDefaultViewer#__init__().(self)): |
| 65 | superscip-python python python-stdlib 3.11 builtins/super#().__init__scip-python python jupytext 1.16.4 `src.jupytext_config.jupytext_config`/SubCommand#__init__().("unset-default-viewer", "Unset default viewers for JupyterLab") |
| 66 | |
| 67 | def mainscip-python python jupytext 1.16.4 `src.jupytext_config.jupytext_config`/UnsetDefaultViewer#main().(selfscip-python python jupytext 1.16.4 `src.jupytext_config.jupytext_config`/UnsetDefaultViewer#main().(self), argsscip-python python jupytext 1.16.4 `src.jupytext_config.jupytext_config`/UnsetDefaultViewer#main().(args)): |
| 68 | LabConfigscip-python python jupytext 1.16.4 `src.jupytext_config.labconfig`/LabConfig#(settings_filescip-python python jupytext 1.16.4 `src.jupytext_config.labconfig`/LabConfig#__init__().(settings_file)=argsscip-python python jupytext 1.16.4 `src.jupytext_config.jupytext_config`/UnsetDefaultViewer#main().(args).settings_file).readscip-python python jupytext 1.16.4 `src.jupytext_config.labconfig`/LabConfig#read().().unset_default_viewersscip-python python jupytext 1.16.4 `src.jupytext_config.labconfig`/LabConfig#unset_default_viewers().( |
| 69 | argsscip-python python jupytext 1.16.4 `src.jupytext_config.jupytext_config`/UnsetDefaultViewer#main().(args).doctype |
| 70 | ).writescip-python python jupytext 1.16.4 `src.jupytext_config.labconfig`/LabConfig#write().() |
| 71 | return 0 |
| 72 | |
| 73 | def fill_parserscip-python python jupytext 1.16.4 `src.jupytext_config.jupytext_config`/UnsetDefaultViewer#fill_parser().(selfscip-python python jupytext 1.16.4 `src.jupytext_config.jupytext_config`/UnsetDefaultViewer#fill_parser().(self), subparserscip-python python jupytext 1.16.4 `src.jupytext_config.jupytext_config`/UnsetDefaultViewer#fill_parser().(subparser)): |
| 74 | subparserscip-python python jupytext 1.16.4 `src.jupytext_config.jupytext_config`/UnsetDefaultViewer#fill_parser().(subparser).add_argument( |
| 75 | "doctype", |
| 76 | nargs="*", |
| 77 | help=f"the document types for which the default viewer will be unset; " |
| 78 | f"defaults to {' '.joinscip-python python python-stdlib 3.11 builtins/str#join().(LabConfigscip-python python jupytext 1.16.4 `src.jupytext_config.labconfig`/LabConfig#.DOCTYPESscip-python python jupytext 1.16.4 `src.jupytext_config.labconfig`/LabConfig#DOCTYPES.)}", |
| 79 | ) |
| 80 | |
| 81 | |
| 82 | # create the subcommands |
| 83 | SUBCOMMANDSscip-python python jupytext 1.16.4 `src.jupytext_config.jupytext_config`/SUBCOMMANDS. = [ |
| 84 | ListDefaultViewerscip-python python jupytext 1.16.4 `src.jupytext_config.jupytext_config`/ListDefaultViewer#(), |
| 85 | SetDefaultViewerscip-python python jupytext 1.16.4 `src.jupytext_config.jupytext_config`/SetDefaultViewer#(), |
| 86 | UnsetDefaultViewerscip-python python jupytext 1.16.4 `src.jupytext_config.jupytext_config`/UnsetDefaultViewer#(), |
| 87 | ] |
| 88 | |
| 89 | |
| 90 | def mainscip-python python jupytext 1.16.4 `src.jupytext_config.jupytext_config`/main().(): |
| 91 | parser = ArgumentParserscip-python python python-stdlib 3.11 argparse/ArgumentParser#() |
| 92 | parser.add_argumentscip-python python python-stdlib 3.11 argparse/_ActionsContainer#add_argument().( |
| 93 | "--settings-file", |
| 94 | defaultscip-python python python-stdlib 3.11 argparse/_ActionsContainer#add_argument().(default)=Pathscip-python python python-stdlib 3.11 pathlib/Path#(jupyter_core_paths.jupyter_config_dir()) |
| 95 | / "labconfig" |
| 96 | / "default_setting_overrides.json", |
| 97 | ) |
| 98 | subparsers = parser.add_subparsersscip-python python python-stdlib 3.11 argparse/ArgumentParser#add_subparsers().(requiredscip-python python python-stdlib 3.11 argparse/ArgumentParser#add_subparsers().(required)=True) |
| 99 | for subcommand in SUBCOMMANDSscip-python python jupytext 1.16.4 `src.jupytext_config.jupytext_config`/SUBCOMMANDS.: |
| 100 | subparser = subparsers.add_parserscip-python python python-stdlib 3.11 argparse/_SubParsersAction#add_parser().(subcommand.name, help=subcommand.help) |
| 101 | subparser.set_defaultsscip-python python python-stdlib 3.11 argparse/_ActionsContainer#set_defaults().(subcommand=subcommand) |
| 102 | subcommand.fill_parser(subparser) |
| 103 | args = parser.parse_argsscip-python python python-stdlib 3.11 argparse/ArgumentParser#parse_args().(sysscip-python python python-stdlib 3.11 sys/__init__:.argvscip-python python python-stdlib 3.11 sys/argv.argv.[1:] or ["--help"]) |
| 104 | return args.subcommand.main(args) |