Quote:
Originally Posted by Doitsu
BS3 is easily embeddable in a plugin, because it's a single Python file, but BS4 installs a folder. Is there any Python tool that'll "flatten" that folder into a single Python file or will I need to change the Import statement after copying the complete BS4 folder into the folder of the plugin?
(The default Import statement didn't work when I copied the whole BS4 folder into the plugin folder.)
|
There are a number of ways to handle it. You can manually add the subdirectory to sys.path so that a normal import will find it or alternatively you can use module based relative paths for importing it. The same is true for libgui as well.
I have added two different ways to import from a subdirectory either as a folder or as a module. See libgui_as_folder_example.zip and libgui_as_module_example.zip.
Notice the differences in test.py for how you add to the path or do the module based import. Also look at the differences in libgui as module that has its own __init__.py and uses relative addressing to import from .askfolder and .user_utilities, versus the libgui as folder example with no __init__.py and that relies on the sys.path search being done to find its imports.
Take care,
KevinH
ps. please note that for BS4 to work crossplatform as pure python, it is probably a good idea to include html5lib as well to get a pure python parser/tokenizer to inside BS4. Together, these will work on all platforms, and make embedding of BS4 quite easy.