Skip to content

Commit

Permalink
Merge pull request #3 from DWesl/add-pre-commit-hooks
Browse files Browse the repository at this point in the history
Add pre-commit hooks
  • Loading branch information
DWesl authored May 26, 2021
2 parents 9a6c14a + 68ad180 commit b7d14ad
Show file tree
Hide file tree
Showing 14 changed files with 119 additions and 40 deletions.
15 changes: 14 additions & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,17 @@ exclude=
docstring-convention=numpy
doctests=True
max-complexity=10
max-line-length=88
max-line-length=88
rst-roles=
# Sphinx
abbr
# My extlinks
pypi
extend_ignore=
# conflicts with numpydoc
RST201
RST301

[pydocstyle]
convention=numpy
add_ignore=D413
14 changes: 14 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
*.py text diff=python
requirements*.txt text

*.cfg text
*.ini text
*.toml text
*.yaml text

/.flake8 text

*.rst text

/MANIFEST.in text
/VERSION text
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ ECMWF
GFS
NAM
NAVGEM
RAP
RAP
44 changes: 44 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# 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.0.1
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- id: fix-encoding-pragma
- id: check-merge-conflict
- repo: https://github.com/PyCQA/isort
rev: 5.8.0
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: 21.5b1
hooks:
- id: black
- repo: https://github.com/PyCQA/flake8
rev: 3.9.2
hooks:
- id: flake8
additional_dependencies: ['flake8-docstrings', 'flake8-rst-docstrings', 'pep8-naming', 'flake8-print']
- repo: https://github.com/PyCQA/pydocstyle
rev: 6.1.1
hooks:
- id: pydocstyle
additional_dependencies: ['toml']
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.812
hooks:
- id: mypy
- repo: https://github.com/PyCQA/pylint
rev: v2.8.2
hooks:
- id: pylint
additional_dependencies: ['python-dateutil']
args: ['--disable=E0401,import-error', '--allow-any-import-level=eccodes']
- repo: https://github.com/asottile/setup-cfg-fmt
rev: v1.17.0
hooks:
- id: setup-cfg-fmt
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include requirements*.txt
include requirements*.txt
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.0.dev0
0.0.0.dev0
2 changes: 1 addition & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ files=src/download_nwp_model_data/*.py
exclude=*_flymake.py

[mypy-eccodes,metpy.*,siphon.catalog,cmdline_provenance,numpy]
ignore_missing_imports=True
ignore_missing_imports=True
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[build-system]
requires = ["setuptools>=30.3.0", "wheel"]
build-backend = "setuptools.build_meta"
build-backend = "setuptools.build_meta"
47 changes: 24 additions & 23 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,46 +1,47 @@
[metadata]
name=weather-data-downloader
version=file:VERSION
description=Download NWP model data
long_description=file:README.rst
long_description_content_type=text/x-rst
platform=any
author=DWesl
author_email=https://github.com/DWesl/weather-data-downloader/issues
url=https://github.com/DWesl/weather-data-downloader
classifiers=
name = weather_data_downloader
version = file:VERSION
description = Download NWP model data
long_description = file: README.rst
long_description_content_type = text/x-rst
url = https://github.com/DWesl/weather-data-downloader
author = DWesl
author_email = https://github.com/DWesl/weather-data-downloader/issues
classifiers =
Development Status :: 1 - Development
Intended Audience :: Developers
Operating System :: OS Independent
Programming Language :: Python :: 3
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Operating System :: OS Independent
zip-safe=True
platform = any
zip_safe = True

[options]
packages = find:
install_requires =
cmdline_provenance
dataclasses; python_version < "3.7"
importlib_metadata; python_version < "3.8"
metpy
numpy
python-dateutil
siphon
xarray
package_dir=
dataclasses;python_version < "3.7"
importlib_metadata;python_version < "3.8"
python_requires = >=3.6.*, <4.*
package_dir =
=src
packages=find:
python_requires= >=3.6.*, <4.*

[options.packages.find]
where = src

[options.entry_points]
console_scripts=
console_scripts =
download-nwp-model-data=download_nwp_model_output.__main__:main

[options.extras_require]
ecmwf=eccodes

[options.packages.find]
where=src
ecmwf =
eccodes

[sdist]
formats=bztar,zip,gztar,xztar
formats = bztar,zip,gztar,xztar
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-
"""Stub to allow old tools to work."""
from setuptools import setup

setup()
3 changes: 2 additions & 1 deletion src/download_nwp_model_output/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
"""Download specified NWP model data.
A quick conversion of my images-on-demand python/django code to just
Expand All @@ -14,7 +15,7 @@
try:
from importlib.metadata import version # type: ignore
except ImportError:
from importlib_metadata import version # type: ignore
from importlib_metadata import version

from .nwp_models import NWP_MODELS

Expand Down
2 changes: 1 addition & 1 deletion src/download_nwp_model_output/__main__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python
# ~*~ coding: utf8 ~*~
# -*- coding: utf-8 -*-
"""Script to download and save data for given model and time.
Each level currently saved in a different file to avoid a half-empty
Expand Down
4 changes: 2 additions & 2 deletions src/download_nwp_model_output/conventions_utilities.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ~*~ coding: utf8 ~*~
"""Utility functions for convention compliance
# -*- coding: utf-8 -*-
"""Utility functions for convention compliance.
Built around the Climate and Forecast (CF) and Attribute Conventions
for Data Discovert (ACDD) conventions. Implementation taken from
Expand Down
18 changes: 11 additions & 7 deletions src/download_nwp_model_output/nwp_models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# ~*~ coding: utf8 ~*~
# -*- coding: utf-8 -*-
"""Collect the data and algorithms needed to get model data.
One general-ish class (general for models available through TDS, less
Expand All @@ -16,7 +16,7 @@

import numpy as np
import xarray
from metpy.constants import earth_avg_radius as EARTH_RADIUS
from metpy.constants import earth_avg_radius as EARTH_RADIUS # noqa: N812
from metpy.units import units
from siphon.catalog import TDSCatalog

Expand All @@ -41,6 +41,8 @@ class NwpModel:
good checker.
"""

# pylint: disable=too-many-instance-attributes

abbrev: str
short_desc: str
cycling_interval: int
Expand Down Expand Up @@ -69,7 +71,7 @@ def convert_pressure_to_reported_units(self, pressure: int) -> int:
return int(units(f"{pressure:d} hPa").to(self.pressure_level_units).magnitude)

def is_model_start(self, init_time: datetime.datetime) -> bool:
"""Is there a model run starting at the given time?
"""Check if there is a model run starting at the given time.
Parameters
----------
Expand Down Expand Up @@ -127,7 +129,7 @@ def model_start_has_data(self, init_time: datetime.datetime) -> bool:
return (now - init_time) > datetime.timedelta(hours=self.cycling_interval)

def get_variable_name(self, variable: str) -> str:
"""Get the name used by the model for the variable
"""Get the name used by the model for the variable.
Parameters
----------
Expand All @@ -139,7 +141,7 @@ def get_variable_name(self, variable: str) -> str:
"""
return self.variable_mapping[variable]

def get_model_data(
def get_model_data( # pylint: disable=too-many-arguments,too-many-locals
self,
init_time: datetime.datetime,
valid_time: datetime.datetime,
Expand Down Expand Up @@ -260,8 +262,10 @@ def get_variable_name(var_name: str) -> typing.List[str]:
return dataset_cf


def xarray_from_grib_data(grib_data: bytes) -> xarray.DataArray:
"""Produce an XArray dataset from binary grib data
def xarray_from_grib_data( # pylint: disable=too-many-locals
grib_data: bytes,
) -> xarray.DataArray:
"""Produce an XArray dataset from binary grib data.
Parameters
----------
Expand Down

0 comments on commit b7d14ad

Please sign in to comment.