From 93dc84481313399897bfcf04b093e6127d74a9d7 Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Tue, 4 Jun 2024 17:26:05 +1200 Subject: [PATCH 01/20] Add pre-commit config with pre-commit-hooks Adding a .pre-commit-config.yaml file with some pre-commit hooks (check-added-large-files, check-yaml, end-of-file-fixer, trailing-whitespace). Also added pre-commit.ci config with autofix_prs=false, and autoupdate_schedule=quarterly. --- .pre-commit-config.yaml | 15 +++++++++++++++ environment.yml | 1 + 2 files changed, 16 insertions(+) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000000..f0a1bd83ac5 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,15 @@ +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.6.0 + hooks: + - id: check-added-large-files + - id: check-yaml + - id: end-of-file-fixer + - id: trailing-whitespace + +# https://pre-commit.ci/#configuration +ci: + autofix_prs: false + autoupdate_schedule: quarterly diff --git a/environment.yml b/environment.yml index 57a4799442e..21961dd8b8f 100644 --- a/environment.yml +++ b/environment.yml @@ -25,6 +25,7 @@ dependencies: - pip # Dev dependencies (style checks) - codespell + - pre-commit - ruff>=0.3.0 # Dev dependencies (unit testing) - matplotlib-base From 0d177305879fae5b6f3a567c72bfeb5a394323b1 Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Tue, 4 Jun 2024 17:37:31 +1200 Subject: [PATCH 02/20] Add pre-commit CI badge to main README.md Copied from https://results.pre-commit.ci/repo/github/85352251 --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index c415f5052df..f0dad7cee1f 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ [](https://anaconda.org/conda-forge/pygmt) [](https://github.com/GenericMappingTools/pygmt/actions/workflows/ci_tests.yaml) [](https://github.com/GenericMappingTools/pygmt/actions/workflows/ci_tests_dev.yaml) +[](https://results.pre-commit.ci/latest/github/GenericMappingTools/pygmt/main) [](https://github.com/astral-sh/ruff) [](https://app.codecov.io/gh/GenericMappingTools/pygmt) [](https://codspeed.io/GenericMappingTools/pygmt) From 8176a185aa71d44fb75a4f899e23f5939926f913 Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Tue, 4 Jun 2024 17:45:09 +1200 Subject: [PATCH 03/20] Mention pre-commit autofix command in doc/contributing.md Xref https://pre-commit.ci/#configuration-autofix_prs --- doc/contributing.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/contributing.md b/doc/contributing.md index 8ee7468d1d8..cd869f9007d 100644 --- a/doc/contributing.md +++ b/doc/contributing.md @@ -485,8 +485,8 @@ For consistency, we also use UNIX-style line endings (`\n`) and file permission 644 (`-rw-r--r--`) throughout the whole project. Don't worry if you forget to do it. Our continuous integration systems will warn us and you can make a new commit with the formatted code. -Even better, you can just write `/format` in the first line of any comment in a -pull request to lint the code automatically. +Even better, you can just write `/format` and/or `pre-commit.ci autofix` in the first +line of any comment in a pull request to lint the code automatically. When wrapping a new alias, use an underscore to separate words bridged by vowels (aeiou), such as `no_skip` and `z_only`. Do not use an underscore to separate From 4ae3ba5176f672648ff1427de0319a9bec03e37a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 4 Jun 2024 05:46:30 +0000 Subject: [PATCH 04/20] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- CODE_OF_CONDUCT.md | 2 +- doc/_templates/autosummary/class.rst | 1 - doc/_templates/autosummary/exception.rst | 1 - doc/_templates/autosummary/function.rst | 1 - doc/changes.md | 4 ++-- doc/team.md | 1 - examples/projections/README.txt | 2 +- pygmt/tests/data/contours.txt | 2 +- 8 files changed, 5 insertions(+), 9 deletions(-) diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index 7ff1c459c25..7246f53e333 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -1,2 +1,2 @@ All participants in the PyGMT community must abide by -the [Generic Mapping Tools organization Code of Conduct](https://github.com/GenericMappingTools/.github/blob/main/CODE_OF_CONDUCT.md). \ No newline at end of file +the [Generic Mapping Tools organization Code of Conduct](https://github.com/GenericMappingTools/.github/blob/main/CODE_OF_CONDUCT.md). diff --git a/doc/_templates/autosummary/class.rst b/doc/_templates/autosummary/class.rst index 5f1bd233edf..cda380f316a 100644 --- a/doc/_templates/autosummary/class.rst +++ b/doc/_templates/autosummary/class.rst @@ -30,4 +30,3 @@ .. raw:: html
- diff --git a/doc/_templates/autosummary/exception.rst b/doc/_templates/autosummary/exception.rst index 24f0ecbf66b..a3ee4ec8e25 100644 --- a/doc/_templates/autosummary/exception.rst +++ b/doc/_templates/autosummary/exception.rst @@ -8,4 +8,3 @@ .. raw:: html - diff --git a/doc/_templates/autosummary/function.rst b/doc/_templates/autosummary/function.rst index 98c403ac6f3..ee551b4b1e4 100644 --- a/doc/_templates/autosummary/function.rst +++ b/doc/_templates/autosummary/function.rst @@ -10,4 +10,3 @@ .. raw:: html - diff --git a/doc/changes.md b/doc/changes.md index e9a1a6ca17c..761ee93201f 100644 --- a/doc/changes.md +++ b/doc/changes.md @@ -7,9 +7,9 @@ ### Highlights * 🎉 **Twelfth minor release of PyGMT** 🎉 -* 🚀 Almost all module wrappers (with a few exceptions) now use in-memory GMT *virtual files* instead of intermediate temporary files to improve performance ([#2730](https://github.com/GenericMappingTools/pygmt/issues/2730)) +* 🚀 Almost all module wrappers (with a few exceptions) now use in-memory GMT *virtual files* instead of intermediate temporary files to improve performance ([#2730](https://github.com/GenericMappingTools/pygmt/issues/2730)) * Almost all module wrappers (with a few exceptions) now have consistent behavior for table-like output ([#1318](https://github.com/GenericMappingTools/pygmt/issues/1318)) -* Adopt [SPEC 0](https://scientific-python.org/specs/spec-0000/) policy for minimum supported versions of GMT, Python, and other core dependencies +* Adopt [SPEC 0](https://scientific-python.org/specs/spec-0000/) policy for minimum supported versions of GMT, Python, and other core dependencies ### Enhancements diff --git a/doc/team.md b/doc/team.md index 08a512bc979..d5af274ad82 100644 --- a/doc/team.md +++ b/doc/team.md @@ -116,4 +116,3 @@ year will be moved to Distinguished Contributors. :::: ::::: - diff --git a/examples/projections/README.txt b/examples/projections/README.txt index 5e43e4cc9af..594dc84a943 100644 --- a/examples/projections/README.txt +++ b/examples/projections/README.txt @@ -2,7 +2,7 @@ Projections =========== PyGMT supports many map projections. Use the ``projection`` parameter to specify which -one you want to use in all plotting methods. The projection is specified by a one-letter +one you want to use in all plotting methods. The projection is specified by a one-letter code along with (sometimes optional) reference longitude and latitude and the width of the map (for example, **A**\ *lon0/lat0*\ [*/horizon*\ ]\ */width*). The map height is determined based on the region and projection. diff --git a/pygmt/tests/data/contours.txt b/pygmt/tests/data/contours.txt index 59513b26929..34278aca356 100644 --- a/pygmt/tests/data/contours.txt +++ b/pygmt/tests/data/contours.txt @@ -5,4 +5,4 @@ 600 A 700 C 800 A -900 C \ No newline at end of file +900 C From c23f776f0f9a58b3e75bdf9b9c583e5705929563 Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Tue, 4 Jun 2024 18:02:27 +1200 Subject: [PATCH 05/20] Add .pre-commit-config.yaml to MAINIFEST.in --- MANIFEST.in | 1 + 1 file changed, 1 insertion(+) diff --git a/MANIFEST.in b/MANIFEST.in index da8835b2c12..6b926e1bc26 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -6,6 +6,7 @@ prune examples* prune pygmt/tests* exclude .dvcignore exclude .gitignore +exclude .pre-commit-config.yaml exclude .readthedocs.yaml exclude AUTHORSHIP.md exclude CODE_OF_CONDUCT.md From ce6d45725134fc1c13aa34ca3638af646aebb4a6 Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Tue, 4 Jun 2024 18:08:12 +1200 Subject: [PATCH 06/20] Add forbid-crlf, remove-crlf and chmod hooks, remove from GitHub Actions Enforcing LF line endings and 644 permissions via pre-commit hooks! --- .github/workflows/format-command.yml | 3 --- .github/workflows/style_checks.yaml | 7 ------- .pre-commit-config.yaml | 7 +++++++ 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/.github/workflows/format-command.yml b/.github/workflows/format-command.yml index 24a9da1d578..6905dde8c42 100644 --- a/.github/workflows/format-command.yml +++ b/.github/workflows/format-command.yml @@ -34,14 +34,11 @@ jobs: run: | python -m pip install ruff python -m pip list - sudo apt-get install dos2unix # Run "make format" and commit the change to the PR branch - name: Commit to the PR branch if any changes run: | make format - git ls-files -z | xargs -0 dos2unix --quiet - git ls-files -z | xargs -0 chmod 644 if [[ $(git ls-files -m) ]]; then git config --global user.name 'actions-bot' git config --global user.email '58130806+actions-bot@users.noreply.github.com' diff --git a/.github/workflows/style_checks.yaml b/.github/workflows/style_checks.yaml index 31914a4e9d4..6744c640ca3 100644 --- a/.github/workflows/style_checks.yaml +++ b/.github/workflows/style_checks.yaml @@ -36,17 +36,10 @@ jobs: run: | python -m pip install ruff python -m pip list - sudo apt-get install dos2unix - name: Formatting check (ruff) run: make check - - name: Ensure files use UNIX line breaks and have 644 permission - run: | - git ls-files -z | xargs -0 dos2unix --quiet - git ls-files -z | xargs -0 chmod 644 - if [[ $(git ls-files -m) ]]; then git --no-pager diff HEAD; exit 1; fi - - name: Ensure example scripts have at least one code block separator run: | git ls-files 'examples/**/*.py' | xargs grep --files-without-match '# %%' > output.txt diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f0a1bd83ac5..328813ae7bc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,6 +8,13 @@ repos: - id: check-yaml - id: end-of-file-fixer - id: trailing-whitespace +- repo: https://github.com/Lucas-C/pre-commit-hooks + rev: v1.5.5 + hooks: + - id: forbid-crlf + - id: remove-crlf + - id: chmod + args: ['644'] # https://pre-commit.ci/#configuration ci: From 5a01ad61b354a832fd956deb8da90b22ac1e22e1 Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Tue, 4 Jun 2024 18:21:36 +1200 Subject: [PATCH 07/20] Remove chmod pre-commit hook and use GitHub Action method again Partially revert ce6d45725134fc1c13aa34ca3638af646aebb4a6 to keep the 644 permission checks and format commands. --- .github/workflows/format-command.yml | 1 + .github/workflows/style_checks.yaml | 5 +++++ .pre-commit-config.yaml | 2 -- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/format-command.yml b/.github/workflows/format-command.yml index 6905dde8c42..9c5efee4261 100644 --- a/.github/workflows/format-command.yml +++ b/.github/workflows/format-command.yml @@ -39,6 +39,7 @@ jobs: - name: Commit to the PR branch if any changes run: | make format + git ls-files -z | xargs -0 chmod 644 if [[ $(git ls-files -m) ]]; then git config --global user.name 'actions-bot' git config --global user.email '58130806+actions-bot@users.noreply.github.com' diff --git a/.github/workflows/style_checks.yaml b/.github/workflows/style_checks.yaml index 6744c640ca3..06be4b8d5c6 100644 --- a/.github/workflows/style_checks.yaml +++ b/.github/workflows/style_checks.yaml @@ -40,6 +40,11 @@ jobs: - name: Formatting check (ruff) run: make check + - name: Ensure files have 644 permission + run: | + git ls-files -z | xargs -0 chmod 644 + if [[ $(git ls-files -m) ]]; then git --no-pager diff HEAD; exit 1; fi + - name: Ensure example scripts have at least one code block separator run: | git ls-files 'examples/**/*.py' | xargs grep --files-without-match '# %%' > output.txt diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 328813ae7bc..2b4440b5bb4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -13,8 +13,6 @@ repos: hooks: - id: forbid-crlf - id: remove-crlf - - id: chmod - args: ['644'] # https://pre-commit.ci/#configuration ci: From a444d3377f78af409326b9c24cc659b8f6e892e9 Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Sun, 9 Jun 2024 18:10:12 +1200 Subject: [PATCH 08/20] Add `pre-commit run --all-files` to `make format` --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 271e5d9083c..4494f2996c3 100644 --- a/Makefile +++ b/Makefile @@ -61,6 +61,7 @@ test_no_images: _runtest format: ruff check --fix --exit-zero $(FORMAT_FILES) ruff format $(FORMAT_FILES) + pre-commit run --all-files check: ruff check $(FORMAT_FILES) From b3eee6ff6a4d77bf0af24f30d71b5331c8faf526 Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Sun, 9 Jun 2024 18:16:21 +1200 Subject: [PATCH 09/20] Mention pre-commit autofix command in Pull Request template --- .github/PULL_REQUEST_TEMPLATE.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index dfc4d07e739..e2069b88a9a 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -18,9 +18,10 @@ Fixes # - [ ] If adding new functionality, add an example to docstrings or tutorials. - [ ] Use underscores (not hyphens) in names of Python files and directories. -**Slash Commands** +**Bot Commands** -You can write slash commands (`/command`) in the first line of a comment to perform -specific operations. Supported slash command is: +You can write certain commands in the first line of a comment to perform specific +operations. Supported commands are: - `/format`: automatically format and lint the code +- `pre-commit.ci autofix`: run pre-commit hooks to fix trailing whitespaces and other issues From d937cacf0d43ba76749ef6b6476a75b38bfd685d Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Tue, 11 Jun 2024 14:43:55 +1200 Subject: [PATCH 10/20] Revert "Add pre-commit CI badge to main README.md" This reverts commit 0d177305879fae5b6f3a567c72bfeb5a394323b1. --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index f0dad7cee1f..c415f5052df 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,6 @@ [](https://anaconda.org/conda-forge/pygmt) [](https://github.com/GenericMappingTools/pygmt/actions/workflows/ci_tests.yaml) [](https://github.com/GenericMappingTools/pygmt/actions/workflows/ci_tests_dev.yaml) -[](https://results.pre-commit.ci/latest/github/GenericMappingTools/pygmt/main) [](https://github.com/astral-sh/ruff) [](https://app.codecov.io/gh/GenericMappingTools/pygmt) [](https://codspeed.io/GenericMappingTools/pygmt) From 0f09fb605e4a4248c0ac0ca4766fb91299ddb6aa Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Tue, 11 Jun 2024 14:44:52 +1200 Subject: [PATCH 11/20] Revert "Mention pre-commit autofix command in doc/contributing.md" This reverts commit 8176a185aa71d44fb75a4f899e23f5939926f913. --- doc/contributing.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/contributing.md b/doc/contributing.md index cd869f9007d..8ee7468d1d8 100644 --- a/doc/contributing.md +++ b/doc/contributing.md @@ -485,8 +485,8 @@ For consistency, we also use UNIX-style line endings (`\n`) and file permission 644 (`-rw-r--r--`) throughout the whole project. Don't worry if you forget to do it. Our continuous integration systems will warn us and you can make a new commit with the formatted code. -Even better, you can just write `/format` and/or `pre-commit.ci autofix` in the first -line of any comment in a pull request to lint the code automatically. +Even better, you can just write `/format` in the first line of any comment in a +pull request to lint the code automatically. When wrapping a new alias, use an underscore to separate words bridged by vowels (aeiou), such as `no_skip` and `z_only`. Do not use an underscore to separate From 386ad8e9eba7f4a8ebfac4a13805db91d6b89c46 Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Tue, 11 Jun 2024 14:45:55 +1200 Subject: [PATCH 12/20] Revert "Mention pre-commit autofix command in Pull Request template" This reverts commit b3eee6ff6a4d77bf0af24f30d71b5331c8faf526. --- .github/PULL_REQUEST_TEMPLATE.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index e2069b88a9a..dfc4d07e739 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -18,10 +18,9 @@ Fixes # - [ ] If adding new functionality, add an example to docstrings or tutorials. - [ ] Use underscores (not hyphens) in names of Python files and directories. -**Bot Commands** +**Slash Commands** -You can write certain commands in the first line of a comment to perform specific -operations. Supported commands are: +You can write slash commands (`/command`) in the first line of a comment to perform +specific operations. Supported slash command is: - `/format`: automatically format and lint the code -- `pre-commit.ci autofix`: run pre-commit hooks to fix trailing whitespaces and other issues From 25652fc6b52298921f76914d003c17637287c067 Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Tue, 11 Jun 2024 14:53:16 +1200 Subject: [PATCH 13/20] Add pre-commit to Style Checks and format-command workflows Co-Authored-By: Dongdong Tian