Skip to content

Commit 741c727

Browse files
authored
Setup pre-commit (#124)
* Setup pre-commit hooks for black, flake8, isort
1 parent 2747f0d commit 741c727

12 files changed

Lines changed: 633 additions & 415 deletions

File tree

.flake8

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[flake8]
2+
max-line-length = 88
3+
extend-ignore = E203, E704

.pre-commit-config.yaml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
ci:
2+
autoupdate_schedule: monthly
3+
autofix_prs: false
4+
5+
repos:
6+
- repo: https://github.com/pre-commit/pre-commit-hooks
7+
rev: v4.4.0
8+
hooks:
9+
- id: trailing-whitespace
10+
- id: end-of-file-fixer
11+
- id: check-docstring-first
12+
- id: check-json
13+
- id: check-yaml
14+
- id: double-quote-string-fixer
15+
- id: debug-statements
16+
- id: mixed-line-ending
17+
18+
- repo: https://github.com/asottile/pyupgrade
19+
rev: v3.3.1
20+
hooks:
21+
- id: pyupgrade
22+
args:
23+
- '--py38-plus'
24+
25+
- repo: https://github.com/psf/black
26+
rev: 23.3.0
27+
hooks:
28+
- id: black
29+
- id: black-jupyter
30+
31+
- repo: https://github.com/keewis/blackdoc
32+
rev: v0.3.8
33+
hooks:
34+
- id: blackdoc
35+
36+
- repo: https://github.com/PyCQA/flake8
37+
rev: 6.0.0
38+
hooks:
39+
- id: flake8
40+
41+
- repo: https://github.com/PyCQA/isort
42+
rev: 5.12.0
43+
hooks:
44+
- id: isort
45+
46+
- repo: https://github.com/pre-commit/mirrors-prettier
47+
rev: v3.0.0-alpha.6
48+
hooks:
49+
- id: prettier

.prettierrc.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
semi = false
2+
singleQuote = true

dataretrieval/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from importlib.metadata import version
2-
from importlib.metadata import PackageNotFoundError
1+
from importlib.metadata import PackageNotFoundError, version
2+
33
from dataretrieval.nadp import *
44
from dataretrieval.nwis import *
55
from dataretrieval.streamstats import *
@@ -10,4 +10,4 @@
1010
try:
1111
__version__ = version('dataretrieval')
1212
except PackageNotFoundError:
13-
__version__ = "version-unknown"
13+
__version__ = 'version-unknown'

dataretrieval/codes/states.py

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,54 @@
11
"""List of 2-digit state codes with commented full names."""
22
state_codes = [
3-
'al', # Alabama
4-
'ak', # Alaska
5-
'az', # Arizona
6-
'ar', # Arkansas
7-
'ca', # California
8-
'co', # Colorado
9-
'ct', # Connecticut
10-
'de', # Delaware
11-
'dc', # District of Columbia
12-
'fl', # Florida
13-
'ga', # Georgia
14-
'hi', # Hawaii
15-
'id', # Idaho
16-
'il', # Illinois
17-
'in', # Indiana
18-
'ia', # Iowa
19-
'ks', # Kansas
20-
'ky', # Kentucky
21-
'la', # Louisiana
22-
'me', # Maine
23-
'md', # Maryland
24-
'ma', # Massachusetts
25-
'mi', # Michigan
26-
'mn', # Minnesota
27-
'ms', # Mississippi
28-
'mo', # Missouri
29-
'mt', # Montana
30-
'ne', # Nebraska
31-
'nv', # Nevada
32-
'nh', # New Hampshire
33-
'nj', # New Jersey
34-
'nm', # New Mexico
35-
'ny', # New York
36-
'nc', # North Carolina
37-
'nd', # North Dakota
38-
'oh', # Ohio
39-
'ok', # Oklahoma
40-
'or', # Oregon
41-
'pa', # Pennsylvania
42-
'ri', # Rhode Island
43-
'sc', # South Carolina
44-
'sd', # South Dakota
45-
'tn', # Tennessee
46-
'tx', # Texas
47-
'ut', # Utah
48-
'vt', # Vermont
49-
'va', # Virginia
50-
'wa', # Washington
51-
'wv', # West Virginia
52-
'wi', # Wisconsin
53-
'wy', # Wyoming
3+
'al', # Alabama
4+
'ak', # Alaska
5+
'az', # Arizona
6+
'ar', # Arkansas
7+
'ca', # California
8+
'co', # Colorado
9+
'ct', # Connecticut
10+
'de', # Delaware
11+
'dc', # District of Columbia
12+
'fl', # Florida
13+
'ga', # Georgia
14+
'hi', # Hawaii
15+
'id', # Idaho
16+
'il', # Illinois
17+
'in', # Indiana
18+
'ia', # Iowa
19+
'ks', # Kansas
20+
'ky', # Kentucky
21+
'la', # Louisiana
22+
'me', # Maine
23+
'md', # Maryland
24+
'ma', # Massachusetts
25+
'mi', # Michigan
26+
'mn', # Minnesota
27+
'ms', # Mississippi
28+
'mo', # Missouri
29+
'mt', # Montana
30+
'ne', # Nebraska
31+
'nv', # Nevada
32+
'nh', # New Hampshire
33+
'nj', # New Jersey
34+
'nm', # New Mexico
35+
'ny', # New York
36+
'nc', # North Carolina
37+
'nd', # North Dakota
38+
'oh', # Ohio
39+
'ok', # Oklahoma
40+
'or', # Oregon
41+
'pa', # Pennsylvania
42+
'ri', # Rhode Island
43+
'sc', # South Carolina
44+
'sd', # South Dakota
45+
'tn', # Tennessee
46+
'tx', # Texas
47+
'ut', # Utah
48+
'vt', # Vermont
49+
'va', # Virginia
50+
'wa', # Washington
51+
'wv', # West Virginia
52+
'wi', # Wisconsin
53+
'wy', # Wyoming
5454
]

dataretrieval/nadp.py

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
2-
Tools for retrieving data from the National Atmospheric Deposition Program (NADP) including
3-
the National Trends Network (NTN), the Mercury Deposition Network (MDN).
2+
Tools for retrieving data from the National Atmospheric Deposition Program
3+
(NADP) including the National Trends Network (NTN), the Mercury Deposition
4+
Network (MDN).
45
56
National Trends Network
67
-----------------------
@@ -28,32 +29,43 @@
2829
2930
"""
3031

31-
import requests
32-
import zipfile
3332
import io
3433
import os
3534
import re
35+
import zipfile
3636
from os.path import basename
3737

38+
import requests
3839

3940
NADP_URL = 'https://nadp.slh.wisc.edu'
4041
NADP_MAP_EXT = 'filelib/maps'
4142

42-
NTN_CONC_PARAMS = ['pH', 'So4', 'NO3', 'NH4', 'Ca',
43-
'Mg', 'K', 'Na', 'Cl', 'Br']
44-
NTN_DEP_PARAMS = ['H', 'So4', 'NO3', 'NH4', 'Ca', 'Mg',
45-
'K', 'Na', 'Cl', 'Br', 'N', 'SPlusN']
43+
NTN_CONC_PARAMS = ['pH', 'So4', 'NO3', 'NH4', 'Ca', 'Mg', 'K', 'Na', 'Cl', 'Br']
44+
NTN_DEP_PARAMS = [
45+
'H',
46+
'So4',
47+
'NO3',
48+
'NH4',
49+
'Ca',
50+
'Mg',
51+
'K',
52+
'Na',
53+
'Cl',
54+
'Br',
55+
'N',
56+
'SPlusN',
57+
]
4658

4759
NTN_MEAS_TYPE = ['conc', 'dep', 'precip'] # concentration or deposition
4860

4961

5062
class NADP_ZipFile(zipfile.ZipFile):
51-
"""Extend zipfile.ZipFile for working on data from NADP
52-
"""
63+
"""Extend zipfile.ZipFile for working on data from NADP"""
64+
5365
def tif_name(self):
5466
"""Get the name of the tif file in the zip file."""
5567
filenames = self.namelist()
56-
r = re.compile(".*tif$")
68+
r = re.compile('.*tif$')
5769
tif_list = list(filter(r.match, filenames))
5870
return tif_list[0]
5971

@@ -93,23 +105,23 @@ def get_annual_MDN_map(measurement_type, year, path):
93105
94106
>>> # get map of mercury concentration in 2010 and extract it to a path
95107
>>> data_path = dataretrieval.nadp.get_annual_MDN_map(
96-
... measurement_type='conc', year='2010', path='somepath')
108+
... measurement_type='conc', year='2010', path='somepath'
109+
... )
97110
98111
"""
99-
url = '{}/{}/MDN/grids/'.format(NADP_URL, NADP_MAP_EXT)
112+
url = f'{NADP_URL}/{NADP_MAP_EXT}/MDN/grids/'
100113

101-
filename = 'Hg_{}_{}.zip'.format(measurement_type, year)
114+
filename = f'Hg_{measurement_type}_{year}.zip'
102115

103116
z = get_zip(url, filename)
104117

105118
if path:
106119
z.extractall(path)
107120

108-
return '{}{}{}'.format(path, os.sep, basename(filename))
121+
return f'{path}{os.sep}{basename(filename)}'
109122

110123

111-
def get_annual_NTN_map(measurement_type, measurement=None, year=None,
112-
path="."):
124+
def get_annual_NTN_map(measurement_type, measurement=None, year=None, path='.'):
113125
"""Download a NTN map from NDAP.
114126
115127
This function looks for a zip file containing gridded information at:
@@ -146,22 +158,23 @@ def get_annual_NTN_map(measurement_type, measurement=None, year=None,
146158
147159
>>> # get a map of precipitation in 2015 and extract it to a path
148160
>>> data_path = dataretrieval.nadp.get_annual_NTN_map(
149-
... measurement_type='Precip', year='2015', path='somepath')
161+
... measurement_type='Precip', year='2015', path='somepath'
162+
... )
150163
151164
"""
152-
url = '{}/{}/NTN/grids/{}/'.format(NADP_URL, NADP_MAP_EXT, year)
165+
url = f'{NADP_URL}/{NADP_MAP_EXT}/NTN/grids/{year}/'
153166

154-
filename = '{}_{}.zip'.format(measurement_type, year)
167+
filename = f'{measurement_type}_{year}.zip'
155168

156169
if measurement:
157-
filename = '{}_{}'.format(measurement, filename)
170+
filename = f'{measurement}_{filename}'
158171

159172
z = get_zip(url, filename)
160173

161174
if path:
162175
z.extractall(path)
163176

164-
return '{}{}{}'.format(path, os.sep, basename(filename))
177+
return f'{path}{os.sep}{basename(filename)}'
165178

166179

167180
def get_zip(url, filename):

0 commit comments

Comments
 (0)