diff --git a/spiffworkflow-backend/bin/codemod/remove_all_unused_functions b/spiffworkflow-backend/bin/codemod/remove_all_unused_functions new file mode 100755 index 00000000..b0686eda --- /dev/null +++ b/spiffworkflow-backend/bin/codemod/remove_all_unused_functions @@ -0,0 +1,41 @@ +#!/usr/bin/env bash + +function error_handler() { + >&2 echo "Exited with BAD EXIT CODE '${2}' in ${0} script at line: ${1}." + exit "$2" +} +trap 'error_handler ${LINENO} $?' ERR +set -o errtrace -o errexit -o nounset + +# HELP: remove all unused functions from python files + +if ! command -v dead >/dev/null 2>&1; then + echo "dead is not installed. installing..." + echo "pip install dead" +fi + +list_of_unused_things="$(dead | grep -E '^[a-z].*is never read')" + +filename_patterns_to_ignore="(codemod|migrations/versions|conftest.py|noxfile.py)" + +while read -r line; do + function_name="$(echo "$line" | awk '{print $1}')" + echo "possible function_name: ${function_name}" + file_name_and_line_number="$(echo "$line" | perl -p -e "s/.*is never read, defined in //g")" + file_name="$(echo "$file_name_and_line_number" | awk -F ':' '{print $1}')" + if ! grep "def $function_name" "$file_name" >/dev/null 2>&1; then + echo "skipping $function_name in ${file_name} because it's not a function" + continue + fi + if grep -E "$filename_patterns_to_ignore" <<< "$file_name" >/dev/null 2>&1; then + echo "skipping ${file_name} because it's in the list of files to ignore (probably because it is a false positive and actually used)" + continue + fi + echo "trying to remove $function_name from: ${file_name}" + + if python bin/codemod/update_file_to_remove_function.py "$file_name" "$function_name"; then + # TODO: run exhaustive tests, and if they pass, report success + echo "function ${function_name} removed from ${file_name}. yay!" + exit 0 + fi +done <<< "$list_of_unused_things" diff --git a/spiffworkflow-backend/bin/codemod/update_file_to_remove_function.py b/spiffworkflow-backend/bin/codemod/update_file_to_remove_function.py new file mode 100644 index 00000000..82d571fa --- /dev/null +++ b/spiffworkflow-backend/bin/codemod/update_file_to_remove_function.py @@ -0,0 +1,33 @@ +from bowler import Query +from bowler.types import Leaf + +# This came about because vulture (actually dead, from the list of Similar programs at https://pypi.org/project/vulture/) +# actually found unused stuff, and I wanted to remove it. +# See also https://github.com/craigds/decrapify + +def remove_function(filename: str, function_name: str) -> None: + + def remove_statement(node, capture, filename): + node.remove() + + bowler_query = (Query(filename) + .select_function(function_name) + .modify(remove_statement) + .execute(write=True, silent=True, interactive=False)) + + if len(bowler_query.exceptions) > 0: + print(f"Failed to remove function {function_name} from {filename}.") + raise Exception(bowler_query.exceptions[0]) + + print(f"Function {function_name} successfully removed from {filename}.") + + +if __name__ == "__main__": + import argparse + + parser = argparse.ArgumentParser(description="Remove a function from a Python file while preserving comments.") + parser.add_argument("filename", help="the file to modify") + parser.add_argument("function_name", help="the name of the function to remove") + args = parser.parse_args() + + remove_function(args.filename, args.function_name) diff --git a/spiffworkflow-backend/bin/import_tickets_for_command_line.py b/spiffworkflow-backend/bin/import_tickets_for_command_line.py index db7e35be..1392c111 100644 --- a/spiffworkflow-backend/bin/import_tickets_for_command_line.py +++ b/spiffworkflow-backend/bin/import_tickets_for_command_line.py @@ -11,17 +11,6 @@ from spiffworkflow_backend.services.process_instance_processor import ( from spiffworkflow_backend.services.process_instance_service import ( ProcessInstanceService, ) - - -def print_process_instance_count(process_model_identifier_ticket: str) -> None: - """Print process instance count.""" - process_instances = ProcessInstanceModel.query.filter_by( - process_model_identifier=process_model_identifier_ticket - ).all() - process_instance_count = len(process_instances) - print(f"process_instance_count: {process_instance_count}") - - def main(): """Main.""" app = get_hacked_up_app_for_script() diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/services/service_task_service.py b/spiffworkflow-backend/src/spiffworkflow_backend/services/service_task_service.py index 8500ecb5..2754e8ec 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/services/service_task_service.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/services/service_task_service.py @@ -91,6 +91,13 @@ class ServiceTaskDelegate: json_parse_error = e parsed_response = {} + if "spiff__logs" in parsed_response: + for log in parsed_response["spiff__logs"]: + current_app.logger.info(f"Log from connector {name}: {log}") + if "api_response" in parsed_response: + parsed_response = parsed_response["api_response"] + response_text = json.dumps(parsed_response) + if proxied_response.status_code >= 300: message = ServiceTaskDelegate.get_message_for_status(proxied_response.status_code) error = f"Received an unexpected response from service {name} : {message}"