Skip to content

Commit b5242be

Browse files
weiji14seisman
andauthored
Add pre-commit config with pre-commit-hooks (#3283)
Adding a .pre-commit-config.yaml file with some pre-commit hooks (check-added-large-files, check-yaml, end-of-file-fixer, trailing-whitespace, forbid-crlf, remove-crlf, chmod). * Add .pre-commit-config.yaml to MAINIFEST.in * Add forbid-crlf, remove-crlf and chmod hooks, remove from GitHub Actions * Add `pre-commit run --all-files` to `make format` * Add pre-commit to Style Checks and format-command workflows * Update note on style_checks.yaml to mention ruff+pre-commit is ran * Mention that pre-commit is used to enforce LF ending and 644 permissions --------- Co-authored-by: Dongdong Tian <[email protected]>
1 parent 844594f commit b5242be

File tree

15 files changed

+32
-24
lines changed

15 files changed

+32
-24
lines changed

.github/workflows/format-command.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,13 @@ jobs:
3232
# Install formatting tools
3333
- name: Install formatting tools
3434
run: |
35-
python -m pip install ruff
35+
python -m pip install ruff pre-commit
3636
python -m pip list
37-
sudo apt-get install dos2unix
3837
3938
# Run "make format" and commit the change to the PR branch
4039
- name: Commit to the PR branch if any changes
4140
run: |
4241
make format
43-
git ls-files -z | xargs -0 dos2unix --quiet
44-
git ls-files -z | xargs -0 chmod 644
4542
if [[ $(git ls-files -m) ]]; then
4643
git config --global user.name 'actions-bot'
4744
git config --global user.email '[email protected]'

.github/workflows/style_checks.yaml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,13 @@ jobs:
3434

3535
- name: Install packages
3636
run: |
37-
python -m pip install ruff
37+
python -m pip install ruff pre-commit
3838
python -m pip list
39-
sudo apt-get install dos2unix
4039
41-
- name: Formatting check (ruff)
42-
run: make check
43-
44-
- name: Ensure files use UNIX line breaks and have 644 permission
40+
- name: Formatting check (ruff + pre-commit)
4541
run: |
46-
git ls-files -z | xargs -0 dos2unix --quiet
47-
git ls-files -z | xargs -0 chmod 644
48-
if [[ $(git ls-files -m) ]]; then git --no-pager diff HEAD; exit 1; fi
42+
make check
43+
pre-commit run --all-files
4944
5045
- name: Ensure example scripts have at least one code block separator
5146
run: |

.pre-commit-config.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# See https://pre-commit.com for more information
2+
# See https://pre-commit.com/hooks.html for more hooks
3+
repos:
4+
- repo: https://github.com/pre-commit/pre-commit-hooks
5+
rev: v4.6.0
6+
hooks:
7+
- id: check-added-large-files
8+
- id: check-yaml
9+
- id: end-of-file-fixer
10+
- id: trailing-whitespace
11+
- repo: https://github.com/Lucas-C/pre-commit-hooks
12+
rev: v1.5.5
13+
hooks:
14+
- id: forbid-crlf
15+
- id: remove-crlf
16+
- id: chmod
17+
args: ['644']

CODE_OF_CONDUCT.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
All participants in the PyGMT community must abide by
2-
the [Generic Mapping Tools organization Code of Conduct](https://github.com/GenericMappingTools/.github/blob/main/CODE_OF_CONDUCT.md).
2+
the [Generic Mapping Tools organization Code of Conduct](https://github.com/GenericMappingTools/.github/blob/main/CODE_OF_CONDUCT.md).

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ prune examples*
66
prune pygmt/tests*
77
exclude .dvcignore
88
exclude .gitignore
9+
exclude .pre-commit-config.yaml
910
exclude .readthedocs.yaml
1011
exclude AUTHORSHIP.md
1112
exclude CODE_OF_CONDUCT.md

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ test_no_images: _runtest
6161
format:
6262
ruff check --fix --exit-zero $(FORMAT_FILES)
6363
ruff format $(FORMAT_FILES)
64+
pre-commit run --all-files
6465

6566
check:
6667
ruff check $(FORMAT_FILES)

doc/_templates/autosummary/class.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,3 @@
3030
.. raw:: html
3131

3232
<div style='clear:both'></div>
33-

doc/_templates/autosummary/exception.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@
88
.. raw:: html
99

1010
<div style='clear:both'></div>
11-

doc/_templates/autosummary/function.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,3 @@
1010
.. raw:: html
1111

1212
<div style='clear:both'></div>
13-

doc/changes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
### Highlights
88

99
* 🎉 **Twelfth minor release of PyGMT** 🎉
10-
* 🚀 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))
10+
* 🚀 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))
1111
* Almost all module wrappers (with a few exceptions) now have consistent behavior for table-like output ([#1318](https://github.com/GenericMappingTools/pygmt/issues/1318))
12-
* Adopt [SPEC 0](https://scientific-python.org/specs/spec-0000/) policy for minimum supported versions of GMT, Python, and other core dependencies
12+
* Adopt [SPEC 0](https://scientific-python.org/specs/spec-0000/) policy for minimum supported versions of GMT, Python, and other core dependencies
1313

1414
### Enhancements
1515

0 commit comments

Comments
 (0)