Skip to content

Commit

Permalink
Run black on sphinx code examples
Browse files Browse the repository at this point in the history
  • Loading branch information
timj committed Jul 8, 2023
1 parent 75f3408 commit 7d37445
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 20 deletions.
16 changes: 9 additions & 7 deletions doc/lsst.daf.butler/concreteStorageClasses.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,20 @@ 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):

.. 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"]]]
40 changes: 27 additions & 13 deletions doc/lsst.daf.butler/writing-subcommands.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,21 @@ 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()
def pull():
"""An example 'pull' subcommand."""
print("pull!")
if __name__ == "__main__":
git()
Expand Down Expand Up @@ -133,18 +136,21 @@ 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)
def commit(all, message):
"""An example 'commit' subcommand."""
print(f"commit. all: {all}, message: {message}")
if __name__ == "__main__":
git()
Expand Down Expand Up @@ -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):
Expand All @@ -199,6 +207,7 @@ An example of a subcommand that uses arguments:
"""
print(f"checkout branch {branch}")
if __name__ == "__main__":
git()
Expand Down Expand Up @@ -257,24 +266,29 @@ 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()
def checkout(branch, make_new_branch):
"""An example 'checkout' subcommand."""
print(f"checkout branch {branch}, make new:{make_new_branch}")
if __name__ == "__main__":
git()
Expand Down Expand Up @@ -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:

Expand Down Expand Up @@ -440,19 +454,19 @@ 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"
# Replace this value with the manifest environment variable described
# 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()
Expand Down

0 comments on commit 7d37445

Please sign in to comment.