From 49405bd14d87aa5ed3c57fbab7e0e6ce8f4f9eca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20M=2E=20Navarro?= Date: Sun, 21 Apr 2024 13:47:43 +0200 Subject: [PATCH] Subrepos' file default name is now defined on the main script file (so it can be overwritten when using this code in library mode). --- src/multigit/__main__.py | 13 +++++++++++-- src/multigit/subrepos.py | 36 ++++++++++++++++-------------------- src/sphinx/subrepos.rst | 2 -- 3 files changed, 27 insertions(+), 24 deletions(-) diff --git a/src/multigit/__main__.py b/src/multigit/__main__.py index 5855981..06d5c54 100644 --- a/src/multigit/__main__.py +++ b/src/multigit/__main__.py @@ -9,14 +9,19 @@ :source: https://github.com/jmnavarrol/python-multigit """ +# Globals __version__ = '0.11.7-dev2' +SUBREPOS_FILE = 'subrepos' +''' +The *"fixed"* name of the YAML file with subrepo definitions. +''' # pylint: disable=W0105 # Import stuff import os, sys import argparse # "local" imports -from .subrepos import Subrepos, SUBREPOS_FILE +from .subrepos import Subrepos # MAIN entry point def main(): @@ -46,7 +51,11 @@ def main(): print("%s %s" % (parser.prog, __version__)) else: my_subrepos = Subrepos() - my_subrepos.process(os.getcwd(), report_only=args.status) + my_subrepos.process( + base_path = os.getcwd(), + subrepos_filename = SUBREPOS_FILE, + report_only = args.status, + ) else: # Program called with no arguments (shows help) print("%s (%s): arguments required.\n" % (parser.prog, __version__)) diff --git a/src/multigit/subrepos.py b/src/multigit/subrepos.py index 980959a..ecf789f 100644 --- a/src/multigit/subrepos.py +++ b/src/multigit/subrepos.py @@ -13,16 +13,6 @@ from .gitrepo import Gitrepo from .subrepofile import Subrepofile -# Globals -SUBREPOS_FILE = 'subrepos' -''' -The *"fixed"* name of the YAML file with subrepo definitions. - -This file will first be loaded from current dir. - -Otherwise, if within a git sandbox, it will be looked for at the git sandbox' root. -''' # pylint: disable=W0105 - class Subrepos(object): '''Recursively reads subrepos files and runs git commands as per its findings''' @@ -31,7 +21,12 @@ def __init__(self): init(autoreset=True) - def process(self, base_path, report_only=True): + def process( + self, + base_path, + subrepos_filename = 'subrepos', + report_only=True + ): ''' Recursively finds and processes subrepos files. @@ -39,16 +34,17 @@ def process(self, base_path, report_only=True): If there is **not** a 'subrepos' file at `base_path` **and** `base_path` is within a git repo, it will try to find one at its root. - :param str base_path: the absolute path to the directory where subrepos file will be searched and processed. + :param str base_path: the absolute path to the directory where subrepos file will be searched for and processed. + :param str subrepos_filename: 'subrepos'. Name of file holding subrepos' definitions. :param bool report_only: `True`, just shows dirtree status; `False`, updates dirtree. ''' - if os.path.isfile(os.path.join(base_path + "/" + SUBREPOS_FILE)): - subrepos_file = os.path.join(base_path + "/" + SUBREPOS_FILE) + if os.path.isfile(os.path.join(base_path + "/" + subrepos_filename)): + subrepos_file = os.path.join(base_path + "/" + subrepos_filename) else: print(Style.BRIGHT + Fore.GREEN + "INFO:", end=' ') print("no valid ", end=' ') - print(Style.BRIGHT + "'" + SUBREPOS_FILE + "'", end=' found at ') + print(Style.BRIGHT + "'" + subrepos_filename + "'", end=' found at ') print(Style.BRIGHT + "'" + base_path + "'", end='.\n') # No subrepos file found at current path. Let's check if we are within a git sandbox try: @@ -59,8 +55,8 @@ def process(self, base_path, report_only=True): print("processing git repository rooted at", end=' ') print(Style.BRIGHT + "'" + root_dir + "'", end=':\n') - if os.path.isfile(os.path.join(base_path + "/" + SUBREPOS_FILE)): - subrepos_file = os.path.join(base_path + "/" + SUBREPOS_FILE) + if os.path.isfile(os.path.join(base_path + "/" + subrepos_filename)): + subrepos_file = os.path.join(base_path + "/" + subrepos_filename) except git_exception.InvalidGitRepositoryError as e: # Not a git repo: no more options left print(Style.BRIGHT + Fore.YELLOW + "WARNING:", end=' ') @@ -73,7 +69,7 @@ def process(self, base_path, report_only=True): except NameError: print(Style.BRIGHT + Fore.RED + "ERROR:", end=' ') print("Couldn't find any", end=' ') - print(Style.BRIGHT + "'" + SUBREPOS_FILE + "'", end=' ') + print(Style.BRIGHT + "'" + subrepos_filename + "'", end=' ') print("file... exiting.") sys.exit(errno.ENOENT) @@ -82,7 +78,7 @@ def process(self, base_path, report_only=True): if not subrepos: print(Style.BRIGHT + Fore.YELLOW + "WARNING:", end=' ') print("Couldn't find any", end=' ') - print(Style.BRIGHT + "'" + SUBREPOS_FILE + "'", end=' ') + print(Style.BRIGHT + "'" + subrepos_filename + "'", end=' ') print("file... exiting.") sys.exit(errno.ENOENT) @@ -103,7 +99,7 @@ def process(self, base_path, report_only=True): # Let's see if new subrepos appeared and (eventually) append them to the queue try: new_subrepos = subrepo.load( - os.path.join(current_subrepo['path'], SUBREPOS_FILE) + os.path.join(current_subrepo['path'], subrepos_filename) ) except FileNotFoundError as e: # It's acceptable not to find new subrepos at this location diff --git a/src/sphinx/subrepos.rst b/src/sphinx/subrepos.rst index c939371..4275916 100644 --- a/src/sphinx/subrepos.rst +++ b/src/sphinx/subrepos.rst @@ -3,8 +3,6 @@ Class Subrepos ============== -.. autodata:: multigit.subrepos.SUBREPOS_FILE - .. autoclass:: multigit::Subrepos :members: :private-members: