From 866cfa85cee5ae42687c74d8acda3c3998ce9eaa Mon Sep 17 00:00:00 2001 From: Stuart Mumford Date: Wed, 30 Oct 2024 16:51:34 +0000 Subject: [PATCH 1/5] Update cruft with batchpr --- .cruft.json | 5 ++- .github/workflows/sub_package_update.yml | 48 +++++++++++++++--------- .pre-commit-config.yaml | 2 +- .ruff.toml | 33 +++++++++++++--- docs/conf.py | 18 +++++++++ pyproject.toml | 1 + sunkit_instruments/_dev/__init__.py | 2 +- sunkit_instruments/_dev/scm_version.py | 4 +- 8 files changed, 84 insertions(+), 29 deletions(-) diff --git a/.cruft.json b/.cruft.json index 6cad2ada..08ed4d66 100644 --- a/.cruft.json +++ b/.cruft.json @@ -1,6 +1,6 @@ { "template": "https://github.com/sunpy/package-template", - "commit": "dd830771f0bb01d5313912e0082f3434715e474a", + "commit": "51fb616094a4d7577c8898445aa50effb89afa31", "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/sub_package_update.yml b/.github/workflows/sub_package_update.yml index 74558476..0b657f24 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 e7b1c01c..4a06984a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,7 +1,7 @@ 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.1" hooks: - id: ruff args: ["--fix"] diff --git a/.ruff.toml b/.ruff.toml index e74fba7c..5971e4c7 100644 --- a/.ruff.toml +++ b/.ruff.toml @@ -1,5 +1,5 @@ target-version = "py310" -line-length = 110 +line-length = 120 exclude = [ ".git,", "__pycache__", @@ -8,16 +8,34 @@ exclude = [ ] [lint] -select = ["E", "F", "W", "UP", "PT"] +select = [ + "E", + "F", + "W", + "UP", + "PT", +] extend-ignore = [ - # pycodestyle (E, W) - "E501", # LineTooLong # TODO! fix + # pycodestyle + "E501", # ignore line length will use a formatter instead + "E712", # Avoid equality comparisons to True; use if {cond}: for truth checks + "E721", # type comparison Use is and is not for type comparisons, or isinstance() for isinstance checks + # upgrades + "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 + "PT011", # except(ValueRaises) is too broad "PT023", # Always use () on pytest decorators + # flake8-pie + "PIE808", # Disallow passing 0 as the first argument to range + # flake8-use-pathlib + "PTH123", # open() should be replaced by Path.open() + # Ruff + "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] @@ -30,6 +48,9 @@ extend-ignore = [ "docs/*.py" = [ "INP001", # Implicit-namespace-package. The examples are not a package. ] +"examples/**.py" = [ + "T201", # allow use of print in examples +] "__init__.py" = ["E402", "F401", "F403"] "test_*.py" = ["B011", "D", "E402", "PGH001", "S101"] diff --git a/docs/conf.py b/docs/conf.py index 5f83edee..c71843c5 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -118,7 +118,25 @@ from sunpy_sphinx_theme import PNG_ICON +<<<<<<< html_theme = "sunpy" +======= +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +html_theme = "sunpy" + +# Render inheritance diagrams in SVG +graphviz_output_format = "svg" + +graphviz_dot_args = [ + "-Nfontsize=10", + "-Nfontname=Helvetica Neue, Helvetica, Arial, sans-serif", + "-Efontsize=10", + "-Efontname=Helvetica Neue, Helvetica, Arial, sans-serif", + "-Gfontsize=10", + "-Gfontname=Helvetica Neue, Helvetica, Arial, sans-serif", +] +>>>>>>> # 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, diff --git a/pyproject.toml b/pyproject.toml index 87f0b01e..2f04db93 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,6 +31,7 @@ tests = [ docs = [ "sphinx", "sphinx-automodapi", + "sunpy-sphinx-theme", "packaging", "sphinx-changelog", "sphinx-gallery", diff --git a/sunkit_instruments/_dev/__init__.py b/sunkit_instruments/_dev/__init__.py index 72583c08..e38b3a8d 100644 --- a/sunkit_instruments/_dev/__init__.py +++ b/sunkit_instruments/_dev/__init__.py @@ -1,5 +1,5 @@ """ -This package contains utilities that are only used when developing drms in a +This package contains utilities that are only used when developing in a copy of the source repository. These files are not installed, and should not be assumed to exist at runtime. diff --git a/sunkit_instruments/_dev/scm_version.py b/sunkit_instruments/_dev/scm_version.py index 1bcf0dd9..988debf5 100644 --- a/sunkit_instruments/_dev/scm_version.py +++ b/sunkit_instruments/_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 except Exception as e: From b3bfcc87078bf47bceb7a8aaa5e1b6272d95b245 Mon Sep 17 00:00:00 2001 From: Stuart Mumford Date: Mon, 11 Nov 2024 21:34:32 +0000 Subject: [PATCH 2/5] Update cruft with batchpr --- .cruft.json | 2 +- .github/workflows/label_sync.yml | 23 +++++++++++++++++ .pre-commit-config.yaml | 2 +- .ruff.toml | 44 +++++++++++++++++++------------- 4 files changed, 51 insertions(+), 20 deletions(-) create mode 100644 .github/workflows/label_sync.yml diff --git a/.cruft.json b/.cruft.json index 08ed4d66..fa4d8d93 100644 --- a/.cruft.json +++ b/.cruft.json @@ -1,6 +1,6 @@ { "template": "https://github.com/sunpy/package-template", - "commit": "51fb616094a4d7577c8898445aa50effb89afa31", + "commit": "75f84c4adf1753af67967930c3335bc73bca9bf5", "checkout": null, "context": { "cookiecutter": { diff --git a/.github/workflows/label_sync.yml b/.github/workflows/label_sync.yml new file mode 100644 index 00000000..7f217758 --- /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/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4a06984a..cea2efce 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,7 +1,7 @@ repos: # This should be before any formatting hooks like isort - repo: https://github.com/astral-sh/ruff-pre-commit - rev: "v0.7.1" + rev: "v0.7.2" hooks: - id: ruff args: ["--fix"] diff --git a/.ruff.toml b/.ruff.toml index 5971e4c7..41d56213 100644 --- a/.ruff.toml +++ b/.ruff.toml @@ -16,43 +16,51 @@ select = [ "PT", ] extend-ignore = [ - # pycodestyle + # pycodestyle (E, W) "E501", # ignore line length will use a formatter instead - "E712", # Avoid equality comparisons to True; use if {cond}: for truth checks - "E721", # type comparison Use is and is not for type comparisons, or isinstance() for isinstance checks - # upgrades + # 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 _ - "PT011", # except(ValueRaises) is too broad "PT023", # Always use () on pytest decorators - # flake8-pie + # flake8-pie (PIE) "PIE808", # Disallow passing 0 as the first argument to range - # flake8-use-pathlib + # flake8-use-pathlib (PTH) "PTH123", # open() should be replaced by Path.open() - # Ruff + # 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 + "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" From 7eb29df762e7922c68a1f6cf45fbe67fa55f247c Mon Sep 17 00:00:00 2001 From: Stuart Mumford Date: Mon, 11 Nov 2024 21:40:07 +0000 Subject: [PATCH 3/5] Update conf.py --- docs/conf.py | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index c71843c5..d0f48d0f 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -116,11 +116,6 @@ # -- Options for HTML output --------------------------------------------------- -from sunpy_sphinx_theme import PNG_ICON - -<<<<<<< -html_theme = "sunpy" -======= # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. html_theme = "sunpy" @@ -136,7 +131,6 @@ "-Gfontsize=10", "-Gfontname=Helvetica Neue, Helvetica, Arial, sans-serif", ] ->>>>>>> # 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, @@ -152,20 +146,10 @@ # https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html#confval-autoclass_content autoclass_content = "both" -# -- Graphviz Output ------------------------------------------------------------ - -graphviz_output_format = "svg" -graphviz_dot_args = [ - "-Nfontsize=10", - "-Nfontname=Helvetica Neue, Helvetica, Arial, sans-serif", - "-Efontsize=10", - "-Efontname=Helvetica Neue, Helvetica, Arial, sans-serif", - "-Gfontsize=10", - "-Gfontname=Helvetica Neue, Helvetica, Arial, sans-serif", -] - # -- Sphinx Gallery ------------------------------------------------------------ +from sunpy_sphinx_theme import PNG_ICON + sphinx_gallery_conf = { "backreferences_dir": os.path.join("generated", "modules"), "filename_pattern": "^((?!skip_).)*$", From f2cbd8cc231f43644935ab7d1aebd97842ef40d4 Mon Sep 17 00:00:00 2001 From: Stuart Mumford Date: Mon, 11 Nov 2024 21:40:28 +0000 Subject: [PATCH 4/5] Update pyproject.toml --- pyproject.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 2f04db93..d8c2586e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -35,7 +35,6 @@ docs = [ "packaging", "sphinx-changelog", "sphinx-gallery", - "sunpy-sphinx-theme", ] [project.urls] repository = "https://sunpy.org" From cc1628f8f86797a90c1857dc12c5647d6e283b85 Mon Sep 17 00:00:00 2001 From: Stuart Mumford Date: Mon, 11 Nov 2024 22:09:24 +0000 Subject: [PATCH 5/5] ignore PT011 --- .ruff.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/.ruff.toml b/.ruff.toml index 41d56213..7e471433 100644 --- a/.ruff.toml +++ b/.ruff.toml @@ -24,6 +24,7 @@ extend-ignore = [ "PT001", # Always use pytest.fixture() "PT004", # Fixtures which don't return anything should have leading _ "PT023", # Always use () on pytest decorators + "PT011", # TODO: Fix (no match= on pytest.raises) # flake8-pie (PIE) "PIE808", # Disallow passing 0 as the first argument to range # flake8-use-pathlib (PTH)