From 3d5562e827543f73c61f48292e205358cbd21f00 Mon Sep 17 00:00:00 2001 From: mcflugen Date: Tue, 21 Jan 2025 13:22:03 -0700 Subject: [PATCH 01/10] use new form for Generator type hint --- sequence/logging.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sequence/logging.py b/sequence/logging.py index 5991a8c..ba5ca92 100644 --- a/sequence/logging.py +++ b/sequence/logging.py @@ -47,7 +47,7 @@ def emit(self, record: logging.LogRecord) -> None: @contextlib.contextmanager -def logging_handler() -> Generator[None, None, None]: +def logging_handler() -> Generator[None]: """Change, temporarily, the current logger.""" handler = LoggingHandler() logger.addHandler(handler) From 2838b509de6c7169da149e56dce6f4e103bb07a7 Mon Sep 17 00:00:00 2001 From: mcflugen Date: Tue, 21 Jan 2025 13:22:29 -0700 Subject: [PATCH 02/10] use isostasy_time property --- sequence/sediment_flexure.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/sequence/sediment_flexure.py b/sequence/sediment_flexure.py index aee8d16..28ae7f9 100644 --- a/sequence/sediment_flexure.py +++ b/sequence/sediment_flexure.py @@ -162,9 +162,9 @@ def __init__( "Flexure parameters\n" + toml.dumps( { - "isostasy_time": 0.0 - if self._isostasy_time is None - else self._isostasy_time, + "isostasy_time": ( + 0.0 if self._isostasy_time is None else self._isostasy_time + ), "alpha": self.alpha, "rigidity": self.rigidity, "gamma_mantle": self.gamma_mantle, @@ -350,9 +350,9 @@ def __init__( "sand_density": self._sand_density, "mud_density": self._mud_density, "water_density": self._water_density, - "isostasy_time": 0.0 - if self.isostasy_time is None - else self.isostasy_time, + "isostasy_time": ( + 0.0 if self.isostasy_time is None else self.isostasy_time + ), "alpha": self.alpha, "rigidity": self.rigidity, "gamma_mantle": self.gamma_mantle, From d6ffffe64a66dfedc3134ba2272f28e81398438f Mon Sep 17 00:00:00 2001 From: mcflugen Date: Tue, 21 Jan 2025 13:22:46 -0700 Subject: [PATCH 03/10] bump version of pre-commit hooks --- .pre-commit-config.yaml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5b615c1..46753de 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/psf/black - rev: 23.12.0 + rev: 24.10.0 hooks: - id: black name: black @@ -23,7 +23,7 @@ repos: additional_dependencies: [".[jupyter]"] - repo: https://github.com/nbQA-dev/nbQA - rev: 1.7.1 + rev: 1.9.1 hooks: - id: nbqa-pyupgrade args: ["--py310-plus"] @@ -32,14 +32,14 @@ repos: args: ["--extend-ignore=E402"] - repo: https://github.com/kynan/nbstripout - rev: 0.6.1 + rev: 0.8.1 hooks: - id: nbstripout description: Strip output from jupyter notebooks args: [--drop-empty-cells] - repo: https://github.com/pycqa/flake8 - rev: 6.1.0 + rev: 7.1.1 hooks: - id: flake8 additional_dependencies: @@ -48,19 +48,19 @@ repos: - flake8-simplify - repo: https://github.com/asottile/pyupgrade - rev: v3.15.0 + rev: v3.19.1 hooks: - id: pyupgrade args: [--py38-plus] - repo: https://github.com/asottile/reorder-python-imports - rev: v3.12.0 + rev: v3.14.0 hooks: - id: reorder-python-imports args: [--py310-plus, --add-import, "from __future__ import annotations"] - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.5.0 + rev: v5.0.0 hooks: - id: check-builtin-literals - id: check-added-large-files @@ -81,14 +81,14 @@ repos: - id: name-tests-test - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.1.8 + rev: v0.9.2 hooks: - id: ruff files: sequence/.*\.py$ args: [--fix] - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.7.1 + rev: v1.14.1 hooks: - id: mypy language_version: python3.12 From 4276884e602bb781848e7add6665f3dcf022fcc0 Mon Sep 17 00:00:00 2001 From: mcflugen Date: Tue, 21 Jan 2025 13:36:47 -0700 Subject: [PATCH 04/10] use isort instead of reorder-python-imports --- .pre-commit-config.yaml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 46753de..b2032fd 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -53,11 +53,13 @@ repos: - id: pyupgrade args: [--py38-plus] -- repo: https://github.com/asottile/reorder-python-imports - rev: v3.14.0 +- repo: https://github.com/PyCQA/isort + rev: 5.13.2 hooks: - - id: reorder-python-imports - args: [--py310-plus, --add-import, "from __future__ import annotations"] + - id: isort + name: isort (python) + args: [--add-import, "from __future__ import annotations"] + types: [python] - repo: https://github.com/pre-commit/pre-commit-hooks rev: v5.0.0 From 8d5f12d21873cbf85fff2363b69e8ce239fb5756 Mon Sep 17 00:00:00 2001 From: mcflugen Date: Tue, 21 Jan 2025 13:37:29 -0700 Subject: [PATCH 05/10] update isort configuration --- pyproject.toml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index b719199..4cad335 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -82,11 +82,9 @@ sequence = [ ] [tool.isort] -multi_line_output = 3 -include_trailing_comma = true -force_grid_wrap = 0 -combine_as_imports = true -line_length = 88 +known_first_party = "sequence" +profile = "black" +force_single_line = true [tool.mypy] check_untyped_defs = true From 2d723c7a3421eadeee64ec2193b6f7015e0e410a Mon Sep 17 00:00:00 2001 From: mcflugen Date: Tue, 21 Jan 2025 13:37:51 -0700 Subject: [PATCH 06/10] add blank line above imports for new version of black --- sequence/__init__.py | 1 + sequence/bathymetry.py | 1 + sequence/cli.py | 1 + sequence/errors.py | 1 + sequence/fluvial.py | 1 + sequence/grid.py | 1 + sequence/input_reader.py | 1 + sequence/logging.py | 1 + sequence/netcdf.py | 1 + sequence/output_writer.py | 1 + sequence/plot.py | 1 + sequence/processes.py | 1 + sequence/sea_level.py | 1 + sequence/sediment_flexure.py | 1 + sequence/sequence.py | 1 + sequence/sequence_model.py | 3 ++- sequence/shoreline.py | 1 + sequence/submarine.py | 1 + sequence/subsidence.py | 1 + tests/shoreline_test.py | 1 + 20 files changed, 21 insertions(+), 1 deletion(-) diff --git a/sequence/__init__.py b/sequence/__init__.py index 351b252..4123e30 100644 --- a/sequence/__init__.py +++ b/sequence/__init__.py @@ -1,4 +1,5 @@ """A sequence-stratigraphic model of a 1D profile written with *Landlab*.""" + from __future__ import annotations from sequence._version import __version__ diff --git a/sequence/bathymetry.py b/sequence/bathymetry.py index 3f84cdb..1a55bc9 100644 --- a/sequence/bathymetry.py +++ b/sequence/bathymetry.py @@ -3,6 +3,7 @@ This module contains *Landlab* components to read bathymetry into a `SequenceModelGrid`. """ + from __future__ import annotations from os import PathLike diff --git a/sequence/cli.py b/sequence/cli.py index 6ab3aa5..5516594 100644 --- a/sequence/cli.py +++ b/sequence/cli.py @@ -1,4 +1,5 @@ """The command line interface for *Sequence*.""" + from __future__ import annotations import inspect diff --git a/sequence/errors.py b/sequence/errors.py index 349d205..cdbd70b 100644 --- a/sequence/errors.py +++ b/sequence/errors.py @@ -1,4 +1,5 @@ """Errors used by *sequence*.""" + from __future__ import annotations from collections.abc import Iterable diff --git a/sequence/fluvial.py b/sequence/fluvial.py index 8430ff3..4630604 100644 --- a/sequence/fluvial.py +++ b/sequence/fluvial.py @@ -3,6 +3,7 @@ This module contains *Landlab* components that add a sand fraction to a `SequenceModelGrid`. """ + from __future__ import annotations import numpy as np diff --git a/sequence/grid.py b/sequence/grid.py index b9f7e8d..8f6d47a 100644 --- a/sequence/grid.py +++ b/sequence/grid.py @@ -1,4 +1,5 @@ """Define the grid used for creating *Sequence* models.""" + from __future__ import annotations import os diff --git a/sequence/input_reader.py b/sequence/input_reader.py index 7109d30..11d7218 100644 --- a/sequence/input_reader.py +++ b/sequence/input_reader.py @@ -2,6 +2,7 @@ This module contains utilities for reading *Sequence* input data. """ + from __future__ import annotations import inspect diff --git a/sequence/logging.py b/sequence/logging.py index ba5ca92..c2d704d 100644 --- a/sequence/logging.py +++ b/sequence/logging.py @@ -1,4 +1,5 @@ """Logger used for printing Sequence log messages.""" + from __future__ import annotations import contextlib diff --git a/sequence/netcdf.py b/sequence/netcdf.py index dcf61a9..2c24431 100644 --- a/sequence/netcdf.py +++ b/sequence/netcdf.py @@ -1,4 +1,5 @@ """Write a `SequenceModelGrid` to a NetCDF file.""" + from __future__ import annotations import contextlib diff --git a/sequence/output_writer.py b/sequence/output_writer.py index 14bf3d2..c2f3d6e 100644 --- a/sequence/output_writer.py +++ b/sequence/output_writer.py @@ -1,4 +1,5 @@ """Write a `SequenceModelGrid` to a file.""" + from __future__ import annotations import errno diff --git a/sequence/plot.py b/sequence/plot.py index 265f22f..ad7125c 100644 --- a/sequence/plot.py +++ b/sequence/plot.py @@ -1,4 +1,5 @@ """Plot the layers of a `SequenceModelGrid`.""" + from __future__ import annotations from functools import partial diff --git a/sequence/processes.py b/sequence/processes.py index ac9700b..78a75f0 100644 --- a/sequence/processes.py +++ b/sequence/processes.py @@ -1,4 +1,5 @@ """All available processes to include in a *Sequence* model.""" + from __future__ import annotations from compaction.landlab import Compact diff --git a/sequence/sea_level.py b/sequence/sea_level.py index 27a4d9b..5ef9758 100644 --- a/sequence/sea_level.py +++ b/sequence/sea_level.py @@ -3,6 +3,7 @@ This module contains *Landlab* components used for adjusting a grid's sea level. """ + from __future__ import annotations from collections.abc import Callable diff --git a/sequence/sediment_flexure.py b/sequence/sediment_flexure.py index 28ae7f9..ad36939 100644 --- a/sequence/sediment_flexure.py +++ b/sequence/sediment_flexure.py @@ -1,4 +1,5 @@ """Subside a `SequenceModelGrid` using flexure.""" + from __future__ import annotations import logging diff --git a/sequence/sequence.py b/sequence/sequence.py index 87edccf..b96b98b 100644 --- a/sequence/sequence.py +++ b/sequence/sequence.py @@ -1,4 +1,5 @@ """*Sequence*'s main API for constructing sequence-stratigraphic models.""" + from __future__ import annotations from collections.abc import Iterable diff --git a/sequence/sequence_model.py b/sequence/sequence_model.py index d3542e0..504d5a1 100644 --- a/sequence/sequence_model.py +++ b/sequence/sequence_model.py @@ -1,11 +1,12 @@ """Build a `SequenceModelGrid` model from collection of components.""" + from __future__ import annotations import logging import os import time -from collections import defaultdict from collections import OrderedDict +from collections import defaultdict from collections.abc import Iterable from contextlib import suppress from typing import Any diff --git a/sequence/shoreline.py b/sequence/shoreline.py index d562a9e..b2b796a 100644 --- a/sequence/shoreline.py +++ b/sequence/shoreline.py @@ -3,6 +3,7 @@ This module contains methods for calculating a grid's shoreline and shelf edge. """ + from __future__ import annotations import bisect diff --git a/sequence/submarine.py b/sequence/submarine.py index c66a58f..9ca9637 100644 --- a/sequence/submarine.py +++ b/sequence/submarine.py @@ -1,4 +1,5 @@ """Diffuse sediment along a profile.""" + from __future__ import annotations from typing import Any diff --git a/sequence/subsidence.py b/sequence/subsidence.py index d72f0d9..4877bfa 100644 --- a/sequence/subsidence.py +++ b/sequence/subsidence.py @@ -1,4 +1,5 @@ """Subside a `SequenceModelGrid`.""" + from __future__ import annotations import os diff --git a/tests/shoreline_test.py b/tests/shoreline_test.py index 8788471..091457e 100644 --- a/tests/shoreline_test.py +++ b/tests/shoreline_test.py @@ -1,4 +1,5 @@ """Test the shoreline.find_shoreline function.""" + from __future__ import annotations import numpy as np From 330461db2459ed043d5fd752d7389d65811a8f2c Mon Sep 17 00:00:00 2001 From: mcflugen Date: Tue, 21 Jan 2025 13:46:32 -0700 Subject: [PATCH 07/10] remove the lint workflow, use pre-commit.ci instead --- .github/workflows/lint.yml | 27 --------------------------- 1 file changed, 27 deletions(-) delete mode 100644 .github/workflows/lint.yml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml deleted file mode 100644 index 92ddc7c..0000000 --- a/.github/workflows/lint.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: Lint - -on: [push, pull_request] - -jobs: - - lint: - name: Check for lint - # We want to run on external PRs, but not on our own internal PRs as they'll be run - # by the push to the branch. Without this if check, checks are duplicated since - # internal PRs match both the push and pull_request events. - if: - github.event_name == 'push' || github.event.pull_request.head.repo.full_name != - github.repository - - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Set up Python 3.12 - uses: actions/setup-python@v5 - with: - python-version: 3.12 - - - name: Lint - run: | - pip install nox - nox -s lint From ffeedd833cc1874e4e6f655875731d76f9952f44 Mon Sep 17 00:00:00 2001 From: mcflugen Date: Tue, 21 Jan 2025 13:52:54 -0700 Subject: [PATCH 08/10] set python 3.10+ for pyupgrade --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b2032fd..df7d607 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -51,7 +51,7 @@ repos: rev: v3.19.1 hooks: - id: pyupgrade - args: [--py38-plus] + args: [--py310-plus] - repo: https://github.com/PyCQA/isort rev: 5.13.2 From fde9bd130eff2a8762f175258c2a74ab0e3a7bca Mon Sep 17 00:00:00 2001 From: mcflugen Date: Tue, 21 Jan 2025 13:57:12 -0700 Subject: [PATCH 09/10] add news fragment --- news/87.misc | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 news/87.misc diff --git a/news/87.misc b/news/87.misc new file mode 100644 index 0000000..7120b4a --- /dev/null +++ b/news/87.misc @@ -0,0 +1,2 @@ + +Updated the *pre-commit* hooks and fixed some newly-found lint. From 3eecb4481439034b0b46b8b635522b8fe884fa2f Mon Sep 17 00:00:00 2001 From: mcflugen Date: Tue, 21 Jan 2025 13:57:33 -0700 Subject: [PATCH 10/10] remove notebook output --- docs/tutorials/notebooks/example.ipynb | 36 +++++++++++++------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/docs/tutorials/notebooks/example.ipynb b/docs/tutorials/notebooks/example.ipynb index 2cdd2ce..c66d7c9 100644 --- a/docs/tutorials/notebooks/example.ipynb +++ b/docs/tutorials/notebooks/example.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "2815939c", + "id": "0", "metadata": {}, "source": [ "![Sequence Logo](https://raw.githubusercontent.com/sequence-dev/sequence/develop/docs/_static/sequence-logo-text-lowercase.png)\n", @@ -14,7 +14,7 @@ }, { "cell_type": "markdown", - "id": "722b40f1", + "id": "1", "metadata": {}, "source": [ "# Create the *sequence* model grid\n", @@ -25,7 +25,7 @@ { "cell_type": "code", "execution_count": null, - "id": "c90feada", + "id": "2", "metadata": {}, "outputs": [], "source": [ @@ -38,7 +38,7 @@ }, { "cell_type": "markdown", - "id": "1f44bed6", + "id": "3", "metadata": {}, "source": [ "The following code create a new grid with 100 vertical stacks that are each 1000 m in width. We then set the initial topoography (and bathymetry) for the model as well as setting sea level." @@ -47,7 +47,7 @@ { "cell_type": "code", "execution_count": null, - "id": "43bc9d89", + "id": "4", "metadata": {}, "outputs": [], "source": [ @@ -58,7 +58,7 @@ }, { "cell_type": "markdown", - "id": "753b28ce", + "id": "5", "metadata": {}, "source": [ "# Create the process components\n", @@ -73,7 +73,7 @@ { "cell_type": "code", "execution_count": null, - "id": "96d9cc6f", + "id": "6", "metadata": {}, "outputs": [], "source": [ @@ -110,7 +110,7 @@ }, { "cell_type": "markdown", - "id": "9f2dce0a", + "id": "7", "metadata": {}, "source": [ "# Create a new *Sequence* model\n", @@ -121,7 +121,7 @@ { "cell_type": "code", "execution_count": null, - "id": "1ba92be6", + "id": "8", "metadata": {}, "outputs": [], "source": [ @@ -141,7 +141,7 @@ }, { "cell_type": "markdown", - "id": "282f70e1", + "id": "9", "metadata": {}, "source": [ "Run the model for 3000 time steps." @@ -150,7 +150,7 @@ { "cell_type": "code", "execution_count": null, - "id": "55057e5e", + "id": "10", "metadata": {}, "outputs": [], "source": [ @@ -161,7 +161,7 @@ }, { "cell_type": "markdown", - "id": "82ce0bad", + "id": "11", "metadata": {}, "source": [ "# Dynamically change parameters\n", @@ -174,7 +174,7 @@ { "cell_type": "code", "execution_count": null, - "id": "97b28fe7", + "id": "12", "metadata": {}, "outputs": [], "source": [ @@ -184,7 +184,7 @@ { "cell_type": "code", "execution_count": null, - "id": "64d17bdf", + "id": "13", "metadata": {}, "outputs": [], "source": [ @@ -195,7 +195,7 @@ }, { "cell_type": "markdown", - "id": "bd7345df", + "id": "14", "metadata": {}, "source": [ "## Create a vertical fault\n", @@ -206,7 +206,7 @@ { "cell_type": "code", "execution_count": null, - "id": "740e6641", + "id": "15", "metadata": {}, "outputs": [], "source": [ @@ -217,7 +217,7 @@ { "cell_type": "code", "execution_count": null, - "id": "b21a4edd", + "id": "16", "metadata": {}, "outputs": [], "source": [ @@ -227,7 +227,7 @@ { "cell_type": "code", "execution_count": null, - "id": "796b0042", + "id": "17", "metadata": {}, "outputs": [], "source": [