Skip to content

Conversation

ujhelyiz
Copy link
Contributor

@ujhelyiz ujhelyiz commented May 15, 2025

This PR introduces an alternative way to register new magic commands to the Jupyter kernel: one based on the Java ServiceLoader mechanism. This extension allows external users to define and register additional commands that can reuse the state of the Jupyter kernel without needing to recompile the existing codebase. New commands are to implement the IMagicCommandRegistrator interface and register the implementation to the ServiceLoader. After that, the JAR file(s) containing the extension(s) are to put next to the kernel binary in the installation.

To handle these additional JAR files, the kernel descriptor file is updated not to rely on a specific JAR file but load all JAR files from the folder. This resulted in a simplification of the Jupyter kernel POM file, as it is no longer required to add the final JAR file name in the kernel descriptor.

This commit adds a service registration based mechanism that can be used
to register additional magic commands to the system.

Furthermore, to allow these commands to add new items to the built-in
help system, and appropriate extension method was added to
SysMLInteractiveHelp
 - Added error handling for the command registrator interface
 - Added Javadoc to the registrator to clarify the expected contract of
implementors
@ujhelyiz ujhelyiz requested review from TheKorpos and seidewitz May 15, 2025 12:53
@seidewitz seidewitz self-assigned this May 15, 2025
@seidewitz seidewitz added this to the 2025-04 milestone May 15, 2025
@seidewitz
Copy link
Member

I have never seen the word "Registrator" used before, but I looked it up, and it turns out it's a real thing. However, wouldn't "Registry" be the more common term to use in an Eclipse context?

@ujhelyiz
Copy link
Contributor Author

I have never seen the word "Registrator" used before, but I looked it up, and it turns out it's a real thing. However, wouldn't "Registry" be the more common term to use in an Eclipse context?

I think the Registry name would be misleading, as the role of the Registry (one who stores the separate entries) is handled by (1) the class Magics and (2) the class SysMLInteractiveHelp - those are the ones storing the registered commands and help texts, respectively. My thinking was that the new registrator classes are responsible for calling the "register*"-like methods, like registerCellMagic or registerLineMagic or registerHelpStrings.

The alternative I was thinking about was a CommandProvider interface, where the specific classes implementing the LineMagics (and maybe one or two specific interface methods for the help texts) are returned. I decided against this approach as the Registrator approach does not specify that LineMagic commands are returned but could be CellMagic as well, and it also allows some custom logic to decide what commands to add. While there are no requirements for these capabilities right now, I was aiming for a more widely useful extension approach here.

@seidewitz seidewitz changed the base branch from ST6RI-836 to master May 22, 2025 13:51
@seidewitz
Copy link
Member

The alternative I was thinking about was a CommandProvider interface, where the specific classes implementing the LineMagics (and maybe one or two specific interface methods for the help texts) are returned. I decided against this approach as the Registrator approach does not specify that LineMagic commands are returned but could be CellMagic as well, and it also allows some custom logic to decide what commands to add. While there are no requirements for these capabilities right now, I was aiming for a more widely useful extension approach here.

OK, I see. The name "Registrator" does seem to make sense, as odd as it sounds!

Copy link
Member

@seidewitz seidewitz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The org.omg.sysml.jupyter.kernel/installKernel.sh script no longer works. It ends with

--- Step 4: Installing kernel ---
python: can't open file '/Users/seidewitz/Documents/Work/git/SysML-v2-Pilot-Implementation/org.omg.sysml.jupyter.kernel/./target/kernel/install.py': [Errno 2] No such file or directory

The templating-maven-plugin, used to copy the resources into the target
directory `kernel`, was causing the kernel zips recursively containing
earlier builds as well, causing its size to balloon (mostly because
maven considered a target folder as a source folder). However, simply
removing broke clean builds, as the installer and other metadata were
missing from the output folder.

This commit uses the maven-resources-plugin to copy the required files
to the installer, thus avoiding the original issue.
@ujhelyiz
Copy link
Contributor Author

Thanks for pointing out this error; it was caused by me not running a clean build on my computer, so the output files were out as expected. I have pushed a fix.

@seidewitz seidewitz merged commit cf9b05c into master May 22, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants