Skip to content

Commit

Permalink
Prefer dashes instead of underscores in flags
Browse files Browse the repository at this point in the history
  • Loading branch information
natefoo committed Apr 6, 2023
1 parent fb5a294 commit 0f7b742
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 24 deletions.
18 changes: 18 additions & 0 deletions src/ephemeris/common_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@
import argparse


class HideUnderscoresHelpFormatter(argparse.HelpFormatter):
def add_arguments(self, actions):
for action in actions:
action.option_strings = list(s for s in action.option_strings if "_" not in s)
self.add_argument(action)


class RawDescriptionHideUnderscoresHelpFormatter(HideUnderscoresHelpFormatter, argparse.RawDescriptionHelpFormatter):
pass


class ArgumentDefaultsHideUnderscoresHelpFormatter(HideUnderscoresHelpFormatter, argparse.ArgumentDefaultsHelpFormatter):
pass


def get_common_args(login_required=True, log_file=False):
parser = argparse.ArgumentParser(add_help=False)
general_group = parser.add_argument_group("General options")
Expand All @@ -11,6 +26,8 @@ def get_common_args(login_required=True, log_file=False):
)
if log_file:
general_group.add_argument(
general_group.add_argument(
"--log-file",
"--log_file",
dest="log_file",
help="Where the log file should be stored. "
Expand All @@ -31,6 +48,7 @@ def get_common_args(login_required=True, log_file=False):
con_group.add_argument("-p", "--password", help="Password for the Galaxy user")
con_group.add_argument(
"-a",
"--api-key",
"--api_key",
dest="api_key",
help="Galaxy admin user API key (required if not defined in the tools list file)",
Expand Down
9 changes: 4 additions & 5 deletions src/ephemeris/generate_tool_list_from_ga_workflow_files.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
#!/usr/bin/env python
"""Tool to generate tools from workflows"""
import json
from argparse import (
ArgumentParser,
RawDescriptionHelpFormatter,
)
from argparse import ArgumentParser
from typing import (
Iterable,
List,
)

import yaml

from .common_parser import RawDescriptionHideUnderscoresHelpFormatter
from .shed_tools import InstallRepoDict
from .shed_tools_methods import format_tool_shed_url

Expand All @@ -30,7 +28,7 @@ def _parse_cli_options():

def _parser():
parser = ArgumentParser(
formatter_class=RawDescriptionHelpFormatter,
formatter_class=RawDescriptionHideUnderscoresHelpFormatter,
usage="%(prog)s <options>",
epilog="Workflow files must have been exported from Galaxy release 16.04 or newer.\n\n"
"example:\n"
Expand All @@ -55,6 +53,7 @@ def _parser():
)
parser.add_argument(
"-l",
"--panel-label",
"--panel_label",
dest="panel_label",
default="Tools from workflows",
Expand Down
17 changes: 11 additions & 6 deletions src/ephemeris/get_tool_list_from_galaxy.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#!/usr/bin/env python
"""Tool to extract a tool list from galaxy."""

from argparse import (
ArgumentDefaultsHelpFormatter,
ArgumentParser,
)
from argparse import ArgumentParser
from distutils.version import StrictVersion

import yaml
from bioblend.galaxy.tools import ToolClient
from bioblend.galaxy.toolshed import ToolShedClient

from . import get_galaxy_connection
from .common_parser import get_common_args
from .common_parser import (
ArgumentDefaultsHideUnderscoresHelpFormatter,
get_common_args,
)
from .shed_tools_methods import format_tool_shed_url


Expand Down Expand Up @@ -245,7 +245,7 @@ def _parser():
"""Creates the parser object."""
parent = get_common_args(login_required=True)
parser = ArgumentParser(
parents=[parent], formatter_class=ArgumentDefaultsHelpFormatter
parents=[parent], formatter_class=ArgumentDefaultsHideUnderscoresHelpFormatter
)
parser.add_argument(
"-o",
Expand All @@ -255,30 +255,35 @@ def _parser():
help="tool_list.yml output file",
)
parser.add_argument(
"--include-tool-panel-id",
"--include_tool_panel_id",
action="store_true",
help="Include tool_panel_id in tool_list.yml ? "
"Use this only if the tool panel id already exists. See "
"https://github.com/galaxyproject/ansible-galaxy-tools/blob/master/files/tool_list.yaml.sample",
)
parser.add_argument(
"--skip-tool-panel-name",
"--skip_tool_panel_name",
action="store_true",
help="Do not include tool_panel_name in tool_list.yml ?",
)
parser.add_argument(
"--skip-changeset-revision",
"--skip_changeset_revision",
action="store_true",
help="Do not include the changeset revision when generating the tool list."
"Use this if you would like to use the list to update all the tools in"
"your galaxy instance using shed-install.",
)
parser.add_argument(
"--get-data-managers",
"--get_data_managers",
action="store_true",
help="Include the data managers in the tool list. Requires admin login details",
)
parser.add_argument(
"--get-all-tools",
"--get_all_tools",
action="store_true",
help="Get all tools and revisions, not just those which are present on the web ui."
Expand Down
7 changes: 5 additions & 2 deletions src/ephemeris/install_tool_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@
from bioblend.galaxy.tools import ToolClient

from ephemeris import get_galaxy_connection
from ephemeris.common_parser import get_common_args
from ephemeris.common_parser import (
get_common_args,
HideUnderscoresHelpFormatter,
)

timeout_codes = (408, 502, 504)


def _parser():
parent = get_common_args()
parser = argparse.ArgumentParser(parents=[parent])
parser = argparse.ArgumentParser(parents=[parent], formatter_class=HideUnderscoresHelpFormatter)
parser.add_argument(
"-t",
"--tool",
Expand Down
7 changes: 6 additions & 1 deletion src/ephemeris/run_data_managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@
get_galaxy_connection,
load_yaml_file,
)
from .common_parser import get_common_args
from .common_parser import (
get_common_args,
HideUnderscoresHelpFormatter,
)
from .ephemeris_log import (
disable_external_library_logging,
setup_global_logger,
Expand Down Expand Up @@ -320,6 +323,7 @@ def _parser():

parser = argparse.ArgumentParser(
parents=[parent],
formatter_class=HideUnderscoresHelpFormatter,
description="Running Galaxy data managers in a defined order with defined parameters."
"'watch_tool_data_dir' in galaxy config should be set to true.'",
)
Expand All @@ -334,6 +338,7 @@ def _parser():
help="Disables checking whether the item already exists in the tool data table.",
)
parser.add_argument(
"--ignore-errors",
"--ignore_errors",
action="store_true",
help="Do not stop running when jobs have failed.",
Expand Down
9 changes: 7 additions & 2 deletions src/ephemeris/set_library_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
from bioblend import galaxy
from rich.progress import Progress

from .common_parser import get_common_args
from .common_parser import (
get_common_args,
HideUnderscoresHelpFormatter,
)

# Print iterations progress

Expand Down Expand Up @@ -75,7 +78,9 @@ def _parser():
"""Constructs the parser object"""
parent = get_common_args()
parser = argparse.ArgumentParser(
parents=[parent], description="Populate the Galaxy data library with data."
parents=[parent],
formatter_class=HideUnderscoresHelpFormatter,
description="Populate the Galaxy data library with data."
)
parser.add_argument("library", help="Specify the data library ID")
parser.add_argument(
Expand Down
9 changes: 7 additions & 2 deletions src/ephemeris/setup_data_libraries.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
import yaml
from bioblend import galaxy

from .common_parser import get_common_args
from .common_parser import (
get_common_args,
HideUnderscoresHelpFormatter,
)


def create_legacy(gi, desc):
Expand Down Expand Up @@ -211,7 +214,9 @@ def _parser():
"""Constructs the parser object"""
parent = get_common_args()
parser = argparse.ArgumentParser(
parents=[parent], description="Populate the Galaxy data library with data."
parents=[parent],
formatter_class=HideUnderscoresHelpFormatter,
description="Populate the Galaxy data library with data."
)
parser.add_argument("-i", "--infile", required=True, type=argparse.FileType("r"))
parser.add_argument(
Expand Down
Loading

0 comments on commit 0f7b742

Please sign in to comment.