Skip to content

Commit

Permalink
Automatically create the directory path for a JSONTokenStorage (#998)
Browse files Browse the repository at this point in the history
  • Loading branch information
derek-globus authored Jul 9, 2024
1 parent d28f1e4 commit 26bb70a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

Fixed
~~~~~

- When a JSONTokenStorage is used, the containing directory will be automatically be
created if it doesn't exist instead of erroring (on Mac).
8 changes: 8 additions & 0 deletions src/globus_sdk/experimental/tokenstorage/json.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import json
import os
import pathlib
import typing as t

Expand Down Expand Up @@ -40,8 +41,15 @@ def __init__(self, filename: pathlib.Path | str, *, namespace: str = "DEFAULT"):
:param namespace: A user-supplied namespace for partitioning token data
"""
self.filename = str(filename)
self._ensure_containing_dir_exists()
super().__init__(namespace=namespace)

def _ensure_containing_dir_exists(self) -> None:
"""
Ensure that the directory containing the given filename exists.
"""
os.makedirs(os.path.dirname(self.filename), exist_ok=True)

def _invalid(self, msg: str) -> t.NoReturn:
raise ValueError(
f"{msg} while loading from '{self.filename}' for JSON Token Storage"
Expand Down

0 comments on commit 26bb70a

Please sign in to comment.