-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Automatically create the directory path for a JSONTokenStorage #998
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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). | ||
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 | ||
|
||
|
@@ -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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we're adding this, shouldn't we do it on the parent class, not here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, that's a fair question. Would you like to open that PR or me? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, I'll work that up! (Also, no worries about merge/review order. I noticed it, and we'll sort out now. 😄 ) |
||
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" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since it's not mac-specific, I don't think we should note the platform. Since I was suggesting an edit, I also went ahead and restored the pr link text from the template (
:pr:`998`
also works).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if it's mac exclusive or not. I only know it doesn't work on mac.