From 4c8063e2bf2a6c30e675d56650afff8868d99b7a Mon Sep 17 00:00:00 2001 From: kosta Date: Thu, 26 Jan 2023 10:25:18 +0300 Subject: [PATCH] [bos #32522][EDF] SALOME on Demand. Updated runSalomeOnDemand to process an ordered list of extensions. Fixed linter issues. --- bin/SalomeOnDemandTK/extension_query.py | 30 ++++++++++++++----------- bin/runSalomeOnDemand.py | 13 +++++------ 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/bin/SalomeOnDemandTK/extension_query.py b/bin/SalomeOnDemandTK/extension_query.py index 35274ee90..68953eee7 100644 --- a/bin/SalomeOnDemandTK/extension_query.py +++ b/bin/SalomeOnDemandTK/extension_query.py @@ -287,16 +287,16 @@ def ext_info_dict(directory): return ext_info -def ext_by_dependants(dependency_tree, depends_on=set()): - """ +def ext_by_dependants(dep_tree, depends_on=None): + r""" Calcualate a list of extensions names sorted by dependencies. Args: - dependency_tree - a dependecy tree of all considered extensions. + dep_tree - a dependecy tree of all considered extensions. depends_on - a set of extensions names to check if the current one depends on them. Returns: - A list of of extensions from dependency_tree sorted by dependencies. + A list of of extensions from dep_tree sorted by dependencies. For example, dictionary like that for extensions A, B, C, D and E: A /|\ @@ -308,15 +308,19 @@ def ext_by_dependants(dependency_tree, depends_on=set()): returns ['A', 'B', 'D', 'C', 'E']. """ - logger.debug('dependency_tree: %s, depends_on: %s', dependency_tree, depends_on) + logger.debug('dep_tree: %s, depends_on: %s', dep_tree, depends_on) - if not dependency_tree: + if not dep_tree: logger.debug('Dependency tree is empty! Return') return [] + # Check if we've got a default value + if not depends_on: + depends_on = set() + # Collect all dependencies for the given dependency level in the tree cur_depends_on = set() - for ext, dependendants in dependency_tree.items(): + for ext, dependendants in dep_tree.items(): # Select all components with empty dependendants is_selected = not dependendants @@ -326,7 +330,7 @@ def ext_by_dependants(dependency_tree, depends_on=set()): intersection = dep_set & depends_on logger.debug('ext: %s, dep_set: %s, intersection: %s', ext, dep_set, intersection) is_selected = intersection == dep_set - + if is_selected: cur_depends_on.add(ext) @@ -335,19 +339,19 @@ def ext_by_dependants(dependency_tree, depends_on=set()): if not cur_depends_on: logger.warning( 'Extensions in the tree doesnt rely on any other extensions! Return all of them') - return [ext for ext, _ in dependency_tree.items()] - + return [ext for ext, _ in dep_tree.items()] + # Collect all extension for this level res_extensions = [] for ext in cur_depends_on: res_extensions.append(ext) - del dependency_tree[ext] + del dep_tree[ext] logger.debug('res_extensions: %s', res_extensions) - # Get extensions from the next dependency level of the tree + # Get extensions from the next dependency level of the tree cur_depends_on |= depends_on - return res_extensions + ext_by_dependants(dependency_tree, cur_depends_on) + return res_extensions + ext_by_dependants(dep_tree, cur_depends_on) if __name__ == '__main__': diff --git a/bin/runSalomeOnDemand.py b/bin/runSalomeOnDemand.py index a54a1ac28..1326dd827 100755 --- a/bin/runSalomeOnDemand.py +++ b/bin/runSalomeOnDemand.py @@ -29,12 +29,11 @@ """Run SALOME app in the context of adding modules as extensions. """ -import os import sys import salomeContext from SalomeOnDemandTK.extension_utilities import logger, \ - DFILE_EXT, \ - list_files_ext, set_selext_env, get_app_root + set_selext_env, get_app_root +from SalomeOnDemandTK.extension_query import ext_by_dependants, dependency_tree def set_ext_env(app_name='', version=''): @@ -55,7 +54,8 @@ def set_ext_env(app_name='', version=''): app_root = get_app_root() # Find and source all _env.py files for installed extensions - installed_ext = list_files_ext(app_root, DFILE_EXT) + tree = dependency_tree(app_root) + installed_ext = ext_by_dependants(tree) logger.debug('Installed extensions: %s', installed_ext) if not installed_ext: logger.debug('There are not any extensions in %s!', app_root) @@ -66,10 +66,7 @@ def set_ext_env(app_name='', version=''): context.setVariable('SALOME_APPLICATION_DIR', app_root, overwrite=True) # Execute env file as a module - for salomexd in installed_ext: - salomexd_name = os.path.basename(salomexd) - ext_name, _ = os.path.splitext(salomexd_name) - + for ext_name in installed_ext: set_selext_env(app_root, ext_name, context) -- 2.39.2