Skip to content

Commit

Permalink
Convert function to constant
Browse files Browse the repository at this point in the history
Avoid the disk access each time when this is checked. If users install
Terminus on the fly, they could restart ST to enable the commands.
  • Loading branch information
jwortmann committed Apr 22, 2024
1 parent 79323c9 commit 79936bc
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,8 @@ class TestItemStatus(StrEnum):


# Workaround until Terminus uses the Python 3.8 API environment
def is_terminus_installed() -> bool:
return os.path.isfile(os.path.join(INSTALLED_PACKAGES_PATH, 'Terminus.sublime-package')) or \
os.path.isdir(os.path.join(PACKAGES_PATH, 'Terminus'))
IS_TERMINUS_INSTALLED = os.path.isfile(os.path.join(INSTALLED_PACKAGES_PATH, 'Terminus.sublime-package')) or \
os.path.isdir(os.path.join(PACKAGES_PATH, 'Terminus'))


def find_output_view(window: sublime.Window, name: str) -> sublime.View | None:
Expand Down Expand Up @@ -828,7 +827,7 @@ class JuliaOpenReplCommand(sublime_plugin.WindowCommand):
def is_enabled(self) -> bool:
# return importlib.find_loader("Terminus") is not None
# Workaround until Terminus uses the Python 3.8 API environment
return is_terminus_installed()
return IS_TERMINUS_INSTALLED

def run(self, panel: bool = True) -> None:
repl_view = find_output_view(self.window, JULIA_REPL_NAME)
Expand Down Expand Up @@ -878,7 +877,7 @@ def is_enabled(self, event: dict | None = None, point: int | None = None) -> boo
# Terminus package must be installed
# if not importlib.find_loader("Terminus"):
# Workaround until Terminus uses the Python 3.8 API environment
if not is_terminus_installed():
if not IS_TERMINUS_INSTALLED:
return False
# cursor must not be at end of file
if self.view.sel()[0].b == self.view.size():
Expand Down Expand Up @@ -931,7 +930,7 @@ def is_enabled(self) -> bool:
# Terminus package must be installed
# if not importlib.find_loader("Terminus"):
# Workaround until Terminus uses the Python 3.8 API environment
if not is_terminus_installed():
if not IS_TERMINUS_INSTALLED:
return False
# cursor must not be at end of file
if self.view.sel()[0].b == self.view.size():
Expand Down

0 comments on commit 79936bc

Please sign in to comment.