diff --git a/.cruft.json b/.cruft.json index 299957f..82d94ee 100644 --- a/.cruft.json +++ b/.cruft.json @@ -1,6 +1,6 @@ { "template": "https://github.com/sunpy/package-template", - "commit": "aec53b81aed2e7e534045e59303d82712fe82fb1", + "commit": "75f84c4adf1753af67967930c3335bc73bca9bf5", "checkout": null, "context": { "cookiecutter": { @@ -16,7 +16,8 @@ "enable_dynamic_dev_versions": "y", "include_example_code": "n", "include_cruft_update_github_workflow": "y", - "_sphinx_theme": "alabaster", + "use_extended_ruff_linting": "n", + "_sphinx_theme": "sunpy", "_parent_project": "", "_install_requires": "", "_copy_without_render": [ diff --git a/.github/workflows/label_sync.yml b/.github/workflows/label_sync.yml new file mode 100644 index 0000000..7f21775 --- /dev/null +++ b/.github/workflows/label_sync.yml @@ -0,0 +1,23 @@ +name: Label Sync +on: + workflow_dispatch: + schedule: + # ┌───────── minute (0 - 59) + # │ ┌───────── hour (0 - 23) + # │ │ ┌───────── day of the month (1 - 31) + # │ │ │ ┌───────── month (1 - 12 or JAN-DEC) + # │ │ │ │ ┌───────── day of the week (0 - 6 or SUN-SAT) + - cron: '0 0 * * *' # run every day at midnight UTC + +# Give permissions to write issue labels +permissions: + issues: write + +jobs: + label_sync: + runs-on: ubuntu-latest + name: Label Sync + steps: + - uses: srealmoreno/label-sync-action@850ba5cef2b25e56c6c420c4feed0319294682fd + with: + config-file: https://raw.githubusercontent.com/sunpy/.github/main/labels.yml diff --git a/.github/workflows/sub_package_update.yml b/.github/workflows/sub_package_update.yml index 7455847..0b657f2 100644 --- a/.github/workflows/sub_package_update.yml +++ b/.github/workflows/sub_package_update.yml @@ -21,14 +21,6 @@ jobs: runs-on: ubuntu-latest strategy: fail-fast: true - matrix: - include: - - add-paths: . - body: apply the changes to this repo. - branch: cruft/update - commit-message: "Automatic package template update" - title: Updates from the package template - steps: - uses: actions/checkout@v4 @@ -55,25 +47,47 @@ jobs: echo "has_changes=$CHANGES" >> "$GITHUB_OUTPUT" - name: Run update if available + id: cruft_update if: steps.check.outputs.has_changes == '1' run: | git config --global user.email "${{ github.actor }}@users.noreply.github.com" git config --global user.name "${{ github.actor }}" - cruft update --skip-apply-ask --refresh-private-variables + cruft_output=$(cruft update --skip-apply-ask --refresh-private-variables) + echo $cruft_output git restore --staged . - - name: Create pull request + if [[ "$cruft_output" == *"Failed to cleanly apply the update, there may be merge conflicts."* ]]; then + echo merge_conflicts=1 >> $GITHUB_OUTPUT + else + echo merge_conflicts=0 >> $GITHUB_OUTPUT + fi + + - name: Check if only .cruft.json is modified + id: cruft_json if: steps.check.outputs.has_changes == '1' + run: | + git status --porcelain=1 + if [[ "$(git status --porcelain=1)" == " M .cruft.json" ]]; then + echo "Only .cruft.json is modified. Exiting workflow early." + echo "has_changes=0" >> "$GITHUB_OUTPUT" + else + echo "has_changes=1" >> "$GITHUB_OUTPUT" + fi + + - name: Create pull request + if: steps.cruft_json.outputs.has_changes == '1' uses: peter-evans/create-pull-request@v7 with: token: ${{ secrets.GITHUB_TOKEN }} - add-paths: ${{ matrix.add-paths }} - commit-message: ${{ matrix.commit-message }} - branch: ${{ matrix.branch }} + add-paths: "." + commit-message: "Automatic package template update" + branch: "cruft/update" delete-branch: true - branch-suffix: timestamp - title: ${{ matrix.title }} + draft: ${{ steps.cruft_update.outputs.merge_conflicts == '1' }} + title: "Updates from the package template" body: | - This is an autogenerated PR, which will ${{ matrix.body }}. - [Cruft](https://cruft.github.io/cruft/) has detected updates from the Package Template + This is an autogenerated PR, which will applies the latest changes from the [SunPy Package Template](https://github.com/sunpy/package-template). + If this pull request has been opened as a draft there are conflicts which need fixing. + + **To run the CI on this pull request you will need to close it and reopen it.** diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d38bc48..70e64e8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,7 +2,7 @@ exclude: ".*(.csv|.fits|.fts|.fit|.header|.txt|tca.*|.json|.asdf)$|^CITATION.rst repos: # This should be before any formatting hooks like isort - repo: https://github.com/astral-sh/ruff-pre-commit - rev: "v0.6.9" + rev: "v0.7.2" hooks: - id: ruff args: ["--fix"] diff --git a/.ruff.toml b/.ruff.toml index f4e4e21..4aa06e5 100644 --- a/.ruff.toml +++ b/.ruff.toml @@ -1,5 +1,5 @@ target-version = "py310" -line-length = 110 +line-length = 120 exclude = [ ".git,", "__pycache__", @@ -8,30 +8,59 @@ exclude = [ ] [lint] -select = ["E", "F", "W", "UP", "PT"] +select = [ + "E", + "F", + "W", + "UP", + "PT", +] extend-ignore = [ # pycodestyle (E, W) - "E501", # LineTooLong # TODO! fix + "E501", # ignore line length will use a formatter instead + # pyupgrade (UP) + "UP038", # Use | in isinstance - not compatible with models and is slower # pytest (PT) "PT001", # Always use pytest.fixture() "PT004", # Fixtures which don't return anything should have leading _ - "PT007", # Parametrize should be lists of tuples # TODO! fix - "PT011", # Too broad exception assert # TODO! fix "PT023", # Always use () on pytest decorators + # flake8-pie (PIE) + "PIE808", # Disallow passing 0 as the first argument to range + # flake8-use-pathlib (PTH) + "PTH123", # open() should be replaced by Path.open() + # Ruff (RUF) + "RUF003", # Ignore ambiguous quote marks, doesn't allow ' in comments + "RUF012", # Mutable class attributes should be annotated with `typing.ClassVar` + "RUF013", # PEP 484 prohibits implicit `Optional` + "RUF015", # Prefer `next(iter(...))` over single element slice ] [lint.per-file-ignores] -# Part of configuration, not a package. -"setup.py" = ["INP001"] -"conftest.py" = ["INP001"] +"setup.py" = [ + "INP001", # File is part of an implicit namespace package. +] +"conftest.py" = [ + "INP001", # File is part of an implicit namespace package. +] "docs/conf.py" = [ - "E402" # Module imports not at top of file + "E402" # Module imports not at top of file ] "docs/*.py" = [ - "INP001", # Implicit-namespace-package. The examples are not a package. + "INP001", # File is part of an implicit namespace package. +] +"examples/**.py" = [ + "T201", # allow use of print in examples + "INP001", # File is part of an implicit namespace package. +] +"__init__.py" = [ + "E402", # Module level import not at top of cell + "F401", # Unused import + "F403", # from {name} import * used; unable to detect undefined names + "F405", # {name} may be undefined, or defined from star imports +] +"test_*.py" = [ + "E402", # Module level import not at top of cell ] -"__init__.py" = ["E402", "F401", "F403"] -"test_*.py" = ["B011", "D", "E402", "PGH001", "S101"] [lint.pydocstyle] convention = "numpy" diff --git a/docs/conf.py b/docs/conf.py index acbd14f..42adb3a 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -51,7 +51,7 @@ ] # Add any paths that contain templates here, relative to this directory. -# templates_path = ["_templates"] # NOQA: ERA001 +# templates_path = ["_templates"] # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. @@ -108,7 +108,7 @@ # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -# html_static_path = ["_static"] # NOQA: ERA001 +# html_static_path = ["_static"] # By default, when rendering docstrings for classes, sphinx.ext.autodoc will # make docs with the class-level docstring and the class-method docstrings, diff --git a/mpl_animators/_dev/scm_version.py b/mpl_animators/_dev/scm_version.py index b33a5ba..61adc66 100644 --- a/mpl_animators/_dev/scm_version.py +++ b/mpl_animators/_dev/scm_version.py @@ -1,11 +1,11 @@ # Try to use setuptools_scm to get the current version; this is only used # in development installations from the git repository. -import os.path +from pathlib import Path try: from setuptools_scm import get_version - version = get_version(root=os.path.join('..', '..'), relative_to=__file__) + version = get_version(root=Path('../..'), relative_to=__file__) except ImportError: raise ImportError('setuptools_scm not installed') except Exception as e: diff --git a/mpl_animators/extern/modest_image.py b/mpl_animators/extern/modest_image.py index 8e073ad..5ae6fef 100644 --- a/mpl_animators/extern/modest_image.py +++ b/mpl_animators/extern/modest_image.py @@ -4,7 +4,6 @@ """ # This file is copied from glue under the terms of the 3 Clause BSD licence. See licenses/GLUE.rst -from __future__ import print_function, division import matplotlib rcParams = matplotlib.rcParams @@ -42,7 +41,7 @@ def __init__(self, *args, **kwargs): self._pressed = False self._full_res = None self._full_extent = kwargs.get('extent', None) - super(ModestImage, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) self.invalidate_cache() self.axes.figure.canvas.mpl_connect('button_press_event', self._press) self.axes.figure.canvas.mpl_connect('button_release_event', self._release) @@ -53,7 +52,7 @@ def __init__(self, *args, **kwargs): self._timer.add_callback(self._resize_paused) def remove(self): - super(ModestImage, self).remove() + super().remove() self._timer.stop() self._timer = None @@ -113,7 +112,7 @@ def contains(self, mouseevent): if self._A is None or self._A.shape is None: return False else: - return super(ModestImage, self).contains(mouseevent) + return super().contains(mouseevent) def set_extent(self, extent): self._full_extent = extent @@ -220,7 +219,7 @@ def draw(self, renderer, *args, **kwargs): # in the array are masked. if hasattr(self._A, 'mask') and np.all(self._A.mask): return - super(ModestImage, self).draw(renderer, *args, **kwargs) + super().draw(renderer, *args, **kwargs) def main(): @@ -245,8 +244,7 @@ def main(): plt.gcf().canvas.draw_idle() t1 = time() - print("Draw time for %s: %0.1f ms" % (artist.__class__.__name__, - (t1 - t0) * 1000)) + print(f"Draw time for {artist.__class__.__name__}: {(t1 - t0) * 1000:0.1f} ms") plt.show() diff --git a/mpl_animators/tests/test_basefuncanimator.py b/mpl_animators/tests/test_basefuncanimator.py index 58dac45..f81e282 100644 --- a/mpl_animators/tests/test_basefuncanimator.py +++ b/mpl_animators/tests/test_basefuncanimator.py @@ -30,8 +30,8 @@ def button_func1(*args, **kwargs): @pytest.mark.parametrize(('fig', 'colorbar', 'buttons'), - ((None, False, [[], []]), - (mfigure.Figure(), True, [[button_func1], ["hi"]]))) + [(None, False, [[], []]), + (mfigure.Figure(), True, [[button_func1], ["hi"]])]) def test_base_func_init(fig, colorbar, buttons): data = np.random.random((3, 10, 10)) func0 = partial(update_plotval, data=data) diff --git a/mpl_animators/tests/test_wcs.py b/mpl_animators/tests/test_wcs.py index 6e98d1c..1303042 100644 --- a/mpl_animators/tests/test_wcs.py +++ b/mpl_animators/tests/test_wcs.py @@ -80,14 +80,14 @@ def wcs_3d(): return WCS(header=fits.Header.fromstring(header, sep='\n')) -@pytest.mark.parametrize(('data', 'slices', 'dim'), ( +@pytest.mark.parametrize(('data', 'slices', 'dim'), [ (np.arange(120).reshape((5, 4, 3, 2)), [0, 0, 'x', 'y'], 2), (np.arange(120).reshape((5, 4, 3, 2)), [0, 'x', 0, 'y'], 2), (np.arange(120).reshape((5, 4, 3, 2)), ['x', 0, 0, 'y'], 2), (np.arange(120).reshape((5, 4, 3, 2)), ['y', 0, 'x', 0], 2), (np.arange(120).reshape((5, 4, 3, 2)), ['x', 'y', 0, 0], 2), (np.arange(120).reshape((5, 4, 3, 2)), [0, 0, 0, 'x'], 1), -)) +]) def test_construct_array_animator(wcs_4d, data, slices, dim): array_animator = ArrayAnimatorWCS(data, wcs_4d, slices) diff --git a/pyproject.toml b/pyproject.toml index f20351e..d7b2d1d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -33,9 +33,9 @@ tests = [ docs = [ "sphinx", "sphinx-automodapi", + "sunpy-sphinx-theme", "packaging", "sphinx_gallery", - "sunpy-sphinx-theme", "sunpy", "scipy", ]