-
Notifications
You must be signed in to change notification settings - Fork 49
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
Actions - Availability Helpers #1357
Comments
For posterity this was the (bad) design for the def filetype_availability(filetypes: list[str]) -> Callable[[FileTab | Path], bool]:
def _filetype_availability(filetypes: list[str], context: FileTab | Path) -> bool:
if isinstance(context, FileTab):
tab = context
if tab.settings.get("filetype_name", object) in filetypes:
return True
return False
if isinstance(context, Path):
path = context
if not path.exists():
raise RuntimeError(f"{path} does not exist.")
if path.is_dir():
raise RuntimeError(
f"{path} is a directory - an action consumer registered this action incorrectly"
)
if not path.is_file():
raise RuntimeError(f"{path} is not a file")
# return True if get_filetype_from_path(path) in filetypes else False
raise NotImplementedError # TODO: there is a way to do this already right?
raise RuntimeError("wrong context passed")
return partial(_filetype_availability, filetypes) |
benjamin-kirkbride
added a commit
to benjamin-kirkbride/porcupine
that referenced
this issue
Jul 11, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Subtask of #1342
I wanted to document the different ideas that have been had for availability helpers (formerly known as availability callbacks).
Discussion here about how we came to the current design: #1349 (comment)
Discussion here about how we need to be sure to document well the different patterns and helpers: #1349 (comment)
List of helpers to be made/ironed out:
The text was updated successfully, but these errors were encountered: