Skip to content

Commit

Permalink
merge to main
Browse files Browse the repository at this point in the history
  • Loading branch information
jedwards4b committed Feb 6, 2024
2 parents ad0a976 + 69a5dc5 commit 459ee47
Show file tree
Hide file tree
Showing 19 changed files with 1,002 additions and 193 deletions.
20 changes: 20 additions & 0 deletions doc/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = .
BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
26 changes: 26 additions & 0 deletions doc/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Configuration file for the Sphinx documentation builder.
#
# For the full list of built-in configuration values, see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

project = "git-fleximod"
author = "Jim Edwards <jedwards@ucar.edu>"
release = "0.4.0"

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

extensions = ["sphinx_argparse_cli"]

templates_path = ["_templates"]
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]


# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

html_theme = "alabaster"
html_static_path = ["_static"]
24 changes: 24 additions & 0 deletions doc/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.. git-fleximod documentation master file, created by
sphinx-quickstart on Sat Feb 3 12:02:22 2024.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Welcome to git-fleximod's documentation!
========================================

.. toctree::
:maxdepth: 2
:caption: Contents:
.. module:: sphinxcontrib.autoprogram
.. sphinx_argparse_cli::
:module: git_fleximod.cli
:func: get_parser
:prog: git-fleximod


Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
35 changes: 35 additions & 0 deletions doc/make.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@ECHO OFF

pushd %~dp0

REM Command file for Sphinx documentation

if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=.
set BUILDDIR=_build

%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.https://www.sphinx-doc.org/
exit /b 1
)

if "%1" == "" goto help

%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end

:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%

:end
popd
File renamed without changes.
119 changes: 119 additions & 0 deletions git_fleximod/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
from pathlib import Path
import argparse

__version__ = "0.6.1"

def find_root_dir(filename=".git"):
d = Path.cwd()
root = Path(d.root)
while d != root:
attempt = d / filename
if attempt.is_dir():
return attempt
d = d.parent
return None


def get_parser():
description = """
%(prog)s manages checking out groups of gitsubmodules with addtional support for Earth System Models
"""
parser = argparse.ArgumentParser(
description=description, formatter_class=argparse.RawDescriptionHelpFormatter
)

#
# user options
#
choices = ["update", "checkout", "status", "test"]
parser.add_argument(
"action",
choices=choices,
default="checkout",
help=f"Subcommand of git-fleximod, choices are {choices[:-1]}",
)

parser.add_argument(
"components",
nargs="*",
help="Specific component(s) to checkout. By default, "
"all required submodules are checked out.",
)

parser.add_argument(
"-C",
"--path",
default=find_root_dir(),
help="Toplevel repository directory. Defaults to top git directory relative to current.",
)

parser.add_argument(
"-g",
"--gitmodules",
nargs="?",
default=".gitmodules",
help="The submodule description filename. " "Default: %(default)s.",
)

parser.add_argument(
"-x",
"--exclude",
nargs="*",
help="Component(s) listed in the gitmodules file which should be ignored.",
)
parser.add_argument(
"-f",
"--force",
action="store_true",
default=False,
help="Override cautions and update or checkout over locally modified repository.",
)

parser.add_argument(
"-o",
"--optional",
action="store_true",
default=False,
help="By default only the required submodules "
"are checked out. This flag will also checkout the "
"optional submodules relative to the toplevel directory.",
)

parser.add_argument(
"-v",
"--verbose",
action="count",
default=0,
help="Output additional information to "
"the screen and log file. This flag can be "
"used up to two times, increasing the "
"verbosity level each time.",
)

parser.add_argument(
"-V",
"--version",
action="version",
version=f"%(prog)s {__version__}",
help="Print version and exit.",
)

#
# developer options
#
parser.add_argument(
"--backtrace",
action="store_true",
help="DEVELOPER: show exception backtraces as extra " "debugging output",
)

parser.add_argument(
"-d",
"--debug",
action="store_true",
default=False,
help="DEVELOPER: output additional debugging "
"information to the screen and log file.",
)

return parser
133 changes: 7 additions & 126 deletions src/git-fleximod → git_fleximod/git_fleximod.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,137 +3,19 @@
import os
import shutil
import logging
import argparse
import textwrap
from pathlib import Path
from fleximod import utils
from fleximod.gitinterface import GitInterface
from fleximod.gitmodules import GitModules
from fleximod.version import __version__
from git_fleximod import utils
from git_fleximod import cli
from git_fleximod.gitinterface import GitInterface
from git_fleximod.gitmodules import GitModules
from configparser import NoOptionError

# logger variable is global
logger = None


def find_root_dir(filename=".git"):
d = Path.cwd()
root = Path(d.root)
while d != root:
attempt = d / filename
if attempt.is_dir():
return attempt
d = d.parent
return None


def get_parser():
description = """
%(prog)s manages checking out groups of gitsubmodules with addtional support for Earth System Models
"""
parser = argparse.ArgumentParser(
description=description, formatter_class=argparse.RawDescriptionHelpFormatter
)

#
# user options
#
choices = ["update", "checkout", "status", "test"]
parser.add_argument(
"action",
choices=choices,
default="checkout",
help=f"Subcommand of fleximod, choices are {choices[:-1]}",
)

parser.add_argument(
"components",
nargs="*",
help="Specific component(s) to checkout. By default, "
"all required submodules are checked out.",
)

parser.add_argument(
"-C",
"--path",
default=find_root_dir(),
help="Toplevel repository directory. Defaults to top git directory relative to current.",
)

parser.add_argument(
"-g",
"--gitmodules",
nargs="?",
default=".gitmodules",
help="The submodule description filename. " "Default: %(default)s.",
)

parser.add_argument(
"-x",
"--exclude",
nargs="*",
help="Component(s) listed in the gitmodules file which should be ignored.",
)
parser.add_argument(
"-f",
"--force",
action="store_true",
default=False,
help="Override cautions and update or checkout over locally modified repository.",
)

parser.add_argument(
"-o",
"--optional",
action="store_true",
default=False,
help="By default only the required submodules "
"are checked out. This flag will also checkout the "
"optional submodules relative to the toplevel directory.",
)

parser.add_argument(
"-v",
"--verbose",
action="count",
default=0,
help="Output additional information to "
"the screen and log file. This flag can be "
"used up to two times, increasing the "
"verbosity level each time.",
)

parser.add_argument(
"-V",
"--version",
action="version",
version=f"%(prog)s {__version__}",
help="Print version and exit.",
)

#
# developer options
#
parser.add_argument(
"--backtrace",
action="store_true",
help="DEVELOPER: show exception backtraces as extra " "debugging output",
)

parser.add_argument(
"-d",
"--debug",
action="store_true",
default=False,
help="DEVELOPER: output additional debugging "
"information to the screen and log file.",
)

return parser


def commandline_arguments(args=None):
parser = get_parser()
parser = cli.get_parser()

if args:
options = parser.parse_args(args)
Expand Down Expand Up @@ -433,7 +315,6 @@ def submodules_update(gitmodules, root_dir, force):
if fxtag and fxtag not in tags:
git.git_operation("fetch", newremote, "--tags")
atag = git.git_operation("describe", "--tags", "--always").rstrip()
print(f"fxtag {fxtag} fxhash {fxhash}")
if fxtag and fxtag != atag:
print(f"{name:>20} updated to {fxtag}")
git.git_operation("checkout", fxtag)
Expand Down Expand Up @@ -506,7 +387,7 @@ def submodules_test(gitmodules, root_dir):
return testfails + localmods


def _main_func():
def main():
(
root_dir,
file_name,
Expand Down Expand Up @@ -556,4 +437,4 @@ def _main_func():


if __name__ == "__main__":
sys.exit(_main_func())
sys.exit(main())
Loading

0 comments on commit 459ee47

Please sign in to comment.