Skip to content

Commit 3ebce51

Browse files
Clara Brasseurceb8
authored andcommitted
making sure cache directory exists
1 parent e3be27a commit 3ebce51

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

astroquery/query.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import textwrap
1616

1717
from datetime import datetime, timedelta
18+
from pathlib import Path
1819

1920
from astropy.config import paths
2021
from astroquery import log
@@ -31,10 +32,14 @@
3132

3233
def to_cache(response, cache_file):
3334
log.debug("Caching data to {0}".format(cache_file))
35+
3436
response = copy.deepcopy(response)
3537
if hasattr(response, 'request'):
3638
for key in tuple(response.request.hooks.keys()):
3739
del response.request.hooks[key]
40+
41+
chache_dir, _ = os.path.split(cache_file)
42+
Path(chache_dir).mkdir(parents=True, exist_ok=True)
3843
with open(cache_file, "wb") as f:
3944
pickle.dump(response, f)
4045

0 commit comments

Comments
 (0)