From a7b412807e344c8fc2c6ee5e1c6f983c9b7700ad Mon Sep 17 00:00:00 2001 From: Adrien Berchet Date: Thu, 23 Apr 2020 18:25:17 +0200 Subject: [PATCH] Fix coverage and simplify the code --- lib/cartopy/io/img_tiles.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/lib/cartopy/io/img_tiles.py b/lib/cartopy/io/img_tiles.py index c183e0266..ec83fbbaf 100644 --- a/lib/cartopy/io/img_tiles.py +++ b/lib/cartopy/io/img_tiles.py @@ -22,6 +22,7 @@ import io import json import os +from uuid import uuid4 import warnings from PIL import Image @@ -52,12 +53,7 @@ def __init__(self, desired_tile_form='RGB', # a change of user_agent may fix the issue. self.cache_path = cache_path self.cache = {} - if self.cache_path is not None: - try: - os.makedirs(self.cache_path) - except OSError: - pass - self._load_cache() + self._load_cache() def image_for_domain(self, target_domain, target_z): tiles = [] @@ -88,8 +84,7 @@ def fetch_tile(tile): img, extent, origin = _merge_tiles(tiles) - if self.cache_path is not None: - self._save_cache() + self._save_cache() return img, extent, origin @@ -107,7 +102,8 @@ def _fetch_cache(self, files): def _save_cache(self): """Save the cache""" if self.cache_path is not None and self.cache: - from uuid import uuid4 + if not os.path.exists(self.cache_path): + os.makedirs(self.cache_path) files = self._cache_files() already_cached = self._fetch_cache(files)