From af7253dbe0cf94b02504b6b9e49f69ce70f9461b Mon Sep 17 00:00:00 2001 From: Tim Jenness Date: Fri, 7 Jul 2023 17:02:19 -0700 Subject: [PATCH] Run black on sphinx code examples --- .../concreteStorageClasses.rst | 16 ++++---- doc/lsst.daf.butler/writing-subcommands.rst | 40 +++++++++++++------ 2 files changed, 36 insertions(+), 20 deletions(-) diff --git a/doc/lsst.daf.butler/concreteStorageClasses.rst b/doc/lsst.daf.butler/concreteStorageClasses.rst index de3014ddff..d7d8745831 100644 --- a/doc/lsst.daf.butler/concreteStorageClasses.rst +++ b/doc/lsst.daf.butler/concreteStorageClasses.rst @@ -26,12 +26,15 @@ Retrieving this dataset via: .. code-block:: python butler.get( - "deepCoadd_obj", ..., + "deepCoadd_obj", + ..., parameters={ - "columns": {"dataset": "meas", - "filter": ["HSC-R", "HSC-I"], - "column": ["base_SdssShape_xx", "base_SdssShape_yy"]} - } + "columns": { + "dataset": "meas", + "filter": ["HSC-R", "HSC-I"], + "column": ["base_SdssShape_xx", "base_SdssShape_yy"], + } + }, ) is equivalent to (but potentially much more efficient than): @@ -39,5 +42,4 @@ is equivalent to (but potentially much more efficient than): .. code-block:: python full = butler.get("deepCoadd_obj", ...) - full.loc[:, ["meas", ["HSC-R", "HSC-I"], - ["base_SdssShape_xx", "base_SdssShape_yy"]]] + full.loc[:, ["meas", ["HSC-R", "HSC-I"], ["base_SdssShape_xx", "base_SdssShape_yy"]]] diff --git a/doc/lsst.daf.butler/writing-subcommands.rst b/doc/lsst.daf.butler/writing-subcommands.rst index 151d2815fc..803547db1b 100644 --- a/doc/lsst.daf.butler/writing-subcommands.rst +++ b/doc/lsst.daf.butler/writing-subcommands.rst @@ -44,11 +44,13 @@ Example of a command or subcommand definition: import click + @click.group() def git(): """An example git-style interface.""" pass + # Notice this uses "@git" instead of "@click", this adds the command to the # git group. @git.command() @@ -56,6 +58,7 @@ Example of a command or subcommand definition: """An example 'pull' subcommand.""" print("pull!") + if __name__ == "__main__": git() @@ -133,11 +136,13 @@ An example of a subcommand that uses options: import click + @click.group() def git(): """An example git-style interface.""" pass + @git.command() @click.option("-m", "--message", help="commit message") @click.option("-a", "--all", help="commit all changed files", is_flag=True) @@ -145,6 +150,7 @@ An example of a subcommand that uses options: """An example 'commit' subcommand.""" print(f"commit. all: {all}, message: {message}") + if __name__ == "__main__": git() @@ -183,11 +189,13 @@ An example of a subcommand that uses arguments: import click + @click.group() def git(): """An example git-style interface.""" pass + @git.command() @click.argument("branch") def checkout(branch): @@ -199,6 +207,7 @@ An example of a subcommand that uses arguments: """ print(f"checkout branch {branch}") + if __name__ == "__main__": git() @@ -257,17 +266,21 @@ An example implementation of ``git checkout`` that uses MWArgumentDecorator and # as the argument name in the command function where it is used. (This is # available for any click.option) new_branch_option = MWOptionDecorator( - "-b", "make_new_branch", + "-b", + "make_new_branch", help="create and checkout a new branch", - is_flag=True) # is_flag makes the option take no values, uses a bool - # which is true if the option is passed and false by - # default. + # is_flag makes the option take no values, uses a bool + # which is true if the option is passed and false by default. + is_flag=True, + ) + @click.group() def git(): """An example git-style interface.""" pass + @git.command() @branch_argument() @new_branch_option() @@ -275,6 +288,7 @@ An example implementation of ``git checkout`` that uses MWArgumentDecorator and """An example 'checkout' subcommand.""" print(f"checkout branch {branch}, make new:{make_new_branch}") + if __name__ == "__main__": git() @@ -311,13 +325,13 @@ Defines an Option Group decorator: :name: option-group-example class pipeline_build_options(OptionGroup): # noqa: N801 - """Decorator to add options to a command function for building a pipeline. - """ + """Decorator to add options to a command function for building a pipeline.""" - def __init__(self): - self.decorators = [ - ctrlMpExecOpts.pipeline_option(), - ctrlMpExecOpts.task_option()] + def __init__(self): + self.decorators = [ + ctrlMpExecOpts.pipeline_option(), + ctrlMpExecOpts.task_option(), + ] Uses an Option Group decorator: @@ -440,9 +454,9 @@ It's easy to create a new kind of command by copying the template below and maki from lsst.daf.butler.cli.butler import LoaderCLI + # Change the class name to better describe your command. class ButlerCLI(LoaderCLI): - # Replace this value with the import path to your `cmd` module. localCmdPkg = "lsst.daf.butler.cli.cmd" @@ -450,9 +464,9 @@ It's easy to create a new kind of command by copying the template below and maki # above. pluginEnvVar = "DAF_BUTLER_PLUGINS" + # Change ``cls=ButlerCLI`` to be the same as your new class name above. - @click.command(cls=ButlerCLI, - context_settings=dict(help_option_names=["-h", "--help"])) + @click.command(cls=ButlerCLI, context_settings=dict(help_option_names=["-h", "--help"])) # You can remove log_level_option if you do not support it. You can add # other command options here. (Subcommand options are declared elsewhere). @log_level_option()