View Single Post
Old 12-01-2014, 07:09 PM   #57
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 7,651
Karma: 5433388
Join Date: Nov 2009
Device: many
Quote:
Originally Posted by Doitsu View Post
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.
Attached Files
File Type: zip libgui_as_folder_example.zip (7.8 KB, 536 views)
File Type: zip libgui_as_module_example.zip (8.0 KB, 517 views)

Last edited by KevinH; 12-01-2014 at 09:17 PM. Reason: Added to examples one using modules and one using folders
KevinH is offline   Reply With Quote