From 1da0d288b0ee537e70092361afa1758819db7d92 Mon Sep 17 00:00:00 2001 From: w-e-w <40751091+w-e-w@users.noreply.github.com> Date: Fri, 19 Jan 2024 18:18:56 +0900 Subject: [PATCH] scripts.basedir() example --- Developing-extensions.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Developing-extensions.md b/Developing-extensions.md index ea382a3..7d1fd19 100644 --- a/Developing-extensions.md +++ b/Developing-extensions.md @@ -8,6 +8,22 @@ Web ui interacts with installed extensions in the following way: - extension's scripts in the `scripts` directory are executed as if they were just usual user scripts, except: - `sys.path` is extended to include the extension directory, so you can import anything in it without worrying. **HOWEVER, please either use a unique file name, or put your files in a uniquely-named folder, as the module will be cached to the global Python module tree by the name you used to import, and create surprises for other components that happen to use the same name.** - you can use `scripts.basedir()` to get the current extension's directory (since user can name it anything he wants) + - - note: `scripts.basedir()` must be used druing extension import stage,
if during other time it will return `webui root`.
click to see scripts.basedir() usage example

+ > stable-diffusion-webui\extensions\example_extension_dir\scripts\example.py + ```py + from modules import scripts + current_extension_directory = scripts.basedir() # 'stable-diffusion-webui\extensions\example_extension_dir' + # save it here for later use + class ExampleScript(scripts.Script): + def title(self): + return 'Example script' + def show(self, is_img2img): + scripts.basedir() # 'B:\GitHub\stable-diffusion-webui' + return scripts.AlwaysVisible + ``` +

+
+ - extension's javascript files in the `javascript` directory are added to the page - extension's localization files in the `localizations` directory are added to settings; if there are two localizations with same name, they are not merged, one replaces another. - extension's `style.css` file is added to the page