Skip to content

Comments

Update for Extensions Platform#7

Open
BradyAJohnston wants to merge 8 commits intomainfrom
extensions-platform
Open

Update for Extensions Platform#7
BradyAJohnston wants to merge 8 commits intomainfrom
extensions-platform

Conversation

@BradyAJohnston
Copy link
Owner

@BradyAJohnston BradyAJohnston commented Sep 24, 2024

Update for use with the new Extensions system / plaform, to potentially allow users to install from within Blender.

Currently rough / a work in progress, and currently doesn't work on Windows as some .whl resolving is failing.

Installing development version of add-on

To install development build, use the Blender VSCode extension, open VSCode in the repo folder. Before building and launching Blender, get Blender to run the .build script:

/Applications/Blender.app/Contents/MacOS/Blender -b -P build.py

This will download the required .whl files in the notebookconnector/wheels and also setup the notebookconnector/blender_manifest.py.

After running that build script you can do the Blender: Build and Run on your installation of Blender and it should install and appear in the list of add-ons. Once there you can use the Append / Remove buttons to register Blender as a usable kernel for Jupyter.

Importing Molecular Nodes

Importing installed add-ons import python scripts has changed slightly. Add-ons need to be installed from the specific repo that they have been installed from. If you have download / installed MN from within Blender, it is in the user_default repo so you can import it like this:

from bl_ext.user_default import molecularnodes as mn

# then we can use it like normal
mn.entities.fetch('1cd3', build_assembly = True, style='ribbon')
CleanShot.2024-09-24.at.18.50.24.mp4

@BradyAJohnston
Copy link
Owner Author

Now I've spent some time going through everything, we could probably actually drop the need for any .whl files to be shipped at all. We are only using it to get the default --data-dir for where to store the kernel registrations. This can probably just be guessed and then also expose as a user preference to be changed.

@kolibril13
Copy link

just tried this:
image
and got this 🎉

image image

@BradyAJohnston
Copy link
Owner Author

This is good to see!

@BradyAJohnston
Copy link
Owner Author

Another thought: we could add the bl_ext.user_default and other repos to PATH so that packages could be imported directly when working inside of a jupyter notebook

@kolibril13
Copy link

Another thought: we could add the bl_ext.user_default and other repos to PATH so that packages could be imported directly when working inside of a jupyter notebook

isn't it already possible that all python packages can be imported directly inside of a jupyter notebook?
Or do you mean other blender extensions can be imported to the notebook?

The pull request looks good to me!

One small remark for copying files: Pathlib has a write_bytes function, so shutil.copyfile could maybe be avoided.
But I'm not sure how the situation is with permissions in that case.

    # copy python files
    kernel_py_dst = kernel_install_path.joinpath(kernel_py_path.name)
    kernel_launcher_py_dst = kernel_install_path.joinpath(kernel_launcher_py_path.name)

    shutil.copyfile(kernel_py_path, kernel_py_dst)
    shutil.copyfile(kernel_launcher_py_path, kernel_launcher_py_dst)
    kernel_launcher_py_dst.chmod(0o755)
from pathlib import Path

# Define source paths
source_path = Path(__file__).resolve().parent / "my_example_path"
src0 = source_path / "config.yaml"
src1 = source_path / "launcher.py"

# Define destination path
dest_path = Path.cwd()  # Use current working directory as the destination

# Destination paths
dest0 = dest_path / "config.yaml"
dest1 = dest_path / "launcher.py"

# Copy files to destination
dest0.write_bytes(src0.read_bytes())
dest1.write_bytes(src1.read_bytes())

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.

2 participants