From 21ba7fd1a1fcaac9781bf180752bb29706e953e3 Mon Sep 17 00:00:00 2001 From: deathaxe Date: Wed, 31 Jul 2024 18:00:46 +0200 Subject: [PATCH 01/11] Opt-in to python 3.8 This commit... 1. opts-in Helium to python 3.8 2. adjusts dependencies for python 3.8 plugin_host - "enum" is now built-in and no longer needed - "pyzmq" 26 however requires "tornado" library --- .python-version | 2 +- dependencies.json | 31 +++++++++++++++++++++++++++---- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/.python-version b/.python-version index eb39e53..cc1923a 100644 --- a/.python-version +++ b/.python-version @@ -1 +1 @@ -3.3 +3.8 diff --git a/dependencies.json b/dependencies.json index 642507d..77567f8 100644 --- a/dependencies.json +++ b/dependencies.json @@ -1,30 +1,53 @@ { "windows": { - "*": [ + "<4000": [ "dateutil", "enum", "python-six", - "pyzmq" + "pyzmq", + "tornado" + ], + ">=4000": [ + "dateutil", + "python-six", + "pyzmq", + "tornado" ] }, "osx": { - "*": [ + "<4000": [ "dateutil", "enum", "pexpect", "ptyprocess", "python-six", "pyzmq" + ], + ">=4000": [ + "dateutil", + "pexpect", + "ptyprocess", + "python-six", + "pyzmq", + "tornado" ] }, "linux": { - "*": [ + "<4000": [ "dateutil", "enum", "pexpect", "ptyprocess", "python-six", "pyzmq" + ], + ">=4000": [ + "dateutil", + "pexpect", + "ptyprocess", + "python-six", + "pyzmq", + "tornado" ] } } \ No newline at end of file From 6996bf32660c65f1dbdd9131bd5b18cb2aa768bd Mon Sep 17 00:00:00 2001 From: deathaxe Date: Wed, 31 Jul 2024 18:07:45 +0200 Subject: [PATCH 02/11] Remove tornado for ST3 --- dependencies.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/dependencies.json b/dependencies.json index 77567f8..da2ac48 100644 --- a/dependencies.json +++ b/dependencies.json @@ -4,8 +4,7 @@ "dateutil", "enum", "python-six", - "pyzmq", - "tornado" + "pyzmq" ], ">=4000": [ "dateutil", From 804ee5523c2b82dad0f984a6c512985445a47ef8 Mon Sep 17 00:00:00 2001 From: deathaxe Date: Wed, 31 Jul 2024 18:10:57 +0200 Subject: [PATCH 03/11] Fix syntax warnings --- lib/client/jupyter_client/manager.py | 2 +- lib/client/traitlets/config/loader.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/client/jupyter_client/manager.py b/lib/client/jupyter_client/manager.py index 3df36fd..f3888f0 100644 --- a/lib/client/jupyter_client/manager.py +++ b/lib/client/jupyter_client/manager.py @@ -78,7 +78,7 @@ def _kernel_name_changed(self, name, old, new): @property def kernel_spec(self): - if self._kernel_spec is None and self.kernel_name is not '': + if self._kernel_spec is None and self.kernel_name != '': self._kernel_spec = self.kernel_spec_manager.get_kernel_spec(self.kernel_name) return self._kernel_spec diff --git a/lib/client/traitlets/config/loader.py b/lib/client/traitlets/config/loader.py index 803b362..ae7e6c9 100644 --- a/lib/client/traitlets/config/loader.py +++ b/lib/client/traitlets/config/loader.py @@ -792,7 +792,7 @@ def _add_arguments(self, aliases=None, flags=None): nargs = '?' else: nargs = None - if len(key) is 1: + if len(key) == 1: paa('-'+key, '--'+key, type=text_type, dest=value, nargs=nargs) else: paa('--'+key, type=text_type, dest=value, nargs=nargs) @@ -801,7 +801,7 @@ def _add_arguments(self, aliases=None, flags=None): # self.alias_flags[self.aliases[key]] = value continue - if len(key) is 1: + if len(key) == 1: paa('-'+key, '--'+key, action='append_const', dest='_flags', const=value) else: paa('--'+key, action='append_const', dest='_flags', const=value) From f92fb4644c9da44168bea2bd0b55f68fc8f6bcb4 Mon Sep 17 00:00:00 2001 From: deathaxe Date: Wed, 31 Jul 2024 18:16:08 +0200 Subject: [PATCH 04/11] Fix regexp pattern --- lib/client/traitlets/config/loader.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/client/traitlets/config/loader.py b/lib/client/traitlets/config/loader.py index ae7e6c9..7395b77 100644 --- a/lib/client/traitlets/config/loader.py +++ b/lib/client/traitlets/config/loader.py @@ -542,7 +542,7 @@ def _load_flag(self, cfg): # rejects: --anything=anything # --two.word -flag_pattern = re.compile(r'\-\-?\w+[\-\w]*$') +flag_pattern = re.compile(r'\-\-?\w[\-\w]*$') class KeyValueConfigLoader(CommandLineConfigLoader): """A config loader that loads key value pairs from the command line. From b22d695cba5ee3ff370a5c269f22903cf7181be9 Mon Sep 17 00:00:00 2001 From: deathaxe Date: Wed, 31 Jul 2024 18:20:31 +0200 Subject: [PATCH 05/11] Fix unused variable --- lib/client/traitlets/config/loader.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/client/traitlets/config/loader.py b/lib/client/traitlets/config/loader.py index 7395b77..c9ef77e 100644 --- a/lib/client/traitlets/config/loader.py +++ b/lib/client/traitlets/config/loader.py @@ -669,7 +669,7 @@ def load_config(self, argv=None, aliases=None, flags=None): elif flag_pattern.match(raw): if item in flags: - cfg,help = flags[item] + cfg,_ = flags[item] self._load_flag(cfg) else: raise ArgumentError("Unrecognized flag: '%s'"%raw) From cc2b074fca17efc65be400ba167c627b85efa462 Mon Sep 17 00:00:00 2001 From: deathaxe Date: Wed, 31 Jul 2024 18:21:55 +0200 Subject: [PATCH 06/11] Tweak README Remove ST version number. --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index efb8b58..64b5660 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ -Helium package for Sublime Text 3 +Helium package for Sublime Text === -Helium is a package for Sublime Text 3, which provides in-editor code execution and autocomplete in interaction with Jupyter kernels. -The concept of an editor extension communicating Jupyter kernels is inspired by @nteract's splendid Atom package [Hydrogen](https://github.com/nteract/Hydrogen). I want something like it in Sublime Text 3, too. +Helium is a package for Sublime Text, which provides in-editor code execution and autocomplete in interaction with Jupyter kernels. +The concept of an editor extension communicating Jupyter kernels is inspired by @nteract's splendid Atom package [Hydrogen](https://github.com/nteract/Hydrogen). I want something like it in Sublime Text, too. Any feedback is highly welcome. I hope this package will help your life with ST3! From c6bde04ec4e5df60d15cf90c83415960faeb72ad Mon Sep 17 00:00:00 2001 From: Yaroslav Yashin Date: Fri, 30 Aug 2024 18:23:49 +0200 Subject: [PATCH 07/11] gutter disabled (hardcode) --- lib/kernel.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/kernel.py b/lib/kernel.py index d44b394..7432842 100644 --- a/lib/kernel.py +++ b/lib/kernel.py @@ -350,7 +350,8 @@ def activate_view(self): current_view = sublime.active_window().active_view() sublime.active_window().focus_view(view) view.set_scratch(True) # avoids prompting to save - view.settings().set("word_wrap", "false") + view.settings().set("gutter", False) + view.settings().set("line_numbers", False) sublime.active_window().focus_view(current_view) def _output_input_code(self, code, execution_count): @@ -578,6 +579,8 @@ def get_view(self): view = window.new_file() view.set_name(view_name) view.settings().set("syntax", "Packages/Helium/Helium.sublime-syntax") + view.settings().set("gutter", False) + view.settings().set("line_numbers", False) num_group = window.num_groups() if num_group != 1: if active_group + 1 < num_group: From de05e6795037b1decef29903f14c9ab8e41f68ff Mon Sep 17 00:00:00 2001 From: Yaroslav Yashin Date: Fri, 30 Aug 2024 18:49:25 +0200 Subject: [PATCH 08/11] Annoying every window helium kernel popup disabled kernels now seems to be captured within a single window (they were global previously) --- helium.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/helium.py b/helium.py index 1c6ee39..676e5b4 100644 --- a/helium.py +++ b/helium.py @@ -842,15 +842,14 @@ def cb(): sublime.set_timeout_async(cb, 0) def _get_parent_view(self) -> sublime.View: - for window in sublime.windows(): - for view in window.views(): - try: - kernel = ViewManager.get_kernel_for_view(view.buffer_id()) - except KeyError: - continue - - if kernel.get_view() == self.view: - return view + for view in sublime.active_window().views(): + try: + kernel = ViewManager.get_kernel_for_view(view.buffer_id()) + except KeyError: + continue + + if kernel.get_view() == self.view: + return view return None From af2f6a264bd2df2c678ac6cc952a85e67fd37210 Mon Sep 17 00:00:00 2001 From: Yaroslav Yashin Date: Fri, 30 Aug 2024 18:50:30 +0200 Subject: [PATCH 09/11] Output view name shortened --- lib/kernel.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/kernel.py b/lib/kernel.py index 7432842..1d8e3cb 100644 --- a/lib/kernel.py +++ b/lib/kernel.py @@ -320,20 +320,21 @@ def del_connection_name(self): @property def view_name(self): """Return name of output view.""" - return "*Helium Output* {repr}".format(repr=self.repr) + return "Helium: {repr}".format(repr=self.repr) @property def repr(self): """Return string representation of the connection.""" + shortened_kernel_id = str(self.kernel_id)[:6] if self.connection_name: return "{connection_name} ([{lang}] {kernel_id})".format( connection_name=self.connection_name, lang=self.lang, - kernel_id=self.kernel_id, + kernel_id=shortened_kernel_id, ) else: return "[{lang}] {kernel_id}".format( - lang=self.lang, kernel_id=self.kernel_id + lang=self.lang, kernel_id=shortened_kernel_id ) @property From 28d89064c6414122b8a67a85d2e4abab38767c28 Mon Sep 17 00:00:00 2001 From: Yaroslav Yashin Date: Fri, 30 Aug 2024 19:12:08 +0200 Subject: [PATCH 10/11] `ShutdownKernel.is_enabled` and `ClearAllCells.is_enabled` logic unified. --- helium.py | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/helium.py b/helium.py index 676e5b4..24a65e6 100644 --- a/helium.py +++ b/helium.py @@ -327,6 +327,17 @@ def _start_kernel(window, view, continue_cb=lambda: None, *, logger=HELIUM_LOGGE continue_cb() +def get_parent_view(view) -> sublime.View: + # FIXME: This method pops up dead kernel view on a command palette call. + for view in sublime.active_window().views(): + try: + kernel = ViewManager.get_kernel_for_view(view.buffer_id()) + except KeyError: + continue + + if kernel.get_view() == view: + return view + return None class HeliumStartKernel(TextCommand): """Start a kernel and connect view to it.""" @@ -600,8 +611,8 @@ def is_enabled(self, *, logger=HELIUM_LOGGER): try: kernel = ViewManager.get_kernel_for_view(self.view.buffer_id()) except KeyError: - return False - return HeliumKernelManager.get_kernel(kernel.kernel_id).is_alive() + parent_view = get_parent_view(self.view) + return parent_view is not None def is_visible(self, *, logger=HELIUM_LOGGER): return self.is_enabled() @@ -680,7 +691,6 @@ def get_indent(view: sublime.View, row: int) -> str: line = get_line(view, row) return INDENT_PATTERN.match(line).group() - def get_block(view: sublime.View, s: sublime.Region) -> (str, sublime.Region): """Get the code block under the cursor. @@ -816,7 +826,7 @@ def is_enabled(self, *, logger=HELIUM_LOGGER): except KeyError: # if view doesn't have an attached kernel, check if view was created by # kernel - parent_view = self._get_parent_view() + parent_view = get_parent_view(self.view) return parent_view is not None def is_visible(self, *, logger=HELIUM_LOGGER): @@ -827,7 +837,7 @@ def run(self, edit, *, logger=HELIUM_LOGGER): try: kernel = ViewManager.get_kernel_for_view(self.view.buffer_id()) except KeyError: - view = self._get_parent_view() + view = get_parent_view(self.view) kernel = ViewManager.get_kernel_for_view(view.buffer_id()) def cb(): @@ -841,17 +851,6 @@ def cb(): # clear the old phantoms async sublime.set_timeout_async(cb, 0) - def _get_parent_view(self) -> sublime.View: - for view in sublime.active_window().views(): - try: - kernel = ViewManager.get_kernel_for_view(view.buffer_id()) - except KeyError: - continue - - if kernel.get_view() == self.view: - return view - return None - class StatusBar(object): """Status Bar with animation. From efd8dbbff107c9f5ae3c3169e92afdf3be619944 Mon Sep 17 00:00:00 2001 From: Yaroslav Yashin Date: Sat, 31 Aug 2024 13:54:30 +0200 Subject: [PATCH 11/11] Revert "`ShutdownKernel.is_enabled` and `ClearAllCells.is_enabled` logic unified." This reverts commit 28d89064c6414122b8a67a85d2e4abab38767c28. --- helium.py | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/helium.py b/helium.py index 24a65e6..676e5b4 100644 --- a/helium.py +++ b/helium.py @@ -327,17 +327,6 @@ def _start_kernel(window, view, continue_cb=lambda: None, *, logger=HELIUM_LOGGE continue_cb() -def get_parent_view(view) -> sublime.View: - # FIXME: This method pops up dead kernel view on a command palette call. - for view in sublime.active_window().views(): - try: - kernel = ViewManager.get_kernel_for_view(view.buffer_id()) - except KeyError: - continue - - if kernel.get_view() == view: - return view - return None class HeliumStartKernel(TextCommand): """Start a kernel and connect view to it.""" @@ -611,8 +600,8 @@ def is_enabled(self, *, logger=HELIUM_LOGGER): try: kernel = ViewManager.get_kernel_for_view(self.view.buffer_id()) except KeyError: - parent_view = get_parent_view(self.view) - return parent_view is not None + return False + return HeliumKernelManager.get_kernel(kernel.kernel_id).is_alive() def is_visible(self, *, logger=HELIUM_LOGGER): return self.is_enabled() @@ -691,6 +680,7 @@ def get_indent(view: sublime.View, row: int) -> str: line = get_line(view, row) return INDENT_PATTERN.match(line).group() + def get_block(view: sublime.View, s: sublime.Region) -> (str, sublime.Region): """Get the code block under the cursor. @@ -826,7 +816,7 @@ def is_enabled(self, *, logger=HELIUM_LOGGER): except KeyError: # if view doesn't have an attached kernel, check if view was created by # kernel - parent_view = get_parent_view(self.view) + parent_view = self._get_parent_view() return parent_view is not None def is_visible(self, *, logger=HELIUM_LOGGER): @@ -837,7 +827,7 @@ def run(self, edit, *, logger=HELIUM_LOGGER): try: kernel = ViewManager.get_kernel_for_view(self.view.buffer_id()) except KeyError: - view = get_parent_view(self.view) + view = self._get_parent_view() kernel = ViewManager.get_kernel_for_view(view.buffer_id()) def cb(): @@ -851,6 +841,17 @@ def cb(): # clear the old phantoms async sublime.set_timeout_async(cb, 0) + def _get_parent_view(self) -> sublime.View: + for view in sublime.active_window().views(): + try: + kernel = ViewManager.get_kernel_for_view(view.buffer_id()) + except KeyError: + continue + + if kernel.get_view() == self.view: + return view + return None + class StatusBar(object): """Status Bar with animation.