diff --git a/.github/workflows/pre-commit.yaml b/.github/workflows/pre-commit.yaml new file mode 100644 index 00000000..30bfdd54 --- /dev/null +++ b/.github/workflows/pre-commit.yaml @@ -0,0 +1,26 @@ +name: Run pre-commit + +on: + push: + branches: + - main + pull_request: + +permissions: + contents: read + +jobs: + pre-commit: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v7 + + - name: Set up Python + uses: actions/setup-python@v6 + with: + python-version: "3.13" + + - name: Run prek + uses: j178/prek-action@v2 + with: + extra_args: --all-files diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 73546dc1..b516f8b1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,6 +5,8 @@ repos: - id: check-yaml args: - "--unsafe" + # These files are deliberately invalid YAML for testing error handling. + exclude: "^tests/config/dbAuth/badDbAuth.*\\.yaml$" - id: end-of-file-fixer - id: trailing-whitespace - id: check-toml diff --git a/doc/lsst.utils/CHANGES.rst b/doc/lsst.utils/CHANGES.rst index 9430614d..dc10294c 100644 --- a/doc/lsst.utils/CHANGES.rst +++ b/doc/lsst.utils/CHANGES.rst @@ -1,3 +1,12 @@ +lsst-utils v30.0.9 (2026-07-14) +=============================== + +New Features +------------ + +- Added ``DeprecatedDict`` mapping. + This can be used to configure a `dict` that issues deprecation warnings when certain keys are accessed. + lsst-utils v30.0.0 (2026-01-15) =============================== diff --git a/python/lsst/utils/argparsing.py b/python/lsst/utils/argparsing.py index 48b62d85..c6cb99fa 100644 --- a/python/lsst/utils/argparsing.py +++ b/python/lsst/utils/argparsing.py @@ -30,6 +30,36 @@ class AppendDict(argparse.Action): does not contain exactly one "=" character is invalid. If the default value is non-empty, the default key-value pairs may be overwritten by values from the command line. + + Parameters + ---------- + option_strings : `str` | `list` [ `str` ] + The command-line option strings that trigger this action, e.g. + ``--config``. + dest : `str` + The name of the `~argparse.Namespace` attribute in which the + accumulated `dict` is stored. + nargs : `int` | `str` | `None`, optional + The number of command-line arguments consumed each time the option + appears, as accepted by `argparse.ArgumentParser.add_argument`. + const : `typing.Any` | `None`, optional + A constant value required by some ``nargs`` settings; unused by this + action. + default : `typing.Any` | `None`, optional + The initial value of the mapping if the option does not appear on the + command line. Must be a `~collections.abc.Mapping` or `None`; `None` + is converted to an empty `dict`. + type : `type` | `None`, optional + A callable applied by argparse to each command-line argument before + it is passed to this action. + choices : `typing.Any` | `None`, optional + A container of the allowable values for the argument. + required : `bool`, optional + Whether the option must appear on the command line. + help : `str` | `None`, optional + A brief description of the argument for usage messages. + metavar : `str` | `None`, optional + The name for the argument's value(s) in usage messages. """ def __init__( diff --git a/python/lsst/utils/plotting/publication_plots.py b/python/lsst/utils/plotting/publication_plots.py index d3a10238..5cea91a3 100644 --- a/python/lsst/utils/plotting/publication_plots.py +++ b/python/lsst/utils/plotting/publication_plots.py @@ -34,9 +34,7 @@ def set_rubin_plotstyle() -> None: - """ - Set the matplotlib style for Rubin publications - """ + """Set the matplotlib style for Rubin publications.""" from matplotlib import style style.use("lsst.utils.plotting.rubin") @@ -98,8 +96,13 @@ def mk_colormap(colorNames): # type: ignore def divergent_cmap(): # type: ignore - """ - Make a divergent color map. + """Make a divergent color map. + + Returns + ------- + cmap : `matplotlib.colors.LinearSegmentedColormap` + A colormap stepping from the standard stars color through + gray to the accent color. """ cmap = mk_colormap([stars_color(), "#D9DCDE", accent_color()]) @@ -107,7 +110,19 @@ def divergent_cmap(): # type: ignore def stars_cmap(single_color=False): # type: ignore - """Make a color map for stars.""" + """Make a color map for stars. + + Parameters + ---------- + single_color : `bool`, optional + If `True` use the standard stars color. + + Returns + ------- + cmap : `matplotlib.colors.Colormap` + A colormap derived from the standard stars color if + ``single_color`` is `True`, otherwise the seaborn "mako" palette. + """ import seaborn as sns from matplotlib.colors import ListedColormap @@ -119,20 +134,35 @@ def stars_cmap(single_color=False): # type: ignore def stars_color() -> str: - """Return the star color string for lines""" + """Return the star color string for lines.""" return "#084d96" def accent_color() -> str: - """Return a contrasting color for overplotting, - black is the best for this but if you need two colors + """Return a contrasting color for overplotting. + + Notes + ----- + Black is the best for this but if you need two colors this works well on blue. """ return "#DE8F05" -def galaxies_cmap(single_color=False): # type: ignore - """Make a color map for galaxies.""" +def galaxies_cmap(single_color: bool = False): # type: ignore + """Make a color map for galaxies. + + Parameters + ---------- + single_color : `bool`, optional + If `True` use the standard galaxies color. + + Returns + ------- + cmap : `matplotlib.colors.LinearSegmentedColormap` or `str` + A colormap derived from the standard galaxies color if + ``single_color`` is `True`, otherwise the colormap name "inferno". + """ if single_color: cmap = mk_colormap([galaxies_color()]) else: @@ -141,17 +171,29 @@ def galaxies_cmap(single_color=False): # type: ignore def galaxies_color() -> str: - """Return the galaxy color string for lines""" + """Return the galaxy color string for lines.""" return "#961A45" def sso_color() -> str: - """Return the SSO color string for lines""" + """Return the SSO color string for lines.""" return "#01694c" -def sso_cmap(single_color=False): # type: ignore - """Make a color map for solar system objects.""" +def sso_cmap(single_color: bool = False): # type: ignore + """Make a color map for solar system objects. + + Parameters + ---------- + single_color : `bool`, optional + If `True` use the standard SSO color. + + Returns + ------- + cmap : `matplotlib.colors.LinearSegmentedColormap` or `str` + A colormap derived from the standard SSO color if + ``single_color`` is `True`, otherwise the colormap name "viridis". + """ if single_color: cmap = mk_colormap([sso_color()]) else: @@ -160,16 +202,19 @@ def sso_cmap(single_color=False): # type: ignore def get_band_dicts() -> dict: - """ - Define palettes, from RTN-045. This includes dicts for colors (bandpass - colors for white background), colors_black (bandpass colors for - black background), plot symbols, and line_styles, keyed on band (ugrizy). + """Define palettes, from RTN-045. Returns ------- band_dict : `dict` of `dict` Dicts of colors, colors_black, symbols, and line_styles, keyed on bands 'u', 'g', 'r', 'i', 'z', and 'y'. + + Notes + ----- + This includes dicts for colors (bandpass colors for white background), + colors_black (bandpass colors for black background), plot symbols, and + line_styles, keyed on band (ugrizy). """ colors = get_multiband_plot_colors() colors_black = get_multiband_plot_colors(dark_background=True) diff --git a/tests/decorator_test/disable_timer.py b/tests/decorator_test/disable_timer.py index 086b5cec..5b95f5c1 100644 --- a/tests/decorator_test/disable_timer.py +++ b/tests/decorator_test/disable_timer.py @@ -12,7 +12,13 @@ @timeMethod(logger=log, logLevel=logging.INFO) def sleep_and_log(self, duration: float) -> None: - """Check that this does not log if the decorator was disabled on import.""" + """Check that this does not log if the decorator was disabled on import. + + Parameters + ---------- + duration : `float` + Time to sleep. + """ time.sleep(duration) @@ -20,5 +26,10 @@ def sleep_and_log(self, duration: float) -> None: def sleep_and_nothing(self, duration: float) -> None: """Check that this does not have a `__wrapped__` attribute to confirm that the decorator is disabled. + + Parameters + ---------- + duration : `float` + Time to sleep. """ time.sleep(duration)