From 797fe4db734283c9c6dd2c40916b36eb4c89843d Mon Sep 17 00:00:00 2001 From: jeff Date: Tue, 5 Dec 2023 23:16:12 -0500 Subject: [PATCH 1/6] extended split_list_arg to split by whitespaces while ignoring filepaths with whitespaces (escaped with '\' extended list_files to normalize filepaths containing whitespaces (escaped with '\') --- run-clang-format.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/run-clang-format.py b/run-clang-format.py index c82a1dd..8628985 100755 --- a/run-clang-format.py +++ b/run-clang-format.py @@ -22,6 +22,7 @@ import subprocess import sys import traceback +import re from distutils.util import strtobool from functools import partial @@ -69,6 +70,7 @@ def list_files(files, recursive=False, extensions=None, exclude=None): out = [] for file in files: + file = file.replace("\\", "") if recursive and os.path.isdir(file): for dirpath, dnames, fnames in os.walk(file): fpaths = [os.path.join(dirpath, fname) for fname in fnames] @@ -248,6 +250,14 @@ def split_list_arg(arg): Otherwise it is returned unchanged Workaround for GHA not allowing list arguments """ + pattern = r'(? Date: Tue, 5 Dec 2023 23:30:28 -0500 Subject: [PATCH 2/6] moved path normalization logic from list_files() to split_list_arg() --- run-clang-format.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/run-clang-format.py b/run-clang-format.py index 8628985..8a7459d 100755 --- a/run-clang-format.py +++ b/run-clang-format.py @@ -70,7 +70,7 @@ def list_files(files, recursive=False, extensions=None, exclude=None): out = [] for file in files: - file = file.replace("\\", "") + # file = file.replace("\\", "") if recursive and os.path.isdir(file): for dirpath, dnames, fnames in os.walk(file): fpaths = [os.path.join(dirpath, fname) for fname in fnames] @@ -254,9 +254,14 @@ def split_list_arg(arg): if len(arg) == 1: # split list by regex paths = re.split(pattern, arg[0]) - for path in paths: - # normalize paths by removing forward slashes - path = path.replace("\\", "") + print(paths) + paths = [path.replace("\\","") for path in paths] + # for path in paths: + # print(path) + # # normalize paths by removing forward slashes + # path = path.replace("\\", "dfgdf") + # print(path) + print(paths) return paths return arg[0].split() if len(arg) == 1 else arg From 4cfac557dbb4baf7c8a270804bc4ed8139317fee Mon Sep 17 00:00:00 2001 From: jeff Date: Thu, 7 Dec 2023 00:01:24 -0500 Subject: [PATCH 3/6] moved path normalization logic from split_list_arg() to normalize_paths() --- run-clang-format.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/run-clang-format.py b/run-clang-format.py index 8a7459d..531ea50 100755 --- a/run-clang-format.py +++ b/run-clang-format.py @@ -243,7 +243,13 @@ def print_trouble(prog, message, use_colors): error_text = bold_red(error_text) print("{}: {} {}".format(prog, error_text, message), file=sys.stderr) - +def normalize_paths(paths): + """ + Normalizes backward slashes in each path in list of paths + Ex) + "features/Test\ Features/feature.cpp" => "features/Test Features/feature.cpp" + """ + return [path.replace("\\","") for path in paths] def split_list_arg(arg): """ If arg is a list containing a single argument it is split into multiple elements. @@ -255,7 +261,7 @@ def split_list_arg(arg): # split list by regex paths = re.split(pattern, arg[0]) print(paths) - paths = [path.replace("\\","") for path in paths] + paths = normalize_paths(paths) # for path in paths: # print(path) # # normalize paths by removing forward slashes From fee86dacc73ab1b5d8acca5a2ee5c7a4619218f9 Mon Sep 17 00:00:00 2001 From: jeff Date: Thu, 7 Dec 2023 00:03:44 -0500 Subject: [PATCH 4/6] refactored split_list_arg() --- run-clang-format.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/run-clang-format.py b/run-clang-format.py index 531ea50..2b05352 100755 --- a/run-clang-format.py +++ b/run-clang-format.py @@ -250,6 +250,7 @@ def normalize_paths(paths): "features/Test\ Features/feature.cpp" => "features/Test Features/feature.cpp" """ return [path.replace("\\","") for path in paths] + def split_list_arg(arg): """ If arg is a list containing a single argument it is split into multiple elements. @@ -257,19 +258,19 @@ def split_list_arg(arg): Workaround for GHA not allowing list arguments """ pattern = r'(? Date: Thu, 7 Dec 2023 00:05:44 -0500 Subject: [PATCH 5/6] added comment for regex pattern in split_list_arg() --- run-clang-format.py | 1 + 1 file changed, 1 insertion(+) diff --git a/run-clang-format.py b/run-clang-format.py index 2b05352..21a1442 100755 --- a/run-clang-format.py +++ b/run-clang-format.py @@ -257,6 +257,7 @@ def split_list_arg(arg): Otherwise it is returned unchanged Workaround for GHA not allowing list arguments """ + # pattern matches all whitespaces except those preceded by a backslash, '\' pattern = r'(? Date: Thu, 7 Dec 2023 00:07:28 -0500 Subject: [PATCH 6/6] removed commented-out draft code from split_list_arg() and list_files() --- run-clang-format.py | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/run-clang-format.py b/run-clang-format.py index 21a1442..84359b3 100755 --- a/run-clang-format.py +++ b/run-clang-format.py @@ -70,7 +70,6 @@ def list_files(files, recursive=False, extensions=None, exclude=None): out = [] for file in files: - # file = file.replace("\\", "") if recursive and os.path.isdir(file): for dirpath, dnames, fnames in os.walk(file): fpaths = [os.path.join(dirpath, fname) for fname in fnames] @@ -259,18 +258,6 @@ def split_list_arg(arg): """ # pattern matches all whitespaces except those preceded by a backslash, '\' pattern = r'(?