Skip to content

Commit

Permalink
Implement pre-commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
owenlittlejohns committed Mar 29, 2024
1 parent deb2796 commit 693db8d
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 10 deletions.
14 changes: 14 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-json
- id: check-yaml
- id: check-added-large-files
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.4
hooks:
- id: ruff
args: ["--fix", "--show-fixes"]
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,37 @@ newest release of the code (starting at the top of the file).
## vX.Y.Z
```

### pre-commit hooks:

This repository uses [pre-commit](https://pre-commit.com/) to enable pre-commit
checking the repository for some coding standard best practices. These include:

* Removing trailing whitespaces.
* Removing blank lines at the end of a file.
* JSON files have valid formats.
* [ruff](https://github.com/astral-sh/ruff) Python linting checks.

To enable these checks:

```bash
# Install pre-commit Python package as part of test requirements:
pip install -r tests/pip_test_requirements.txt

# Install the git hook scripts:
pre-commit install

# (Optional) Run against all files:
pre-commit run --all-files
```

When you try to make a new commit locally, `pre-commit` will automatically run.
If any of the hooks detect non-compliance (e.g., trailing whitespace), that
hook will state it failed, and also try to fix the issue. You will need to
review and `git add` the changes before you can make a commit.

It is planned to implement additional hooks, possibly including tools such as
`black`, and `mypy`.

## Get in touch:

You can reach out to the maintainers of this repository via email:
Expand Down
2 changes: 1 addition & 1 deletion docker/tests.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ ENV PYTHONDONTWRITEBYTECODE=1
COPY tests/pip_test_requirements.txt .
RUN conda run --name hoss pip install --no-input -r pip_test_requirements.txt

# Copy test directory containing Python unittest suite, test data and utilities
# Copy test directory containing Python unittest suite, test data and utilities
COPY ./tests tests

# Set conda environment to hoss, as conda run will not stream logging.
Expand Down
2 changes: 1 addition & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#
#
# These requirements are used by the documentation Jupyter notebooks in the
# harmony-opendap-subsetter/docs directory.
#
Expand Down
2 changes: 1 addition & 1 deletion tests/data/ATL16_prefetch.dmr
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,4 @@
<Attribute name="short_name" type="String">
<Value>ATL16</Value>
</Attribute>
</Dataset>
</Dataset>
2 changes: 1 addition & 1 deletion tests/data/ATL16_prefetch_bnds.dmr
Original file line number Diff line number Diff line change
Expand Up @@ -217,4 +217,4 @@
<Attribute name="short_name" type="String">
<Value>ATL16</Value>
</Attribute>
</Dataset>
</Dataset>
2 changes: 1 addition & 1 deletion tests/data/ATL16_prefetch_group.dmr
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,4 @@
<Attribute name="short_name" type="String">
<Value>ATL16</Value>
</Attribute>
</Dataset>
</Dataset>
4 changes: 2 additions & 2 deletions tests/data/GPM_3IMERGHH_example.dmr
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ EndianType=LITTLE_ENDIAN;
</Attribute>
<Attribute name="LongName" type="String">
<Value>Longitude at the center of
0.10 degree grid intervals of longitude
0.10 degree grid intervals of longitude
from -180 to 180.</Value>
</Attribute>
<Attribute name="bounds" type="String">
Expand Down Expand Up @@ -157,7 +157,7 @@ EndianType=LITTLE_ENDIAN;
<Value>time</Value>
</Attribute>
<Attribute name="LongName" type="String">
<Value>Representative time of data in
<Value>Representative time of data in
seconds since 1970-01-01 00:00:00 UTC.</Value>
</Attribute>
<Attribute name="bounds" type="String">
Expand Down
2 changes: 1 addition & 1 deletion tests/data/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,4 @@
* ATL16_prefetch_bnds.dmr
- An example `.dmr` file that is nearly identical to the `ATL16_prefetch.dmr` file
except for four additional fabricated variables that represented the four
possible cases of combining bounds variable existence and cell alignment.
possible cases of combining bounds variable existence and cell alignment.
2 changes: 1 addition & 1 deletion tests/geojson_examples/multilinestring.geo.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@
}
}
]
}
}
1 change: 1 addition & 0 deletions tests/pip_test_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
coverage~=7.2.2
pre-commit~=3.7.0
pycodestyle~=2.10.0
pylint~=2.17.2
unittest-xml-reporting~=3.2.0
1 change: 0 additions & 1 deletion tests/unit/test_dimension_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

from harmony.util import config
from harmony.message import Message
from pathlib import PurePosixPath
from netCDF4 import Dataset
from numpy.ma import masked_array
from numpy.testing import assert_array_equal
Expand Down

0 comments on commit 693db8d

Please sign in to comment.