From ff49438056be738f30863c78139c0f0fa7aa0b1d Mon Sep 17 00:00:00 2001 From: CyclingNinja Date: Wed, 30 Oct 2024 17:04:13 +0000 Subject: [PATCH] Updates cruft to most recent features --- .cruft.json | 5 ++- .github/workflows/sub_package_update.yml | 48 +++++++++++++++--------- .pre-commit-config.yaml | 2 +- .ruff.toml | 33 +++++++++++++--- radiospectra/_dev/scm_version.py | 4 +- 5 files changed, 64 insertions(+), 28 deletions(-) diff --git a/.cruft.json b/.cruft.json index 713057a..fbcf0a9 100644 --- a/.cruft.json +++ b/.cruft.json @@ -1,6 +1,6 @@ { "template": "https://github.com/sunpy/package-template", - "commit": "ed1ad671639f78312b042a76075ea7e9073ab804", + "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 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 64ced18..9d76b4c 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 269c162..9db6f90 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/radiospectra/_dev/scm_version.py b/radiospectra/_dev/scm_version.py index 1bcf0dd..988debf 100644 --- a/radiospectra/_dev/scm_version.py +++ b/radiospectra/_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: