Skip to content

Commit

Permalink
Merge pull request #11 from ssl-hep/fix_up_cmd_line_args
Browse files Browse the repository at this point in the history
Use a better name for adding in command lien args
  • Loading branch information
gordonwatts authored Jun 11, 2021
2 parents c21dcc0 + e627a8d commit ee5bee1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ If you do need to configure your DID finder from command line arguments, then us
help='Prefix to add to Xrootd URLs')
parser.add_argument('--threads', dest='threads', action='store',
default=10, type=int, help="Number of threads to spawn")
default_command_line_args(parser)
add_did_finder_cnd_arguments(parser)

args = parser.parse_args()

Expand Down Expand Up @@ -99,7 +99,7 @@ If you do need to configure your DID finder from command line arguments, then us

In particular note:

1. The call to `default_command_line_args` to setup the arguments required by the finder library.
1. The call to `add_did_finder_cnd_arguments` to setup the arguments required by the finder library.
2. Parsing of the arguments using the usual `parse_args` method
3. Passing the parsed arguments to `start_did_finder`.

Expand Down
2 changes: 1 addition & 1 deletion src/servicex_did_finder_lib/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '1.0.0a1'

from .communication import start_did_finder, \
default_command_line_args # NOQA
add_did_finder_cnd_arguments # NOQA
22 changes: 11 additions & 11 deletions src/servicex_did_finder_lib/communication.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ def rabbit_mq_callback(user_callback: UserDIDHandler, channel, method, propertie
properties ([type]): Properties of the message
body ([type]): The body (json for us) of the message
'''
request_id = None # set this in case we get an exception while loading request
try:
# Unpack the message. Really bad if we fail up here!
request_id = None # set this in case we get an exception while loading request
did_request = json.loads(body)
did = did_request['did']
request_id = did_request['request_id']
Expand Down Expand Up @@ -137,8 +137,8 @@ def init_rabbit_mq(user_callback: UserDIDHandler,
raise


def default_command_line_args(parser: argparse.ArgumentParser):
'''default_command_line_args Add required arguments to a parser
def add_did_finder_cnd_arguments(parser: argparse.ArgumentParser):
'''add_did_finder_cnd_arguments Add required arguments to a parser
If you need to parse command line arguments for some special configuration, create your
own argument parser, and call this function to make sure the arguments needed
Expand Down Expand Up @@ -170,18 +170,18 @@ def start_did_finder(did_finder_name: str,
did_name (str): Name of the DID finder (baked into the rabbit mq name)
callback (UserDIDHandler): Callback to handle the DID rendering requests
parser (Optional[argparse.Namespace], optional): If you need to parse your own
command line arguments, create
an arg parser, make sure to call
default_command_line_args, run the
parser and pass in the resulting
parsed arguments.
Defaults to None (automatically
parses)
an arg parser, make sure to call
add_did_finder_cnd_arguments, run the
parser and pass in the resulting
parsed arguments.
Defaults to None (automatically
parses)
command line arguments, create
'''
# Setup command line parsing
if parsed_args is None:
parser = argparse.ArgumentParser()
default_command_line_args(parser)
add_did_finder_cnd_arguments(parser)
parsed_args = parser.parse_args()

# Initialize the root logger
Expand Down
4 changes: 2 additions & 2 deletions tests/servicex_did_finder_lib/test_communication.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import pika
import pytest
from servicex_did_finder_lib.communication import (default_command_line_args,
from servicex_did_finder_lib.communication import (add_did_finder_cnd_arguments,
init_rabbit_mq,
start_did_finder)

Expand Down Expand Up @@ -205,7 +205,7 @@ def test_arg_required(init_rabbit_callback):
'Make sure the argument passed on the command line makes it in'
# This option is only available in 3.9, so for less than 3.9 we can't run this test.
parser = argparse.ArgumentParser()
default_command_line_args(parser)
add_did_finder_cnd_arguments(parser)
parser.add_argument('--dude', dest="sort_it", action='store')

args = parser.parse_args(['--rabbit-uri', 'not-really-there'])
Expand Down

0 comments on commit ee5bee1

Please sign in to comment.