Skip to content

Commit

Permalink
Bulk refactoring so multigit can be also used as an imported module.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmnavarrol committed Apr 7, 2024
1 parent 2b1701e commit 19a5939
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 85 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Next Release
* Differences from [previous tag](/../../compare/v0.11.6…main).
* Code and metadata refactoring for an easier *"librarizing* in the future.

## 0.11.6 (2024-MAR-10)
* Differences from [previous tag](/../../compare/v0.11.5…v0.11.6).
Expand Down
2 changes: 1 addition & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ Pending actions, general notes, etc. (in no particular order):
* https://www.codingwiththomas.com/blog/my-sphinx-best-practice-for-a-multiversion-documentation-in-different-languages
* Refactor code so Makefile, pyproject.toml are at the repository's root?
* [#10](../../issues/10): Review [vag](https://github.com/charlyoleg2/vag) and [vcstool](https://github.com/dirk-thomas/vcstool) for inspiration.
* Refactor multigit so it can be used in library mode by other applications.
* Find the way to simplify subrepos' format allowing for *gitref* instead of *branch|tag|commit* (the code should find what kind of object *gitref* references).
* Add a `--check-version` option (or something like that) that looks for updates.
* Refactor tests so they go into subdirectories by "main" feature.

## IN PROGRESS
* Refactor multigit so it can be used in library mode by other applications.
61 changes: 2 additions & 59 deletions src/multigit/__init__.py
Original file line number Diff line number Diff line change
@@ -1,62 +1,5 @@
# -*- coding: utf-8 -*-
"""
This script is a Python implementation of `simplest-git-subrepos <https://github.com/jmnavarrol/simplest-git-subrepos>`_.

:package: multigit |release|
:author: `Jesús M. Navarro <mailto:[email protected]>`_
:license: `GNU General Public License v3.0 <https://github.com/jmnavarrol/python-multigit/blob/main/LICENSE>`_
:source: https://github.com/jmnavarrol/python-multigit
"""

__version__ = '0.11.6'

# Import stuff
import os, sys
import argparse

# "local" imports
from .subrepos import Subrepos, SUBREPOS_FILE
# Other imports so there's visibility of all classes in the module
from .__main__ import __version__
from .gitrepo import Gitrepo
from .subrepofile import Subrepofile



# MAIN entry point
def main():
'''Processes command line parameters'''
parser = argparse.ArgumentParser(
description="Manages git repos within git repos.",
add_help=False, # this way I can force help to be an exclusion option along the others
)

# Main options
main_parser = parser.add_mutually_exclusive_group()
main_parser.add_argument('-h', '--help', action='store_true', help="Shows this help.")
main_parser.add_argument('-V', '--version', action='store_true', help="Shows " + parser.prog + " version and quits.")
main_parser.add_argument('-r', '--run', action='store_true', help="Recursively processes '" + SUBREPOS_FILE + "' files found.")
main_parser.add_argument('-s', '--status', action='store_true', help="Shows repositories' current status.")

# Ready to parse args
args = parser.parse_args()
#print(args)

# Run on the options
if len(sys.argv) > 1:
if args.help:
print("%s (%s)\n" % (parser.prog, __version__))
parser.print_help()
elif args.version:
print("%s %s" % (parser.prog, __version__))
else:
my_subrepos = Subrepos()
my_subrepos.process(os.getcwd(), report_only=args.status)
else:
# Program called with no arguments (shows help)
print("%s (%s): arguments required.\n" % (parser.prog, __version__))
parser.print_help()


if __name__ == '__main__':
# execute only if run as a script
sys.exit(main())
from .subrepos import Subrepos
62 changes: 59 additions & 3 deletions src/multigit/__main__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,63 @@
# -*- coding: utf-8 -*-

from . import main
"""
**multigit** script is a Python implementation of `simplest-git-subrepos <https://github.com/jmnavarrol/simplest-git-subrepos>`_.
:package: multigit |release|
:author: `Jesús M. Navarro <mailto:[email protected]>`_
:license: `GNU General Public License v3.0 <https://github.com/jmnavarrol/python-multigit/blob/main/LICENSE>`_
:source: https://github.com/jmnavarrol/python-multigit
"""

__version__ = '0.11.7-dev1'

# Import stuff
import os, sys
import argparse

# "local" imports
from .subrepos import Subrepos, SUBREPOS_FILE
# Other imports so there's visibility of all classes in the module
from .gitrepo import Gitrepo
from .subrepofile import Subrepofile


# MAIN entry point
def main():
'''Processes command line parameters'''
parser = argparse.ArgumentParser(
description="Manages git repos within git repos.",
add_help=False, # this way I can force help to be an exclusion option along the others
)

# Main options
main_parser = parser.add_mutually_exclusive_group()
main_parser.add_argument('-h', '--help', action='store_true', help="Shows this help.")
main_parser.add_argument('-V', '--version', action='store_true', help="Shows " + parser.prog + " version and quits.")
main_parser.add_argument('-r', '--run', action='store_true', help="Recursively processes '" + SUBREPOS_FILE + "' files found.")
main_parser.add_argument('-s', '--status', action='store_true', help="Shows repositories' current status.")

# Ready to parse args
args = parser.parse_args()
#print(args)

# Run on the options
if len(sys.argv) > 1:
if args.help:
print("%s (%s)\n" % (parser.prog, __version__))
parser.print_help()
elif args.version:
print("%s %s" % (parser.prog, __version__))
else:
my_subrepos = Subrepos()
my_subrepos.process(os.getcwd(), report_only=args.status)
else:
# Program called with no arguments (shows help)
print("%s (%s): arguments required.\n" % (parser.prog, __version__))
parser.print_help()


if __name__ == '__main__':
main()

sys.exit(
main()
)
5 changes: 4 additions & 1 deletion src/multigit/gitrepo.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-

# Import stuff
import sys
from git import Repo, exc as git_exception


Expand Down Expand Up @@ -223,4 +224,6 @@ def update(self, repoconf):

if __name__ == '__main__':
# execute only if run as a script
main()
sys.exit(
main()
)
4 changes: 3 additions & 1 deletion src/multigit/subrepos.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,6 @@ def __print_subrepo_status(self, subrepo):

if __name__ == '__main__':
# execute only if run as a script
main()
sys.exit(
main()
)
4 changes: 2 additions & 2 deletions src/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ development = [
]

[project.scripts]
multigit = "multigit:main"
multigit = "multigit:__main__.main"

[build-system]
requires = [
Expand All @@ -56,4 +56,4 @@ requires = [
build-backend = "hatchling.build"

[tool.hatch.version]
path = "multigit/__init__.py"
path = "multigit/__main__.py"
35 changes: 17 additions & 18 deletions src/sphinx/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,31 @@
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
multigit documentation
======================
.. toctree::
:caption: Contents:
:hidden:
:maxdepth: 2

* :ref:`genindex`
* **Classes:**
* :ref:`Subrepos<subrepos>`: *"main"* entrypoint for the full process.
* :ref:`Gitrepo<gitrepo>`: manages a single git repository as per the requested configuration.
genindex
Class Subrepos <subrepos>
Class Gitrepo <gitrepo>

----
multigit documentation
======================
multigit script and module.

.. automodule:: multigit
.. automodule:: multigit.__main__
:noindex:
:members:
:undoc-members:
:show-inheritance:

.. command-output:: multigit --help

----

*"Main"* entry point is the `multigit` script:
**multigit** can also be used as an imported module.

.. command-output:: multigit --help

.. toctree::
:caption: Contents:
:hidden:
:maxdepth: 2

Class Subrepos <subrepos>
Class Gitrepo <gitrepo>
**Classes:**
* :ref:`Subrepos<subrepos>`: processes a full subrepos' configuration.
* :ref:`Gitrepo<gitrepo>`: manages a single git repository as per the requested configuration.

0 comments on commit 19a5939

Please sign in to comment.