diff --git a/.github/workflows/awesome_workflow.yml b/.github/workflows/awesome_workflow.yml index 473d79406..a9fe27f50 100644 --- a/.github/workflows/awesome_workflow.yml +++ b/.github/workflows/awesome_workflow.yml @@ -9,7 +9,7 @@ jobs: name: Code Formatter runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v7 with: fetch-depth: 0 - uses: actions/setup-python@v4 diff --git a/filename_formatter.sh b/filename_formatter.sh new file mode 100644 index 000000000..555f5c8f4 --- /dev/null +++ b/filename_formatter.sh @@ -0,0 +1,61 @@ +#!/bin/bash + +echo -e "Arguments: +[0] - Used by Bash (script filename) +[1] - Base directory +[2] - Filename type (maximum two values) +[3] - Ignored files or folders (optional; use "\""./"\"") +" + +# Separate $2 value (filename types) if it has a comma +if [[ "$2" == *","* ]]; +then + string="$2" + + str_value=${string#*,} + str_value2=${string%%,*} +else + str_value="$2" + str_value2="$2" +fi + +# Do not run script if there are no given arguments. +if [[ "$1" == "" ]] || [[ "$2" == "" ]]; +then + echo "No arguments given. Please specify minimum two arguments." + exit 1 +fi + +echo "Changed files:" + +IFS=$'\n'; set -f +for fname in $(find $1 -type f -name "*$str_value2" -or -name "*$str_value") +do + ignored_files="$(echo "$3" | tr "," "\n")" + + str="${fname}" + value=${str%/*} # If the base directory is `.`, check in all directories for the ignored filenames + + for files in $ignored_files + do + echo ${fname} + if [ "${fname}" == "$value/$files" ] || [ "$value" == "$files" ]; + then + continue 2 + fi + done + + #echo ${fname} + new_fname=$(echo "${fname}" | tr ' ' '_') + #echo " ${new_fname}" + new_fname=$(echo "${new_fname}" | tr '[:upper:]' '[:lower:]') + #echo " ${new_fname}" + new_fname=$(echo "${new_fname}" | tr '-' '_') + #echo " ${new_fname}" + if [ "${fname}" != "${new_fname}" ] + then + echo " ${fname} --> ${new_fname}" + git "mv" "${fname}" "${new_fname}" # Requires you to be in version control + fi +done +unset IFS; set +f diff --git a/scripts/file_linter.py b/scripts/file_linter.py index cfa98a4b9..f26fbfea0 100644 --- a/scripts/file_linter.py +++ b/scripts/file_linter.py @@ -5,15 +5,28 @@ import sys print("Python {}.{}.{}".format(*sys.version_info)) # Python 3.8 with open("git_diff.txt") as in_file: modified_files = sorted(in_file.read().splitlines()) - print("{} files were modified.".format(len(modified_files))) + print(f"{len(modified_files)} files were modified.") - cpp_exts = tuple(".c .c++ .cc .cpp .cu .cuh .cxx .h .h++ .hh .hpp .hxx".split()) + cpp_exts = ( + ".c", + ".c++", + ".cc", + ".cpp", + ".cu", + ".cuh", + ".cxx", + ".h", + ".h++", + ".hh", + ".hpp", + ".hxx", + ) cpp_files = [file for file in modified_files if file.lower().endswith(cpp_exts)] print(f"{len(cpp_files)} C++ files were modified.") if not cpp_files: sys.exit(0) - subprocess.run( + _ = subprocess.run( [ "clang-tidy", "--fix", @@ -26,7 +39,7 @@ with open("git_diff.txt") as in_file: text=True, stderr=subprocess.STDOUT, ) - subprocess.run( + _ = subprocess.run( ["clang-format", "-i", "-style=file", *cpp_files], check=True, text=True,