From 955806db7ec073505204c1c4757f6c4ac49f72e9 Mon Sep 17 00:00:00 2001 From: Mathieu Benoit Date: Sun, 4 May 2025 03:06:49 -0400 Subject: [PATCH] [UPD] script pycharm configuration: exclude with dynamic search --- script/ide/pycharm_configuration.py | 46 +++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/script/ide/pycharm_configuration.py b/script/ide/pycharm_configuration.py index f912ab2..4a2a19e 100755 --- a/script/ide/pycharm_configuration.py +++ b/script/ide/pycharm_configuration.py @@ -30,13 +30,6 @@ IDEA_WORKSPACE = os.path.join(IDEA_PATH, "workspace.xml") VCS_WORKSPACE = os.path.join(IDEA_PATH, "vcs.xml") PATH_EXCLUDE_FOLDER = "./conf/pycharm_exclude_folder.txt" -if os.path.isfile(PATH_EXCLUDE_FOLDER): - with open(PATH_EXCLUDE_FOLDER) as txt: - txt_read = txt.read() - LST_EXCLUDE_FOLDER = txt_read.strip().split("\n") -else: - LST_EXCLUDE_FOLDER = [] - PATH_DEFAULT_CONFIGURATION = "./conf/pycharm_default_configuration.csv" @@ -436,6 +429,35 @@ def add_configuration(dct_xml, file_name, config): return has_change +def get_lst_exclude_folder(): + if os.path.isfile(PATH_EXCLUDE_FOLDER): + with open(PATH_EXCLUDE_FOLDER) as txt: + txt_read = txt.read() + lst_exclude_folder = txt_read.strip().split("\n") + else: + lst_exclude_folder = [] + + # lst_to_exclude = ["./.venv.*", "./addons.*"] + lst_to_exclude = ["./.venv.*", "./addons"] + for s_exclude in lst_to_exclude: + for dir_venv in glob.glob(s_exclude): + lst_exclude_folder.append(dir_venv[2:]) + + # Dynamic exclude + lst_exclude_from_repo = ["setup"] + + git_tool = GitTool() + lst_repo = git_tool.get_repo_info_manifest_xml() + # Create a mapping of git directory from ERPLibre + for dct_repo in lst_repo: + relative_path = dct_repo.get("path") + for exclude_from_repo in lst_exclude_from_repo: + path_to_check = os.path.join(relative_path, exclude_from_repo) + if os.path.isdir(path_to_check): + lst_exclude_folder.append(path_to_check) + return lst_exclude_folder + + def add_exclude_folder(dct_xml, file_name, config): has_change = False dct_module = dct_xml.get("module") @@ -469,12 +491,10 @@ def add_exclude_folder(dct_xml, file_name, config): ) lst_exclude_folder = dct_content.get("excludeFolder") - # lst_to_exclude = ["./.venv.*", "./addons.*"] - lst_to_exclude = ["./.venv.*", "./addons"] - for s_exclude in lst_to_exclude: - for dir_venv in glob.glob(s_exclude): - LST_EXCLUDE_FOLDER.append(dir_venv[2:]) - lst_exclude_item = [f"file://$MODULE_DIR$/{a}" for a in LST_EXCLUDE_FOLDER] + lst_exclude_item_raw = get_lst_exclude_folder() + lst_exclude_item = [ + f"file://$MODULE_DIR$/{a}" for a in lst_exclude_item_raw + ] if lst_exclude_folder: if type(lst_exclude_folder) is list: