sverchok icon indicating copy to clipboard operation
sverchok copied to clipboard

Modules duplication

Open Durman opened this issue 3 years ago • 0 comments

Problem statement

Because of this code

https://github.com/nortikin/sverchok/blob/a5d07429c5f697fd44caba94191890fc9a7ab2ca/core/init.py#L96-L99

https://github.com/nortikin/sverchok/blob/a5d07429c5f697fd44caba94191890fc9a7ab2ca/init.py#L64-L66

the same modules can be imported several times. This is bad because some modules can share information between eachother via third modules and if each of them has its own instance of a module then there is no information interchange. In general I think all modules should have only one instance.

Looks like that sverchok name was added to sys.modules so that import path could be started from sverchok name. But it's not clear why relative import paths could not be used instead.

Adding main module reachable by sverchok name makes importing modules peculiar. For example:

__name__ == "svercok-master"  # True
from sverchok.data_structure import DEBUG_MODE
assert('sverchok.data_structure' in sys.modules)  # True
__name__ == "svercok-master"  # True
from sverchok import data_structure
assert('sverchok-master.data_structure' in sys.modules)  # True

I'm not sure yet how this can be handled. Probably adding __name__ = "sverchok" would solve the problem.

Useful links: https://b3d.interplanety.org/en/creating-multifile-add-on-for-blender/ https://devtalk.blender.org/t/plugin-hot-reload-by-cleaning-sys-modules/20040

Durman avatar Aug 13 '21 10:08 Durman