Find, parse and cache extensions.
There are two types of extensions: UI Extensions (components.Extension) and
Library Extensions (components.LibraryExtension).
This module, finds the ui extensions installed and parses their directory for
tools or loads them from cache. It also finds the library extensions and adds
their directory address to the ui extensions so the python tools can use
the shared libraries.
To do its job correctly, this module needs to communicate with
pyrevit.userconfig to get a list of user extension folder and also
pyrevit.extensions.extpackages to check whether an extension is active or not.
Attributes
mlogger = get_logger(__name__)
module-attribute
Classes
Functions
get_thirdparty_extension_data()
Returns all installed and active UI and Library extensions (not parsed).
Returns:
Type |
Description |
list
|
list of components.Extension or components.LibraryExtension
|
Source code in pyrevitlib/pyrevit/extensions/extensionmgr.py
| def get_thirdparty_extension_data():
"""Returns all installed and active UI and Library extensions (not parsed).
Returns:
(list): list of components.Extension or components.LibraryExtension
"""
# FIXME: reorganzie this code to use one single method to collect
# extension data for both lib and ui
ext_data_list = []
for root_dir in user_config.get_thirdparty_ext_root_dirs():
ext_data_list.extend(
[ui_ext for ui_ext in parse_dir_for_ext_type(root_dir,
Extension)])
ext_data_list.extend(
[lib_ext for lib_ext in parse_dir_for_ext_type(root_dir,
LibraryExtension)])
return _remove_disabled_extensions(ext_data_list)
|
get_installed_lib_extensions(root_dir)
Returns all the installed and active Library extensions (not parsed).
Parameters:
Name |
Type |
Description |
Default |
root_dir |
str
|
Extensions directory address
|
required
|
Returns:
Type |
Description |
list[LibraryExtension]
|
list of components.LibraryExtension objects
|
Source code in pyrevitlib/pyrevit/extensions/extensionmgr.py
| def get_installed_lib_extensions(root_dir):
"""Returns all the installed and active Library extensions (not parsed).
Args:
root_dir (str): Extensions directory address
Returns:
(list[LibraryExtension]): list of components.LibraryExtension objects
"""
lib_ext_list = \
[lib_ext for lib_ext in parse_dir_for_ext_type(root_dir,
LibraryExtension)]
return _remove_disabled_extensions(lib_ext_list)
|
get_installed_ui_extensions()
Returns all UI extensions (fully parsed) under the given directory.
This will also process the Library extensions and will add
their path to the syspath of the UI extensions.
Returns:
Type |
Description |
list[Extension]
|
list of components.Extension objects
|
Source code in pyrevitlib/pyrevit/extensions/extensionmgr.py
| def get_installed_ui_extensions():
"""Returns all UI extensions (fully parsed) under the given directory.
This will also process the Library extensions and will add
their path to the syspath of the UI extensions.
Returns:
(list[Extension]): list of components.Extension objects
"""
ui_ext_list = []
lib_ext_list = []
# get a list of all directories that could include extensions
ext_search_dirs = user_config.get_ext_root_dirs()
mlogger.debug('Extension Directories: %s', ext_search_dirs)
# collect all library extensions. Their dir paths need to be added
# to sys.path for all commands
for root_dir in ext_search_dirs:
lib_ext_list.extend(get_installed_lib_extensions(root_dir))
# Get a list of all installed extensions in this directory
# _parser.parse_dir_for_ext_type() returns a list of extensions
# in given directory
for root_dir in ext_search_dirs:
for ext_info in parse_dir_for_ext_type(root_dir, Extension):
# test if cache is valid for this ui_extension
# it might seem unusual to create a ui_extension and then
# re-load it from cache but minimum information about the
# ui_extension needs to be passed to the cache module for proper
# hash calculation and ui_extension recovery. at this point
# `ui_extension` does not include any sub-components
# (e.g, tabs, panels, etc) ui_extension object is very small and
# its creation doesn't add much overhead.
if _is_extension_enabled(ext_info):
ui_extension = _parse_or_cache(ext_info)
ui_ext_list.append(ui_extension)
else:
mlogger.debug('Skipping disabled ui extension: %s',
ext_info.name)
# update extension master syspaths with standard pyrevit lib paths and
# lib address of other lib extensions (to support extensions that provide
# library only to be used by other extensions)
# all other lib paths internal to the extension and tool bundles have
# already been set inside the extension bundles and will take precedence
# over paths added by this method (they're the first paths added to the
# search paths list, and these paths will follow)
for ui_extension in ui_ext_list:
_update_extension_search_paths(
ui_extension,
lib_ext_list,
[MAIN_LIB_DIR, MISC_LIB_DIR]
)
return ui_ext_list
|