diff --git a/.github/workflows/format-command.yml b/.github/workflows/format-command.yml index 24a9da1d578..b197dc6aae0 100644 --- a/.github/workflows/format-command.yml +++ b/.github/workflows/format-command.yml @@ -32,16 +32,13 @@ jobs: # Install formatting tools - name: Install formatting tools run: | - python -m pip install ruff + python -m pip install ruff pre-commit 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..b7d57b5b532 100644 --- a/.github/workflows/style_checks.yaml +++ b/.github/workflows/style_checks.yaml @@ -34,18 +34,13 @@ jobs: - name: Install packages run: | - python -m pip install ruff + python -m pip install ruff pre-commit 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 + - name: Formatting check (ruff + pre-commit) 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 + make check + pre-commit run --all-files - name: Ensure example scripts have at least one code block separator run: | diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000000..d758c6b5187 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,17 @@ +# 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 +- repo: https://github.com/Lucas-C/pre-commit-hooks + rev: v1.5.5 + hooks: + - id: forbid-crlf + - id: remove-crlf + - id: chmod + args: ['644'] 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/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 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) 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/contributing.md b/doc/contributing.md index 8ee7468d1d8..ec33c9a4daa 100644 --- a/doc/contributing.md +++ b/doc/contributing.md @@ -481,8 +481,8 @@ the code yourself. Before committing, run it to automatically format your code: make format ``` -For consistency, we also use UNIX-style line endings (`\n`) and file permission -644 (`-rw-r--r--`) throughout the whole project. +For consistency, we also use `pre-commit` hooks to enforce 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 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/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 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