Best, Nice or Comfortable Practices to setup a development environment for BonsaiBIM

vdlvdl
edited March 13 in General

..

Comments

  • Dear all,
    I am fairly new to doing some small PRs in Bonsai. I am not a professional programmer so I would very much appreciate your feedback on both the setup I have and what you guys are using to develop.
    In my case I have followed the Bonsai documentation:
    https://docs.bonsaibim.org/guides/development/index.html
    Currently I am running AlmaLinux release 9.5 (Teal Serval) with two users and I switch between them via the OS.
    One "production" user with stable Ifcfiles/bonsai, where I keep the files from the contracted Architect
    One "development user" where I have installed the Live development environment with dev_environment.sh.
    I use VSCode with these extensions:

    • "Github Pull Requests", "Github Repositories", "Remote Repositories", (Working with GitHub in VS Code)
    • "Pylance", "Python", "Python Debugger", "GitHub Copilot" & "GitHub Copilot Chat"

    I had to add echo "*.so" >> "${PWD}/.gitignore" to the dev_environment.sh or github would complain about large files for a .so which is copied to the cloned repository.

    In Blender I have "Screencast Keys" extension enabled (an of course the daily one for Bonsai)
    I use LibreOffice to handle csv files imported/exported from Bonsai
    I use "Flameshot" to take screenshots and "Blue Recorder" for screen recording (I have seen that some of you have beautiful recordings that show the mouse clicks. Are those available in Linux?)
    The process I follow is:

    • I have a fork from https://github.com/IfcOpenShell/IfcOpenShell in my personal Github https://github.com/falken10vdl/IfcOpenShell
    • I create a folder in my home folder: bonsaiDevel
    • I store there the dev_environment.sh with the appropriate PATH and the .gitignore
    • In VScode I "Clone Repository" from my fork
    • I run dev_environment.sh which changes links so python changes in folders below "bonsaiDevel" are taken in the blender instance once reloaded
    • I create a branch in vscode
    • I commit / push and PR to my personal Github (some files due to dev_environment.sh are pushed)
    • I start to hack in the bonsaiDevel files
    • Whenever satisifed I commit/push to my Personal Gihub and eventually PR to https://github.com/IfcOpenShell/IfcOpenShell

    What tools do you use? Do you follow a similar procedure? I find that the "reloading" process to see the changes in effect in blender is probably the bottleneck. Do you have some automation about it?
    Thanks!

    Massimotim
  • I’m a newbie but I had worked out the same process you list above. It would be great if an experienced developer could comment on it and then add this to: https://docs.bonsaibim.org/guides/development/index.html
    I use GitKraken for interacting with git repositories and multiple different forks. Not necessarily a recommendation, it’s just what I use.

  • I find that the "reloading" process to see the changes in effect in blender is probably the bottleneck.

    At the bottom of this section, there is a tip about this. Did you check the VSCode extension?

    A few random tips:

    • Keep learning git stuff. You never know when they are going to be useful.
    • Keep learning about your code editor. Things like how to edit and find things faster are very useful in the long run.
    • With https://github.com/Victor-IX/Blender-Launcher-V2 you can easily manage multiple Blender installations. I keep one tied to the dev environment and another with Bonsai installed as extension.
    theoryshawtimMassimocarlopavLarissaBrosler
  • @bruno_perdigao Thanks a lot! I am going to check the VSCode extension already. Thanks!

  • edited March 15

    @falken10vdl well, this is an interesting topic... many times i think that i could save much time with the right tool.
    I'm not a professional developer, but i studied a bit of coding during the university and, most important, i like coding! :-)
    I contributed i bit to Bonsai code, this is my setup:

    • OS: Linux Debian
    • editor: gvim (i know, i'm weird)
    • i use git from command line, so the workflow is fork, fetch, pull, new branch, commit push, make a PR. The command line is not so difficult after all.

    What i struggle with and what i feel that i'm unefficient:

    • every time a make a change in the code, i have to close blender and restart...or i have to print a particular variable and rerun blender...so much time lost i guess...
    • i have to jump from one file to another and every time i have to search where is the right file

    My advices, on the other hand, are the following:

    • structure the code into core, tool, UI and data...there was a bug about this and about the refactoring, i think this should be a good practice
    • create tests (tool and feature) and run it after a change because it's not unusual to solve a problem in a way that it recreates an old bug...tests should prevent this

    So, i'm only a coding nerd but these a my two cents :-)

    theoryshawfalken10vdl
  • @Massimo said:
    What i struggle with and what i feel that i'm unefficient:

    • every time a make a change in the code, i have to close blender and restart...or i have to print a particular variable and rerun blender...so much time lost i guess...
    • i have to jump from one file to another and every time i have to search where is the right file

    I strongly recommend the document that @theoryshaw linked to... because I wrote it ;-) Here's a prettier link: https://docs.bonsaibim.org/guides/development/debugging.html
    Now you can set breakpoints, and step line by line through the running code, watching how variables are filled or calculated. You can examine the global and local scope variables for each nested function/method. That is already a massive efficiency gain, over poke, print, reload, repeat.
    It doesn't prevent having to restart Blender, but it makes it quick to do so, because you run Blender from the VSCode/Codium IDE with a single command. Alternatively you can read this link https://community.osarch.org/discussion/comment/22852 and see if that works for you. I never bothered with the reloading.

    Massimofalken10vdlMoult
  • @sjb007 thanks for the hint, i have to try!

  • @sjb007 said:

    @Massimo said:
    What i struggle with and what i feel that i'm unefficient:

    • every time a make a change in the code, i have to close blender and restart...or i have to print a particular variable and rerun blender...so much time lost i guess...
    • i have to jump from one file to another and every time i have to search where is the right file

    I strongly recommend the document that @theoryshaw linked to... because I wrote it ;-) Here's a prettier link: https://docs.bonsaibim.org/guides/development/debugging.html
    Now you can set breakpoints, and step line by line through the running code, watching how variables are filled or calculated. You can examine the global and local scope variables for each nested function/method. That is already a massive efficiency gain, over poke, print, reload, repeat.
    It doesn't prevent having to restart Blender, but it makes it quick to do so, because you run Blender from the VSCode/Codium IDE with a single command. Alternatively you can read this link https://community.osarch.org/discussion/comment/22852 and see if that works for you. I never bothered with the reloading.

    @sjb007 Thanks a lot for the doc! I am trying to set it up and I can get the breakpoints to work as follows:

    1. git clone to my DEVELOPMENT FOLDER: /home/falken10/bonsaiDevel this folder has:
    • dev_environment.sh (i attach a copy. I updated it a bit to add .gitignore for *.so)
    • IfcOpenShell -> Here is were all the clone stuff donwloaded from GitHub is
    1. dev_environment.sh establishes the following:
    • PWD: /home/falken10/bonsaiDevel/IfcOpenShell
    • REPO PATH (...../IfcOpenshell): /home/falken10/bonsaiDevel/IfcOpenShell
    • BLENDER PATH: /home/falken10/.config/blender/4.3
    • PACKAGE PATH (...../etensions/.local/lib/python3.11/site-packages): /home/falken10/.config/blender/4.3/extensions/.local/lib/python3.11/site-packages
    • BONSAI PATH (...../extensions/raw_githubusercontent_com/bonsai): /home/falken10/.config/blender/4.3/extensions/raw_githubusercontent_com/bonsai
    1. So after running dev_environment.sh there are links in the installed repo path that now point to DEVELOPMENT FOLDER:
    • ls -l /home/falken10/.config/blender/4.3/extensions/raw_githubusercontent_com/bonsai

      • -rw-r--r--. 1 falken10 falken10 6337 Mar 14 18:25 blender_manifest.toml
      • drwxr-xr-x. 2 falken10 falken10 6 Mar 14 21:58 config
      • drwxr-xr-x. 5 falken10 falken10 60 Mar 14 21:58 extensions
      • lrwxrwxrwx. 1 falken10 falken10 69 Mar 14 19:11 init.py -> /home/falken10/bonsaiDevel/IfcOpenShell/src/bonsai/bonsai/init.py
      • drwxr-xr-x. 2 falken10 falken10 38 Mar 14 18:26 pycache
      • drwxr-xr-x. 4 falken10 falken10 35 Mar 14 21:58 scripts
      • -rw-r--r--. 1 falken10 falken10 222265 Mar 14 18:25 translations.py
      • drwxr-xr-x. 2 falken10 falken10 8192 Mar 14 18:25 wheels
    • And similarly /home/falken10/.config/blender/4.3/extensions/.local/lib/python3.11/site-packages

      • lrwxrwxrwx. 1 falken10 falken10 57 Mar 14 19:11 bonsai -> /home/falken10/bonsaiDevel/IfcOpenShell/src/bonsai/bonsai
      • lrwxrwxrwx. 1 falken10 falken10 55 Mar 14 19:11 ifc4d -> /home/falken10/bonsaiDevel/IfcOpenShell/src/ifc4d/ifc4d
      • etc.
    1. I have installed the "Blender Development" extension to VSCode
    2. I start VSCode and open folder DEVELOPMENT FOLDER/IfcOpenShell
    3. In VScode I do ctrl-shift-P and run Blender:Start
    4. I can setup breakpoints:
    5. This is already a very nice environment allowing to move by steps and check variables values in the debugger
    6. However if I try "Blender: Reload Addons" in the VSCCode I do not get anything.

    Have you managed to get bonsai reloaded from VScode somehow without killing Blender and restarting it again with "Blender:Start"?
    Thanks!

    Massimo
  • @falken10vdl As I said in my comment, I never bothered with the addon reloading. I just remembered the thread and linked it.
    This next bit is from memory based on what I figured out back when I figured this all out, so it is not verified. I recall the blender_vscode extension for VSCode/Codium did some funky stuff with the project folder when you launch it, linking it into the selected Blender install. I think you might be editing code that is not the one being used by blender, as that is a duplicate that is "installed" by the blender_vscode extension.

  • @sjb007 said:
    @falken10vdl As I said in my comment, I never bothered with the addon reloading. I just remembered the thread and linked it.
    This next bit is from memory based on what I figured out back when I figured this all out, so it is not verified. I recall the blender_vscode extension for VSCode/Codium did some funky stuff with the project folder when you launch it, linking it into the selected Blender install. I think you might be editing code that is not the one being used by blender, as that is a duplicate that is "installed" by the blender_vscode extension.

    Ok. Thanks for the explanation! It looks to me that since in Blender now there is the concept of extension (which is within the extendions folder) which is different to the one of addon (which is within the scripts folder), the vscode "Blender: Addon reloads" is applying to the ones below de scripts folder.
    Thanks!

  • @falken10vdl @sjb007 i managed to make the blender extension work, so i can make my change and run blender with VSCode but i can't debug it...
    When i click to "run and debug" it asks me which debug use and i don't know which one i have to select...have i to install also a blender debug installer?

  • edited March 15

    @Massimo Don't use the standard run debug buttons. You use the command line (Ctrl+Shift+P) Then "Blender: Start" (start typing and it will predictively find the rest of the command if it's not already listed.) This runs the blender_vscode extension, and will set everything up and open Blender. Now if you've set a breakpoint, it will interrupt Blender when it hits it, and then you can use the standard buttons to step through the code and examine the stack and variables.

    Massimo
  • edited March 15

    @Massimo Yes, I follow @sjb007 directions. I launch blender within VScode. I open the development folder I use. I go to the file (files section in VScode) and set the break point (the little red dot) in the right place of the file. You do not need to hit run. You just go to blender and trigger whatever action that will run the code that has the break-point. In my case I go to the solar Analysis and click the "no shadow" rendering mode. I have setup the corresponding break-point just before a print statement. You can see that the break point gets triggered and if I continue (the play button) then the print comes to the terminal within VScode.
    As you can see, you set the break-point within the file in the "files section" of VScode. Then when the even in Blender is triggered, VScode changed to the "debugging section" where you can step and check variables.
    Here the extensions I am running in VScode:

    Here the video with an example:
    "
    Thanks!

    Massimo
  • BTW if you find any improvements to make to the docs about this workflow, a PR would be really appreciated :)

  • Sure! I have a nice worflow I believe. Once I have it smooth I willbe glad to share the complete setup in the docs.
    The only missing part is the "Blender: Reload Addons" which is not working with the vscode blender extension. Apparently as long as the addon has register/unregister functions it should work... I have raised a question to the vscode blender extension author.
    @Moult currently if you do some change to your git cloned folder, how do you get the changes updated in blender? I am only able to restart blender to see the changes (and reload typically a testing ifc file)
    Thanks!

    carlopav
  • I either restart Blender (it takes only 2-3 seconds to start on my machine) or I rerun the automated failing test.

  • Ok thanks! Yes, restart blender is the current option I have as well. It takes a couple of seconds as you say. What it takes then longer is to load a test ifc file to check. It is few MBs and that one takes half a minute.
    It is not a nightmare but I just wanted to explore if there is a way to get bonsai reloaded in an.already opened ifc file in blender from within vscode.
    Thanks!

  • I'm not totally following this 100%, but with vscode blender extension i run the code from blender's extension folder, and the I symlink these files back to the ifcopenshell repo. I don't think ou can run vscode blender extension from the ifcopenshell repo. Could be wrong.

  • Well I open VSCode folder in the repo I cloned from ifcopenshell and it works. "Blender: Start" is starting the blender executable that has the addon installed as "Live development environment" with the dev_environment.sh executed so it has links from the .config towards the cloned repository.
    The only missing part I have in my workflow is automating teh restart and reload of an ifc file as part of the process to see the changes I do in the cloned repository propagated to blender execution.
    I am trying to launch blender from vscode with the parameter --python-expr "import bpy; bpy.ops.bim.load_project(filepath=\"/home/falken10/bonsaiDevel/exmaple.ifc\", should_start_fresh_session=True, use_detailed_tooltip=True)" but although it works perfectly from a linux terminal, it troughs an error when doing it in the VSCode blender extension settings.
    I am taking a look to that vscode extension to see if that can be fixed.

  • I raised a couple of questions to the current VSCode Blender extension mantainer (Mateusz-Grzelinski) and I think I have now a nice workflow in which I do not use Blender:Reload-Addons. I rather use F3 within Blender and trigger bim.restart_blender - Restart Blender. I then have an startup argument to load the project I use to test during development.

    I am going to craft a complete doc explaining the setup in case this is useful.
    Thanks!
    PS: The quesitons in VSCode github:
    Blender Additional Arguments not working? --python-expr "unknown argument"? #221
    Blender Reload Addons not working for Bonsai extension #220

    Massimosteverugi
  • When there is an agreed workflow for VSCode, due to its popularity it woudl be awesome if you could submit a PR to update the docs :)

    steverugi
  • @theoryshaw , thanks a lot for the link! I didn't know about it. There are hidden gems in this forum.
    Since I was not able to get the reload function to work (I understand now why...) I took the pragmatic approach to restart blender with a startup parametr to reload the ifc project. In my case that is about 5-10 secs in total for a file with a few thousand objects.
    Thanks!

    Massimo
  • edited March 21

    @Moult said:
    When there is an agreed workflow for VSCode, due to its popularity it woudl be awesome if you could submit a PR to update the docs :)

    @Moult here is a PR Add quickstart guide for linux IDE #6408 for a possible QS guide for IDE in Linux. If you guys can provide feedback I can update it and do the corresponding ones for Windows & MacOs.
    My native language is not English either, so maybe there are awkward constructions...
    I attach the QS as a print to PDF from the html page.
    Thanks!

  • edited April 19

    New to this, but i tried the 'Bundling for Blender' and the same error in this doc kept popping up:
    cd build && python3 -m venv env && . env/bin/activate && pip3.11 install build
    /bin/sh: pip3.11: command not found
    Seems to be something with pip, but I can't figure it out...

  • @ifcastel what os and version are you running?. Basically you seem to not have pip3.11 installed or in the path.

  • edited 2:06PM

    @falken10vdl said:
    @ifcastel what os and version are you running?. Basically you seem to not have pip3.11 installed or in the path.

    MacOS Sequoia on a Mac Mini with M2 chip. I figured out the error: i was building for python3.12, but if you look at the makefile it uses pip3.11, which i had not installed since i did not have python3.11 installed. Is it weird that it uses pip3.11 for building for python3.12?
    However, it seems to build for quite a while and then says IfcOpenShell/src/ifcopenshell-python/build/env/bin/python3: No module named build

  • Ah! I do not have MacOs. Maybe others can help?

Sign In or Register to comment.