From dce52dadff8c20daa084582cd340aa2a85f8b42b Mon Sep 17 00:00:00 2001 From: alexiswl <8197659+alexiswl@users.noreply.github.com> Date: Mon, 29 Jan 2024 20:57:02 +1100 Subject: [PATCH] Autocompletion - update python helper scripts to pull in cwl-ica module --- autocompletion/bash/cwl-ica.bash | 522 ++++++++++++------ .../_cwl-ica_list_all_expression_paths.py | 9 +- .../helpers/_cwl-ica_list_all_schema_paths.py | 7 +- .../helpers/_cwl-ica_list_all_tool_paths.py | 7 +- ...ca_list_all_typescript_expression_paths.py | 7 +- .../_cwl-ica_list_all_workflow_paths.py | 7 +- .../helpers/_cwl-ica_list_category_names.py | 4 +- .../helpers/_cwl-ica_list_project_names.py | 4 +- ...wl-ica_list_registered_expression_paths.py | 7 +- .../_cwl-ica_list_registered_schema_paths.py | 7 +- .../_cwl-ica_list_registered_tool_paths.py | 9 +- ..._cwl-ica_list_registered_workflow_paths.py | 9 +- .../helpers/_cwl-ica_list_run_instance_ids.py | 5 +- .../helpers/_cwl-ica_list_tenant_names.py | 5 +- .../helpers/_cwl-ica_list_tool_names.py | 5 +- ...-ica_list_unregistered_expression_paths.py | 9 +- ..._cwl-ica_list_unregistered_schema_paths.py | 10 +- .../_cwl-ica_list_unregistered_tool_paths.py | 10 +- ...wl-ica_list_unregistered_workflow_paths.py | 10 +- .../helpers/_cwl-ica_list_user_names.py | 5 +- .../helpers/_cwl-ica_list_workflow_names.py | 5 +- autocompletion/run-autocompletion.sh | 6 +- autocompletion/zsh/_cwl-ica | 519 +++++++++++------ 23 files changed, 817 insertions(+), 371 deletions(-) diff --git a/autocompletion/bash/cwl-ica.bash b/autocompletion/bash/cwl-ica.bash index ff574c2..fa0a03f 100644 --- a/autocompletion/bash/cwl-ica.bash +++ b/autocompletion/bash/cwl-ica.bash @@ -78,6 +78,7 @@ Each project is linked to a tenancy id '$'\n''tool-sync'$'\t''Sync a tool md5sum in \${CWL_ICA_REPO_PATH}/config/tool.yaml and update definition on ICA '$'\n''tool-validate'$'\t''Validate a CWL tool ready for initialising on ICA +'$'\n''typescript-expression-update'$'\t''Update a typescript expression yarn.lock file '$'\n''typescript-expression-validate'$'\t''Validate a typescript expression and generate a .cwljs file ready for importation '$'\n''validate-api-key-script'$'\t''Confirm your api-key script works for a given project '$'\n''validate-config-yamls'$'\t''Confirm all config yamls are legitimate @@ -1341,6 +1342,26 @@ to workflow names ;; esac ;; + typescript-expression-update) + OPTIONS+=('--typescript-expression-dir' 'The name of the workflow +' '--xtrace' 'Set xtrace on the update_yarn_dependencies shell script +') + __cwl-ica_handle_options_flags + case ${MYWORDS[$INDEX-1]} in + --typescript-expression-dir) + _cwl-ica_typescript-expression-update_option_typescript_expression_dir_completion + ;; + --xtrace) + ;; + + esac + case $INDEX in + + *) + __comp_current_options || return + ;; + esac + ;; typescript-expression-validate) OPTIONS+=('--typescript-expression-dir' 'The name of the workflow ' '--xtrace' 'Set xtrace on the validate_typescript_expressions_directory shell script @@ -1490,8 +1511,9 @@ python - <= 1 and s_file.parent.parts[-1] == 'tests') and + # We also want to make sure it's under the tools, expressions or typescript-expressions directories + len( + {"tools", "expressions", "typescript-expressions"}.intersection( + [ + s_file.resolve().absolute().relative_to(get_cwl_ica_repo_path()).parent.parts[0] + ] + ) + ) > 0 + ] +else: + if current_word_value.endswith("/"): + current_path_resolved = Path(getcwd()).joinpath(Path(current_word_value)).resolve() + else: + current_path_resolved = Path(getcwd()).joinpath(Path(current_word_value).parent).resolve() + + typescript_expression_paths = [ + s_file.parent.relative_to(get_cwl_ica_repo_path()) + for s_file in current_path_resolved.glob("**/*.ts") + # We don't want to pull in the typescript test files + if not (len(s_file.parent.parts) >= 1 and s_file.parent.parts[-1] == 'tests') and + # We also want to make sure it's under the tools, expressions or typescript-expressions directories + len( + {"tools", "expressions", "typescript-expressions"}.intersection( + [ + s_file.resolve().absolute().relative_to(get_cwl_ica_repo_path()).parent.parts[0] + ] + ) + ) > 0 + ] + +# Resolve the current path +# If getcwd() is "/c/Users/awluc" +# 1. Non relative paths: current_word_value = "/etc" -> current_path_resolved = "/etc" +# 2. Relative parent path: current_word_value = "../../Program Files" -> current_path_resolved = "/c/Program Files" +# 3. Subfolder: current_word_value = "OneDrive" -> current_path_resolved = "/c/Users/awluc/OneDrive" +# 4. Subfolder of expressions dir = "OneDrive/GitHub/UMCCR/expressions/contig/" -> current path resolved + +# Is the current_path_resolved a subpath of the expressions directory? +try: + _ = current_path_resolved.relative_to(get_cwl_ica_repo_path()) + in_repo_dir = True +except ValueError: + in_repo_dir = False + +if in_repo_dir: + current_path_resolved_relative_to_expressions_dir = current_path_resolved.relative_to(get_cwl_ica_repo_path()) + if current_path_resolved_relative_to_expressions_dir == Path("."): + for s_path in typescript_expression_paths: + if current_word_value.endswith("/"): + print(Path(current_word_value) / s_path) + else: + print(Path(current_word_value).parent / s_path) + else: + for s_path in typescript_expression_paths: + if str(s_path).startswith(str(current_path_resolved_relative_to_expressions_dir)): + if current_word_value.endswith("/"): + print(Path(current_word_value) / s_path.relative_to( + current_path_resolved_relative_to_expressions_dir)) + else: + print(Path(current_word_value).parent / s_path.relative_to( + current_path_resolved_relative_to_expressions_dir)) + +else: + # Now get the expressions yaml path relative to the current path + try: + expressions_dir = get_cwl_ica_repo_path().relative_to(current_path_resolved) + except ValueError: + # We could be in a different mount point OR just in a subdirectory + if str(get_cwl_ica_repo_path().absolute()) in str(relpath(get_cwl_ica_repo_path(), current_path_resolved)): + # Separate mount point + expressions_dir = get_cwl_ica_repo_path().absolute() + else: + expressions_dir = Path(relpath(get_cwl_ica_repo_path(), current_path_resolved)) + + # Now iterate through paths + for s_path in typescript_expression_paths: + if current_word_value.endswith("/"): + print(Path(current_word_value) / expressions_dir.joinpath(s_path)) + else: + print(Path(current_word_value).parent / expressions_dir.joinpath(s_path)) +EOF +)" + _cwl-ica_compreply "$param_typescript_expression_dir" +} _cwl-ica_typescript-expression-validate_option_typescript_expression_dir_completion() { local CURRENT_WORD="${words[$cword]}" local param_typescript_expression_dir="$( @@ -4771,13 +4968,14 @@ python - <cmd1' \ + '--help[Show command help]' \ + '-h[Show command help]' \ + '--typescript-expression-dir[The name of the workflow +]:typescript-expression-dir:_cwl-ica_typescript-expression-update_option_typescript_expression_dir_completion' \ + '--xtrace[Set xtrace on the update_yarn_dependencies shell script +]:xtrace' \ + && ret=0 + + ;; typescript-expression-validate) @@ -1181,8 +1197,9 @@ python - <= 1 and s_file.parent.parts[-1] == 'tests') and + # We also want to make sure it's under the tools, expressions or typescript-expressions directories + len( + {"tools", "expressions", "typescript-expressions"}.intersection( + [ + s_file.resolve().absolute().relative_to(get_cwl_ica_repo_path()).parent.parts[0] + ] + ) + ) > 0 + ] +else: + if current_word_value.endswith("/"): + current_path_resolved = Path(getcwd()).joinpath(Path(current_word_value)).resolve() + else: + current_path_resolved = Path(getcwd()).joinpath(Path(current_word_value).parent).resolve() + + typescript_expression_paths = [ + s_file.parent.relative_to(get_cwl_ica_repo_path()) + for s_file in current_path_resolved.glob("**/*.ts") + # We don't want to pull in the typescript test files + if not (len(s_file.parent.parts) >= 1 and s_file.parent.parts[-1] == 'tests') and + # We also want to make sure it's under the tools, expressions or typescript-expressions directories + len( + {"tools", "expressions", "typescript-expressions"}.intersection( + [ + s_file.resolve().absolute().relative_to(get_cwl_ica_repo_path()).parent.parts[0] + ] + ) + ) > 0 + ] + +# Resolve the current path +# If getcwd() is "/c/Users/awluc" +# 1. Non relative paths: current_word_value = "/etc" -> current_path_resolved = "/etc" +# 2. Relative parent path: current_word_value = "../../Program Files" -> current_path_resolved = "/c/Program Files" +# 3. Subfolder: current_word_value = "OneDrive" -> current_path_resolved = "/c/Users/awluc/OneDrive" +# 4. Subfolder of expressions dir = "OneDrive/GitHub/UMCCR/expressions/contig/" -> current path resolved + +# Is the current_path_resolved a subpath of the expressions directory? +try: + _ = current_path_resolved.relative_to(get_cwl_ica_repo_path()) + in_repo_dir = True +except ValueError: + in_repo_dir = False + +if in_repo_dir: + current_path_resolved_relative_to_expressions_dir = current_path_resolved.relative_to(get_cwl_ica_repo_path()) + if current_path_resolved_relative_to_expressions_dir == Path("."): + for s_path in typescript_expression_paths: + if current_word_value.endswith("/"): + print(Path(current_word_value) / s_path) + else: + print(Path(current_word_value).parent / s_path) + else: + for s_path in typescript_expression_paths: + if str(s_path).startswith(str(current_path_resolved_relative_to_expressions_dir)): + if current_word_value.endswith("/"): + print(Path(current_word_value) / s_path.relative_to( + current_path_resolved_relative_to_expressions_dir)) + else: + print(Path(current_word_value).parent / s_path.relative_to( + current_path_resolved_relative_to_expressions_dir)) + +else: + # Now get the expressions yaml path relative to the current path + try: + expressions_dir = get_cwl_ica_repo_path().relative_to(current_path_resolved) + except ValueError: + # We could be in a different mount point OR just in a subdirectory + if str(get_cwl_ica_repo_path().absolute()) in str(relpath(get_cwl_ica_repo_path(), current_path_resolved)): + # Separate mount point + expressions_dir = get_cwl_ica_repo_path().absolute() + else: + expressions_dir = Path(relpath(get_cwl_ica_repo_path(), current_path_resolved)) + + # Now iterate through paths + for s_path in typescript_expression_paths: + if current_word_value.endswith("/"): + print(Path(current_word_value) / expressions_dir.joinpath(s_path)) + else: + print(Path(current_word_value).parent / expressions_dir.joinpath(s_path)) +EOF + + ) ) + compadd -X "typescript_expression_dir:" $__dynamic_completion +} _cwl-ica_typescript-expression-validate_option_typescript_expression_dir_completion() { local __dynamic_completion local CURRENT_WORD="$words[CURRENT]" @@ -4608,13 +4802,14 @@ python - <