Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sverchok imports refactoring #4823

Merged
merged 5 commits into from
Dec 19, 2022
Merged

Sverchok imports refactoring #4823

merged 5 commits into from
Dec 19, 2022

Conversation

Durman
Copy link
Collaborator

@Durman Durman commented Dec 16, 2022

Addressed problem description

Modules in the utils folder are not imported unless their imported from other modules (from core, ui, nodes). It also means that their register and unregister functions won't be called unless their are not imported. So it's possible to put operators into utils folder and register them there but in this case they should be explicitly imported to a module where they are used. This is done for performance of add-on startup though on this stage it might be barely measurable.

Also it fix import settings module. It was imported under add-on folder name. For example if the folder was sverchok-master the modules was imported with sverchok-master.settings path. Also modules imported in the settings modules could have the same root in path. In the same time all other modules are imported with sverchok root, independent to add-on folder name. This caused problems like that #4281.

Also it includes some small optimization, removes some code duplications and unused code.

Next step is to consider to use normal import statements. Now we use importlib.import_module function to import modules dynamically. This probably was implemented in this way to get import modules explicitly and call their register functions. But we also can easily get modules from sys.modules dictionary to call their registration functions. This is actually how it's done for imported utils modules now. Also current import approach is not friendly to use such tool as pydeps. On other hand using dynamic imports in a function is more convenient for startup profiling.

🚀 Startup performance is about 10% faster #4752

…4281

Settings were purposely imported via addon_folder_name.settings instead of sverchok.settings. I assume this was done to be able to write this: class SvPreferences: bl_idname = __package__. Because it seems that bl_idname of add-on settings should always be equal to name of add-on folder.
removing collecting sverchok node classes, it can be done by calling bpy.types.Node.bl_rna_get_subclass_py(bl_idname) instead,
move UI code from utils to the ui folder,
utils now are only registered when are imported from another core module or node.
@Durman Durman merged commit 8192dcd into master Dec 19, 2022
@Durman Durman deleted the sverchok_imports branch December 19, 2022 07:41
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.

1 participant