Skip to content

Commit

Permalink
Add pre-commit to manage code style & repo QA (#22)
Browse files Browse the repository at this point in the history
Initial hooks:

* Code formatting by black
* Trim trailing whitespace
* Ensure that files are either empty, or end with one newline
* Confirm that YAML files have parsable syntax
* Confirm that XML files have parsable syntax
* Prevent files larger than 500 kB from being committed
  • Loading branch information
douglatornell authored Nov 5, 2024
1 parent 35f6b48 commit 77985d2
Show file tree
Hide file tree
Showing 25 changed files with 143 additions and 112 deletions.
1 change: 0 additions & 1 deletion .github/workflows/assign-issue-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@ jobs:
issues: write
pull-requests: write
uses: UBC-MOAD/gha-workflows/.github/workflows/auto-assign.yaml@main

22 changes: 22 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Git pre-commit hooks config file
# Only takes effect if you have pre-commit installed in the env,
# and after you run `pre-commit install`
#
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
# Out-of-the-box hooks from the pre-commit org
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-xml
exclude: ^datasets\/(prefix|postfix)\.xml$
- id: check-added-large-files
# Code formatting with black
- repo: https://github.com/psf/black
rev: 24.10.0
hooks:
- id: black
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
"structlog"
],
"esbonio.sphinx.confDir": ""
}
}
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Also in the repo are:
* Python scripts to check that the XML fragments are well-formed,
and to build ``datasets.xml`` from the dataset description fragments
* Jupyter notebooks that are used to generate and maintain the dataset description fragments
* conda environment description YAML files to build conda environment in which the above code
* conda environment description YAML files to build conda environment in which the above code
can be executed


Expand Down
4 changes: 3 additions & 1 deletion build_datasets_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@

logger = structlog.get_logger()


def main(config_path, datasets_xml):
with config_path.open("rt") as _config:
config = yaml.safe_load(_config)

ds_tree = Path(config["datasets tree"])
prefix = ds_tree / config["prefix"]
postfix = ds_tree / config["postfix"]
ds_descs = [ds_tree/ds_desc for ds_desc in config["datasets"]]
ds_descs = [ds_tree / ds_desc for ds_desc in config["datasets"]]

logger.info("starting to write", datasets_xml=os.fspath(datasets_xml))
with datasets_xml.open("wt") as _datasets_xml:
Expand All @@ -44,6 +45,7 @@ def main(config_path, datasets_xml):
_write_section(postfix, _datasets_xml, end="")
logger.info("finished writing", datasets_xml=os.fspath(datasets_xml))


def _write_section(section, _datasets_xml, end="\n"):
with section.open("rt") as _section:
_datasets_xml.write(_section.read())
Expand Down
12 changes: 9 additions & 3 deletions check_datasets_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,23 @@ def main(config_path):
config = yaml.safe_load(_config)

ds_tree = Path(config["datasets tree"])
ds_descs = [ds_tree/ds_desc for ds_desc in config["datasets"]]
ds_descs = [ds_tree / ds_desc for ds_desc in config["datasets"]]
# ds_descs = [Path("test_datasets.xml")]

exit_code = 0
for ds_desc in ds_descs:
try:
lxml.etree.parse(ds_desc)
logger.info("lxml parse", dataset_description=os.fspath(ds_desc), status="ok")
logger.info(
"lxml parse", dataset_description=os.fspath(ds_desc), status="ok"
)
except lxml.etree.LxmlError as exc:
exit_code = 2
logger.info("lxml parse", dataset_description=os.fspath(ds_desc), status="not well-formed XML!")
logger.info(
"lxml parse",
dataset_description=os.fspath(ds_desc),
status="not well-formed XML!",
)
logger.exception(exc)
raise SystemExit(exit_code)

Expand Down
104 changes: 52 additions & 52 deletions datasets.xml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<att name="creator_name">SalishSeaCast Project Contributors</att>
<att name="creator_email">[email protected]</att>
<att name="creator_url">https://salishsea-meopar-docs.readthedocs.io/</att>
<att name="acknowledgement">Fisheries &amp; Oceans Canada,
<att name="acknowledgement">Fisheries &amp; Oceans Canada,
Vancouver Fraser Port Authority (VFPA)</att>
<att name="infoUrl">https://salishsea.eos.ubc.ca/</att>
<att name="institution">UCB EOAS, DFO IOS &amp; VFPA</att>
Expand Down
2 changes: 1 addition & 1 deletion datasets/atmospheric/ubcSSaAtmosphereGridV1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ They are licensed under the Apache License, Version 2.0. http://www.apache.org/l

This dataset is derived from a product of the Environment and Climate Change Canada HRDPS
(High Resolution Deterministic Prediction System) model.
The Terms and conditions of use of Meteorological Data from Environment and Climate Change Canada
The Terms and conditions of use of Meteorological Data from Environment and Climate Change Canada
are available at http://dd.weather.gc.ca/doc/LICENCE_GENERAL.txt.</att>
<att name="standard_name_vocabulary">CF Standard Name Table v29</att>
<att name="summary">HRDPS, SalishSeaCast, Atmospheric Forcing Grid, Geo-location, v1
Expand Down
6 changes: 3 additions & 3 deletions datasets/fvcom-vhfr/ubcSSFVCOM-VHFR-BaroclinicR12.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<att name="subsetVariables">fileType</att>
<att name="infoUrl">https://salishsea.eos.ubc.ca/</att>
<att name="institution">UBC EOAS &amp; DFO IOS</att>
<att name="institution_fullname">Dept of Earth, Ocean &amp; Atmospheric Sciences, University of British Columbia,
<att name="institution_fullname">Dept of Earth, Ocean &amp; Atmospheric Sciences, University of British Columbia,
Fisheries and Oceans Canada, Institute of Ocean Sciences</att>
<att name="keywords">model results, file, identifier, lastModified, modified, name, size, time</att>
<att name="license">The SalishSeaCast model results are copyright
Expand Down Expand Up @@ -43,8 +43,8 @@ R12: FVCOM-4.1; NEMO-3.6; ubcSSnBathymetryV17-02 bathymetry.
<att name="creator_name">SalishSeaCast Project Contributors</att>
<att name="creator_email">[email protected]</att>
<att name="creator_url">https://salishsea-meopar-docs.readthedocs.io/</att>
<att name="acknowledgement">Fisheries &amp; Oceans Canada,
Ocean Networks Canada (ONC),
<att name="acknowledgement">Fisheries &amp; Oceans Canada,
Ocean Networks Canada (ONC),
Digital Research Alliance of Canada</att>
<att name="history">null</att>
</addAttributes>
Expand Down
6 changes: 3 additions & 3 deletions datasets/fvcom-vhfr/ubcSSFVCOM-VHFR-BaroclinicX2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<att name="subsetVariables">fileType</att>
<att name="infoUrl">https://salishsea.eos.ubc.ca/</att>
<att name="institution">UBC EOAS &amp; DFO IOS</att>
<att name="institution_fullname">Dept of Earth, Ocean &amp; Atmospheric Sciences, University of British Columbia,
<att name="institution_fullname">Dept of Earth, Ocean &amp; Atmospheric Sciences, University of British Columbia,
Fisheries and Oceans Canada, Institute of Ocean Sciences</att>
<att name="keywords">model results, file, identifier, lastModified, modified, name, size, time</att>
<att name="license">The SalishSeaCast model results are copyright
Expand Down Expand Up @@ -43,8 +43,8 @@ X2: FVCOM-4.1; NEMO-3.6; ubcSSnBathymetryV17-02 bathymetry.
<att name="creator_name">SalishSeaCast Project Contributors</att>
<att name="creator_email">[email protected]</att>
<att name="creator_url">https://salishsea-meopar-docs.readthedocs.io/</att>
<att name="acknowledgement">Fisheries &amp; Oceans Canada,
Ocean Networks Canada (ONC),
<att name="acknowledgement">Fisheries &amp; Oceans Canada,
Ocean Networks Canada (ONC),
Digital Research Alliance of Canada</att>
<att name="history">null</att>
</addAttributes>
Expand Down
6 changes: 3 additions & 3 deletions datasets/fvcom-vhfr/ubcSSFVCOM-VHFRLowFilesV2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<att name="subsetVariables">fileType</att>
<att name="infoUrl">https://salishsea.eos.ubc.ca/</att>
<att name="institution">UBC EOAS &amp; DFO IOS</att>
<att name="institution_fullname">Dept of Earth, Ocean &amp; Atmospheric Sciences, University of British Columbia,
<att name="institution_fullname">Dept of Earth, Ocean &amp; Atmospheric Sciences, University of British Columbia,
Fisheries and Oceans Canada, Institute of Ocean Sciences</att>
<att name="keywords">model results, file, identifier, lastModified, modified, name, size, time</att>
<att name="license">The SalishSeaCast model results are copyright
Expand All @@ -40,8 +40,8 @@ V2: FVCOM-4.1; NEMO-3.6; ubcSSnBathymetryV17-02 bathymetry.
<att name="creator_name">SalishSeaCast Project Contributors</att>
<att name="creator_email">[email protected]</att>
<att name="creator_url">https://salishsea-meopar-docs.readthedocs.io/</att>
<att name="acknowledgement">Fisheries &amp; Oceans Canada,
Ocean Networks Canada (ONC),
<att name="acknowledgement">Fisheries &amp; Oceans Canada,
Ocean Networks Canada (ONC),
Digital Research Alliance of Canada</att>
<att name="history">null</att>
</addAttributes>
Expand Down
10 changes: 5 additions & 5 deletions datasets/nemo-grid/ubcSSn2DMeshMaskV17-02.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ https://bitbucket.org/salishsea/nemo-forcing/src/tip/grid/bathymetery_201702.nc
<att name="creator_name">SalishSeaCast Project Contributors</att>
<att name="creator_email">[email protected]</att>
<att name="creator_url">https://salishsea-meopar-docs.readthedocs.io/</att>
<att name="acknowledgement">Canadian Hydrographic Service (CHS),
National Ocean and Atmospheric Administration (NOAA),
United States Geological Service (USGS),
<att name="acknowledgement">Canadian Hydrographic Service (CHS),
National Ocean and Atmospheric Administration (NOAA),
United States Geological Service (USGS),
Digital Research Alliance of Canada

This product has been produced by the University of British Columbia based in part on
Canadian Hydrographic Service charts and/or data, pursuant to CHS Direct User Licence
This product has been produced by the University of British Columbia based in part on
Canadian Hydrographic Service charts and/or data, pursuant to CHS Direct User Licence
No. 2016-0504-1260-U.

The incorporation of data sourced from CHS in this product shall not be construed as
Expand Down
10 changes: 5 additions & 5 deletions datasets/nemo-grid/ubcSSn2DMeshMaskV21-08.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
<att name="creator_name">SalishSeaCast Project Contributors</att>
<att name="creator_email">[email protected]</att>
<att name="creator_url">https://salishsea-meopar-docs.readthedocs.io/</att>
<att name="acknowledgement">Canadian Hydrographic Service (CHS),
National Ocean and Atmospheric Administration (NOAA),
United States Geological Service (USGS),
<att name="acknowledgement">Canadian Hydrographic Service (CHS),
National Ocean and Atmospheric Administration (NOAA),
United States Geological Service (USGS),
Digital Research Alliance of Canada

This product has been produced by the University of British Columbia based in part on
Canadian Hydrographic Service charts and/or data, pursuant to CHS Direct User Licence
This product has been produced by the University of British Columbia based in part on
Canadian Hydrographic Service charts and/or data, pursuant to CHS Direct User Licence
No. 2016-0504-1260-U.

The incorporation of data sourced from CHS in this product shall not be construed as
Expand Down
10 changes: 5 additions & 5 deletions datasets/nemo-grid/ubcSSn3DMeshMaskV17-02.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ https://bitbucket.org/salishsea/nemo-forcing/src/tip/grid/bathymetery_201702.nc
<att name="creator_name">SalishSeaCast Project Contributors</att>
<att name="creator_email">[email protected]</att>
<att name="creator_url">https://salishsea-meopar-docs.readthedocs.io/</att>
<att name="acknowledgement">Canadian Hydrographic Service (CHS),
National Ocean and Atmospheric Administration (NOAA),
United States Geological Service (USGS),
<att name="acknowledgement">Canadian Hydrographic Service (CHS),
National Ocean and Atmospheric Administration (NOAA),
United States Geological Service (USGS),
Digital Research Alliance of Canada

This product has been produced by the University of British Columbia based in part on
Canadian Hydrographic Service charts and/or data, pursuant to CHS Direct User Licence
This product has been produced by the University of British Columbia based in part on
Canadian Hydrographic Service charts and/or data, pursuant to CHS Direct User Licence
No. 2016-0504-1260-U.

The incorporation of data sourced from CHS in this product shall not be construed as
Expand Down
10 changes: 5 additions & 5 deletions datasets/nemo-grid/ubcSSn3DMeshMaskV21-08.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
<att name="creator_name">SalishSeaCast Project Contributors</att>
<att name="creator_email">[email protected]</att>
<att name="creator_url">https://salishsea-meopar-docs.readthedocs.io/</att>
<att name="acknowledgement">Canadian Hydrographic Service (CHS),
National Ocean and Atmospheric Administration (NOAA),
United States Geological Service (USGS),
<att name="acknowledgement">Canadian Hydrographic Service (CHS),
National Ocean and Atmospheric Administration (NOAA),
United States Geological Service (USGS),
Digital Research Alliance of Canada

This product has been produced by the University of British Columbia based in part on
Canadian Hydrographic Service charts and/or data, pursuant to CHS Direct User Licence
This product has been produced by the University of British Columbia based in part on
Canadian Hydrographic Service charts and/or data, pursuant to CHS Direct User Licence
No. 2016-0504-1260-U.

The incorporation of data sourced from CHS in this product shall not be construed as
Expand Down
10 changes: 5 additions & 5 deletions datasets/nemo-grid/ubcSSnBathymetryV17-02.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
<att name="creator_name">SalishSeaCast Project Contributors</att>
<att name="creator_email">[email protected]</att>
<att name="creator_url">https://salishsea-meopar-docs.readthedocs.io/</att>
<att name="acknowledgement">Canadian Hydrographic Service (CHS),
National Ocean and Atmospheric Administration (NOAA),
United States Geological Service (USGS),
<att name="acknowledgement">Canadian Hydrographic Service (CHS),
National Ocean and Atmospheric Administration (NOAA),
United States Geological Service (USGS),
Digital Research Alliance of Canada

This product has been produced by the University of British Columbia based in part on
Canadian Hydrographic Service charts and/or data, pursuant to CHS Direct User Licence
This product has been produced by the University of British Columbia based in part on
Canadian Hydrographic Service charts and/or data, pursuant to CHS Direct User Licence
No. 2016-0504-1260-U.

The incorporation of data sourced from CHS in this product shall not be construed as
Expand Down
14 changes: 7 additions & 7 deletions datasets/nemo-grid/ubcSSnBathymetryV21-08.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
<att name="creator_name">SalishSeaCast Project Contributors</att>
<att name="creator_email">[email protected]</att>
<att name="creator_url">https://salishsea-meopar-docs.readthedocs.io/</att>
<att name="acknowledgement">Canadian Hydrographic Service (CHS),
National Ocean and Atmospheric Administration (NOAA),
United States Geological Service (USGS),
<att name="acknowledgement">Canadian Hydrographic Service (CHS),
National Ocean and Atmospheric Administration (NOAA),
United States Geological Service (USGS),
Digital Research Alliance of Canada

This product has been produced by the University of British Columbia based in part on
Canadian Hydrographic Service charts and/or data, pursuant to CHS Direct User Licence
This product has been produced by the University of British Columbia based in part on
Canadian Hydrographic Service charts and/or data, pursuant to CHS Direct User Licence
No. 2016-0504-1260-U.

The incorporation of data sourced from CHS in this product shall not be construed as
Expand Down Expand Up @@ -75,7 +75,7 @@ v17-02: same variables,
* CHS Multibeam data and all point cloud data for the Salish Sea.
Straightened and smoothed Juan de Fuca &amp; Johnstone Strait open boundaries.
Added proxy channel for Fraser River upstream of confluence with the Pitt River.
Adjustments by Michael Dunphy to increase resolution of Fraser River channels downstream of
Adjustments by Michael Dunphy to increase resolution of Fraser River channels downstream of
confluence with the Pitt River.
v21-08: same variables,
Bathymetry composed from 3 datasets:
Expand All @@ -84,7 +84,7 @@ v21-08: same variables,
* CHS Multibeam data and all point cloud data for the Salish Sea.
Straightened and smoothed Juan de Fuca &amp; Johnstone Strait open boundaries.
Added proxy channel for Fraser River upstream of confluence with the Pitt River.
Adjustments by Michael Dunphy to increase resolution of Fraser River channels downstream of
Adjustments by Michael Dunphy to increase resolution of Fraser River channels downstream of
confluence with the Pitt River.
Moved coastline to 2m isobath and set depth there to 4m; in contrast to 4m depth at 0m isobath;
volume is approximately conserved.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ https://dx.doi.org/10.1016/j.ocemod.2017.02.008</att>
<att name="long_name">Grid X</att>
<att name="standard_name">x</att>
<att name="coverage_content_type">modelResult</att>
<att name="comment">gridX values are grid indices in the model x-direction;
<att name="comment">gridX values are grid indices in the model x-direction;
geo-location data for the SalishSeaCast NEMO model grid is available in the ubcSSnBathymetry2V17-02 dataset.</att>
<att name="ioos_category">location</att>
</addAttributes>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ They are licensed under the Apache License, Version 2.0. https://www.apache.org/
<att name="summary">Green, SalishSeaCast, 3d Biology Fields, Monthly, v19-05

3d SMELT biological model field values averaged over 1 month intervals
from SalishSeaCast NEMO model runs with physics, biology and chemistry.
from SalishSeaCast NEMO model runs with physics, biology and chemistry.
The values are calculated for the entire model grid that includes the Juan de Fuca Strait, the Strait of Georgia,
Puget Sound, and Johnstone Strait on the coasts of Washington State and British Columbia.
The time values are UTC.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ They are licensed under the Apache License, Version 2.0. https://www.apache.org/

Variable values at the 3d zonal (u) component velocity grid points averaged over 1 month intervals
from SalishSeaCast NEMO model runs with physics, biology and chemistry.
The values are calculated for the entire model grid that includes the Juan de Fuca Strait, the Strait of Georgia,
The values are calculated for the entire model grid that includes the Juan de Fuca Strait, the Strait of Georgia,
Puget Sound, and Johnstone Strait on the coasts of Washington State and British Columbia.
The time values are UTC.
They are the centre of the intervals over which the calculated model results are averaged;
Expand Down
6 changes: 3 additions & 3 deletions datasets/wwatch3/ubcSSWaveWatch3-SoGFilesV17-02.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<att name="subsetVariables">fileType</att>
<att name="infoUrl">https://salishsea.eos.ubc.ca/</att>
<att name="institution">UBC EOAS &amp; DFO IOS</att>
<att name="institution_fullname">Dept of Earth, Ocean &amp; Atmospheric Sciences, University of British Columbia,
<att name="institution_fullname">Dept of Earth, Ocean &amp; Atmospheric Sciences, University of British Columbia,
Fisheries and Oceans Canada, Institute of Ocean Sciences</att>
<att name="keywords">model results, file, identifier, lastModified, modified, name, size, time</att>
<att name="license">The SalishSeaCast model results are copyright
Expand All @@ -37,8 +37,8 @@ v17-02: WaveWatch III&#174; v5.16; NEMO-3.6; ubcSSnBathymetryV17-02 bathymetry;
<att name="creator_name">SalishSeaCast Project Contributors</att>
<att name="creator_email">[email protected]</att>
<att name="creator_url">https://salishsea-meopar-docs.readthedocs.io/</att>
<att name="acknowledgement">Fisheries &amp; Oceans CanadaCast,
Ocean Networks Canada (ONC),
<att name="acknowledgement">Fisheries &amp; Oceans CanadaCast,
Ocean Networks Canada (ONC),
Digital Research Alliance of Canada</att>
<att name="history">null</att>
</addAttributes>
Expand Down
Loading

0 comments on commit 77985d2

Please sign in to comment.