Skip to content

Commit

Permalink
Reformatted using black
Browse files Browse the repository at this point in the history
  • Loading branch information
pchakraborty committed May 7, 2024
1 parent df62e83 commit 195e714
Show file tree
Hide file tree
Showing 60 changed files with 1,446 additions and 1,005 deletions.
27 changes: 19 additions & 8 deletions docs/make_md_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
from mdutils.mdutils import MdUtils
import subprocess as sp

preamble='''
preamble = """
mepo provides many different commands for working with a multi-repository fixture.
'''
"""

# Assume this script is in mepo/doc. Then we need to get to the mepo/mepo.d/command directory
doc_dir_path = os.path.dirname(os.path.realpath(__file__))
Expand All @@ -21,11 +21,12 @@

mepo_command_path = os.path.join(main_dir_path, "bin", "mepo")


def get_command_list(directory):
# Get all commands
all_commands_py = glob.glob(os.path.join(directory, "*.py"))
all_commands = [os.path.basename(x).replace(".py", "") for x in all_commands_py]
all_commands.remove("command") # manually remove
all_commands.remove("command") # manually remove

# Now let's find the commands that have subcommands
## First we get commands with underscore
Expand All @@ -37,13 +38,16 @@ def get_command_list(directory):

return sorted(all_useful_commands)


def create_markdown_from_usage(command, mdFile):
cmd = [mepo_command_path, command, "--help"]

# Some commands have spaces, so we need to break it up again
cmd = " ".join(cmd).split()

result = sp.run(cmd, capture_output=True, universal_newlines=True, env={"COLUMNS": "256"})
result = sp.run(
cmd, capture_output=True, universal_newlines=True, env={"COLUMNS": "256"}
)
output = result.stdout

output_list = output.split("\n")
Expand All @@ -58,18 +62,25 @@ def create_markdown_from_usage(command, mdFile):
mdFile.new_header(level=3, title="Usage")
mdFile.insert_code(usage)

positional_arguments = output.partition("positional arguments:\n")[2].partition("\n\n")[0]
positional_arguments = output.partition("positional arguments:\n")[2].partition(
"\n\n"
)[0]
if positional_arguments:
mdFile.new_header(level=3, title="Positional Arguments")
mdFile.insert_code(positional_arguments)

optional_arguments = output.partition("optional arguments:\n")[2].partition("\n\n")[0]
optional_arguments = output.partition("optional arguments:\n")[2].partition("\n\n")[
0
]
# Remove extra blank lines
optional_arguments = os.linesep.join([s for s in optional_arguments.splitlines() if s])
optional_arguments = os.linesep.join(
[s for s in optional_arguments.splitlines() if s]
)
if optional_arguments:
mdFile.new_header(level=3, title="Optional Arguments")
mdFile.insert_code(optional_arguments)


if __name__ == "__main__":

doc_file = "Mepo-Commands.md"
Expand All @@ -83,7 +94,7 @@ def create_markdown_from_usage(command, mdFile):
for command in command_list:
mdFile.new_header(level=2, title=command)
print(f"mepo command: {command}")
create_markdown_from_usage(command,mdFile)
create_markdown_from_usage(command, mdFile)

mdFile.new_table_of_contents(table_title="Table of Contents", depth=2)
mdFile.create_md_file()
Expand Down
72 changes: 35 additions & 37 deletions src/mepo/cmdline/branch_parser.py
Original file line number Diff line number Diff line change
@@ -1,62 +1,60 @@
import argparse


class MepoBranchArgParser(object):

def __init__(self, branch):
self.branch_subparsers = branch.add_subparsers()
self.branch_subparsers.title = 'mepo branch sub-commands'
self.branch_subparsers.dest = 'mepo_branch_cmd'
self.branch_subparsers.title = "mepo branch sub-commands"
self.branch_subparsers.dest = "mepo_branch_cmd"
self.branch_subparsers.required = True
self.__list()
self.__create()
self.__delete()

def __list(self):
brlist = self.branch_subparsers.add_parser(
'list',
description = 'List local branches. If no component is specified, runs over all components')
"list",
description="List local branches. If no component is specified, runs over all components",
)
brlist.add_argument(
'-a', '--all',
action = 'store_true',
help = 'list all (local+remote) branches')
"-a", "--all", action="store_true", help="list all (local+remote) branches"
)
brlist.add_argument(
'--nocolor',
action = 'store_true',
help = 'do not display color')
"--nocolor", action="store_true", help="do not display color"
)
brlist.add_argument(
'comp_name',
metavar = 'comp-name',
nargs = '*',
help = 'component to list branches in')
"comp_name",
metavar="comp-name",
nargs="*",
help="component to list branches in",
)

def __create(self):
create = self.branch_subparsers.add_parser(
'create',
description = 'Create branch <branch-name> in component <comp-name>')
create.add_argument(
'branch_name',
metavar = 'branch-name',
help = "name of branch")
"create", description="Create branch <branch-name> in component <comp-name>"
)
create.add_argument("branch_name", metavar="branch-name", help="name of branch")
create.add_argument(
'comp_name',
metavar = 'comp-name',
nargs = '+',
help = 'component to create branches in')
"comp_name",
metavar="comp-name",
nargs="+",
help="component to create branches in",
)

def __delete(self):
delete = self.branch_subparsers.add_parser(
'delete',
description = 'Delete branch <branch-name> in component <comp-name>')
delete.add_argument(
'branch_name',
metavar = 'branch-name',
help = "name of branch")
"delete", description="Delete branch <branch-name> in component <comp-name>"
)
delete.add_argument("branch_name", metavar="branch-name", help="name of branch")
delete.add_argument(
'comp_name',
metavar = 'comp-name',
nargs = '+',
help = 'component to delete branches in')
"comp_name",
metavar="comp-name",
nargs="+",
help="component to delete branches in",
)
delete.add_argument(
'--force',
action = 'store_true',
help = 'delete branch even if it has not been fully merged')
"--force",
action="store_true",
help="delete branch even if it has not been fully merged",
)
62 changes: 30 additions & 32 deletions src/mepo/cmdline/config_parser.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import argparse
import textwrap


class MepoConfigArgParser(object):

def __init__(self, config):
self.config = config.add_subparsers()
self.config.title = 'mepo config sub-commands'
self.config.dest = 'mepo_config_cmd'
self.config.title = "mepo config sub-commands"
self.config.dest = "mepo_config_cmd"
self.config.required = True
self.__get()
self.__set()
Expand All @@ -15,42 +16,39 @@ def __init__(self, config):

def __get(self):
get = self.config.add_parser(
'get',
description = ('Get config `entry` in `.mepoconfig`. '
'Note this uses gitconfig style where `entry` is of the form `section.option`. '
'So to get an `alias` `st` You would run `mepo config get alias.st`'))
get.add_argument(
'entry',
metavar = 'entry',
help = 'Entry to display.')
"get",
description=(
"Get config `entry` in `.mepoconfig`. "
"Note this uses gitconfig style where `entry` is of the form `section.option`. "
"So to get an `alias` `st` You would run `mepo config get alias.st`"
),
)
get.add_argument("entry", metavar="entry", help="Entry to display.")

def __set(self):
set = self.config.add_parser(
'set',
description = ('Set config `entry` to `value` in `.mepoconfig`. '
'Note this uses gitconfig style where `entry` is of the form `section.option`. '
'So to set an `alias` for `status` of `st` You would run `mepo config set alias.st status`'))
set.add_argument(
'entry',
metavar = 'entry',
help = 'Entry to set.')
set.add_argument(
'value',
metavar = 'value',
help = 'Value to set entry to.')
"set",
description=(
"Set config `entry` to `value` in `.mepoconfig`. "
"Note this uses gitconfig style where `entry` is of the form `section.option`. "
"So to set an `alias` for `status` of `st` You would run `mepo config set alias.st status`"
),
)
set.add_argument("entry", metavar="entry", help="Entry to set.")
set.add_argument("value", metavar="value", help="Value to set entry to.")

def __delete(self):
delete = self.config.add_parser(
'delete',
description = ('Delete config `entry` in `.mepoconfig`. '
'Note this uses gitconfig style where `entry` is of the form `section.option`. '
'So to delete an `alias` `st` You would run `mepo config delete alias.st`'))
delete.add_argument(
'entry',
metavar = 'entry',
help = 'Entry to delete.')
"delete",
description=(
"Delete config `entry` in `.mepoconfig`. "
"Note this uses gitconfig style where `entry` is of the form `section.option`. "
"So to delete an `alias` `st` You would run `mepo config delete alias.st`"
),
)
delete.add_argument("entry", metavar="entry", help="Entry to delete.")

def __print(self):
print = self.config.add_parser(
'print',
description = 'Print contents of `.mepoconfig`')
"print", description="Print contents of `.mepoconfig`"
)
Loading

0 comments on commit 195e714

Please sign in to comment.