Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions parallelforeachsubmodule/pfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
import multiprocessing


def worker(submodule_list, path, command, counter, output_filter="", cmd_func=None, output_func=None):
def worker(submodule_list, path, command, filter_branch, counter, output_filter="", cmd_func=None, output_func=None):
if isinstance(submodule_list, Scheduler):
while not submodule_list.empty():
PFSProcess(submodule_list.get(), path, command, counter, output_filter, cmd_func, output_func).run()
PFSProcess(submodule_list.get(), path, command, filter_branch, counter, output_filter, cmd_func, output_func).run()
else:
for submodule in submodule_list:
PFSProcess(submodule, path, command, counter, output_filter, cmd_func, output_func).run()
PFSProcess(submodule, path, command, filter_branch, counter, output_filter, cmd_func, output_func).run()


class PFS(object):
Expand All @@ -36,6 +36,8 @@ def __init__(self):
parser.add_argument('-c', '--command', dest='command', help='Command to execute',
# type=self.empty_cmd,
default="")
parser.add_argument('--filter', dest='filter_branch',
help='Execute this command only in modules that have an specific branch')
parser.add_argument('-s', '--schedule', dest='schedule', help='Scheduling strategy', default='load-share',
choices=['CHUNK', 'LOAD-SHARE'],
type=lambda s: s.upper())
Expand Down Expand Up @@ -69,8 +71,8 @@ def __init__(self):
if str(output)[:-1].find(self.args.not_in_branch) == -1 else "In branch -> " + output),
}

self.__submodule_path_pattern = re.compile('path ?= ?([A-za-z0-9-_]+)(\/[A-za-z0-9-_]+)*([A-za-z0-9-_])')
self.__path_pattern = re.compile(' ([A-za-z0-9-_]+)(\/[A-za-z0-9-_]+)*([A-za-z0-9-_])')
self.__submodule_path_pattern = re.compile('path ?= ?([A-za-z0-9-_]+)(\\/[A-za-z0-9-_]+)*([A-za-z0-9-_])')
self.__path_pattern = re.compile(' ([A-za-z0-9-_]+)(\\/[A-za-z0-9-_]+)*([A-za-z0-9-_])')
Comment on lines +74 to +75
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What kind of problems did you have to make this change?

Copy link
Copy Markdown
Author

@andergnet andergnet Jun 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually this is a unrelated change. When I was testing the new feature I noticed a warning complaining about a malformed regular expression, something like unrecognized escape sequence. Either it was missing a backslash or it had one extra. I decided that it was missing one so it's able to parse windows paths.

It could go in a different PR if you wish.


@staticmethod
def exists_path(path):
Expand Down Expand Up @@ -174,11 +176,11 @@ def run(self):
for i in range(self.args.jobs):
if self.args.schedule == "load-share":
t = threading.Thread(target=worker,
args=(scheduler, self.args.path, command, self.__counter,
args=(scheduler, self.args.path, command, self.args.filter_branch, self.__counter,
Comment thread
RDCH106 marked this conversation as resolved.
output_filter, command_function, output_function,))
else:
t = threading.Thread(target=worker,
args=(list_submodule_list[i], self.args.path, command, self.__counter,
args=(list_submodule_list[i], self.args.path, command, self.args.filter_branch, self.__counter,
output_filter, command_function, output_function,))
self.__threads.append(t)
t.start()
Expand Down
6 changes: 5 additions & 1 deletion parallelforeachsubmodule/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@


class PFSProcess(object):
def __init__(self, submodule, path, cmd, counter, output_filter="", cmd_func=None, output_func=None):
def __init__(self, submodule, path, cmd, filter_branch, counter, output_filter="", cmd_func=None, output_func=None):
self.__submodule = submodule
self.__path = path
self.__cwd = os.path.join(self.__path, self.__submodule)
self.__cmd = cmd
self.__filter_branch = filter_branch
self.__counter = counter
self.__output_filter = output_filter
self.__active_branch = self.get_current_branch(self.__cwd)[:-1]
Expand All @@ -24,6 +25,9 @@ def get_current_branch(path):
return sub.check_output(['git', '-C', path, 'rev-parse', '--abbrev-ref', 'HEAD']).decode('utf-8')

def run(self):
if (self.__filter_branch and self.__filter_branch != self.__active_branch):
return

is_empty = True
self.__output = "\n\n" + self.__submodule + "\n"
# self.__output = sub.check_output(self.__cmd)
Expand Down