Skip to content

Commit

Permalink
Subrepos' file default name is now defined on the main script file (s…
Browse files Browse the repository at this point in the history
…o it can be overwritten when using this code in library mode).
  • Loading branch information
jmnavarrol committed Apr 21, 2024
1 parent 7e90c8a commit 49405bd
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 24 deletions.
13 changes: 11 additions & 2 deletions src/multigit/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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__))
Expand Down
36 changes: 16 additions & 20 deletions src/multigit/subrepos.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'''

Expand All @@ -31,24 +21,30 @@ 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.
If there's a 'subrepos' file right a `base_path`, it will be processed.
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:
Expand All @@ -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=' ')
Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -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
Expand Down
2 changes: 0 additions & 2 deletions src/sphinx/subrepos.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
Class Subrepos
==============

.. autodata:: multigit.subrepos.SUBREPOS_FILE

.. autoclass:: multigit::Subrepos
:members:
:private-members:
Expand Down

0 comments on commit 49405bd

Please sign in to comment.