Skip to content

Commit

Permalink
apply new version of black
Browse files Browse the repository at this point in the history
  • Loading branch information
b8raoult committed Mar 14, 2023
1 parent ec7b643 commit cb3d1c5
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 20 deletions.
2 changes: 1 addition & 1 deletion ecmwf/opendata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@

from .client import Client

__version__ = "0.1.2"
__version__ = "0.1.3"

__all__ = ["Client"]
29 changes: 20 additions & 9 deletions ecmwf/opendata/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@


def warning_once(*args, did_you_mean=None):

if repr(args) in ONCE:
return

Expand Down Expand Up @@ -109,21 +108,22 @@ def __init__(
preserve_request_order=False,
infer_stream_keyword=True,
debug=False,
verify=True,
):
self._url = None
self.source = source
self.beta = beta
self.preserve_request_order = preserve_request_order
self.infer_stream_keyword = infer_stream_keyword
self.session = requests.Session()
self.verify = verify

if debug:
logging.basicConfig(level=logging.DEBUG)

@property
def url(self):

if self._url is None:

if self.source.startswith("http://") or self.source.startswith("https://"):
self._url = self.source
else:
Expand All @@ -141,12 +141,22 @@ def url(self):

def retrieve(self, request=None, target=None, **kwargs):
result = self._get_urls(request, target=target, use_index=True, **kwargs)
result.size = download(result.urls, target=result.target)
result.size = download(
result.urls,
target=result.target,
verify=self.verify,
session=self.session,
)
return result

def download(self, request=None, target=None, **kwargs):
result = self._get_urls(request, target=target, use_index=False, **kwargs)
result.size = download(result.urls, target=result.target)
result.size = download(
result.urls,
target=result.target,
verify=self.verify,
session=self.session,
)
return result

def latest(self, request=None, **kwargs):
Expand All @@ -171,15 +181,17 @@ def latest(self, request=None, **kwargs):
date=date,
**params,
)
codes = [robust(requests.head)(url).status_code for url in result.urls]
codes = [
robust(self.session.head)(url, verify=self.verify).status_code
for url in result.urls
]
if len(codes) > 0 and all(c == 200 for c in codes):
return date
date -= delta

raise ValueError("Cannot establish latest date for %r" % (result.for_urls,))

def _get_urls(self, request=None, use_index=None, target=None, **kwargs):

assert use_index in (True, False)
if request is None:
params = dict(**kwargs)
Expand Down Expand Up @@ -230,7 +242,6 @@ def _get_urls(self, request=None, use_index=None, target=None, **kwargs):
)

def get_parts(self, data_urls, for_index):

count = len(for_index)
result = []
line = None
Expand All @@ -240,7 +251,7 @@ def get_parts(self, data_urls, for_index):
for url in data_urls:
base, _ = os.path.splitext(url)
index_url = f"{base}.index"
r = robust(requests.get)(index_url)
r = robust(self.session.get)(index_url, verify=self.verify)
r.raise_for_status()

parts = []
Expand Down
2 changes: 0 additions & 2 deletions ecmwf/opendata/date.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ def canonical_time(time):


def full_date(date, time=None):

if isinstance(date, datetime.date) and not isinstance(date, datetime.datetime):
date = datetime.datetime(date.year, date.month, date.day)

Expand All @@ -43,7 +42,6 @@ def full_date(date, time=None):
date = datetime.datetime(date // 10000, date % 10000 // 100, date % 100)

if isinstance(date, str):

try:
return full_date(int(date), time)
except ValueError:
Expand Down
1 change: 0 additions & 1 deletion ecmwf/opendata/grib.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@


def grib_index(path):

index = []
with open(path, "rb") as f:
while True:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def read(fname):
url="https://github.com/ecmwf/ecmwf-opendata",
packages=setuptools.find_namespace_packages(include=["ecmwf.*"]),
include_package_data=True,
install_requires=["multiurl>=0.2.0"],
install_requires=["multiurl>=0.2.1"],
zip_safe=True,
keywords="tool",
classifiers=[
Expand Down
1 change: 0 additions & 1 deletion tests/test_date.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

@freeze_time("2022-01-21T13:21:34Z")
def test_date_1():

assert full_date("20010101") == datetime.datetime(2001, 1, 1)
assert full_date(20010101) == datetime.datetime(2001, 1, 1)
assert full_date("2001-01-01") == datetime.datetime(2001, 1, 1)
Expand Down
1 change: 0 additions & 1 deletion tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@


def example_list():

examples = []
code = []
python = False
Expand Down
1 change: 0 additions & 1 deletion tests/test_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ def patch_stream(stream, time, type):


def test_stream():

assert patch_stream("oper", 0, "fc") == "oper"
assert patch_stream("oper", 6, "fc") == "scda"
assert patch_stream("oper", 12, "fc") == "oper"
Expand Down
1 change: 0 additions & 1 deletion tools/check-index.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@
("stream", rstream, stream),
("type", rtype, type),
):

if b != c:
print("Mismatch: %r %r %r" % (a, b, c))
# assert False
2 changes: 0 additions & 2 deletions tools/param-units.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@

with open("index.txt") as f:
for j, url in enumerate(f):

url = url.rstrip()

if (
Expand All @@ -67,7 +66,6 @@
lines.append(line)

for i, line in enumerate(lines):

key = tuple(line.get(x) for x in ("type", "stream", "levtype", "param"))
if key in seen:
continue
Expand Down

0 comments on commit cb3d1c5

Please sign in to comment.