Skip to content

Commit

Permalink
Remove the overwriting of sys.argv
Browse files Browse the repository at this point in the history
There's no need to do this since argparse can accept a list of
arguments, and it doesn't seem like a good idea to overwrite the list of
arguments provided.
  • Loading branch information
nbelakovski-mssm committed Jul 29, 2024
1 parent ca0fda1 commit ec1aa5d
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 48 deletions.
2 changes: 1 addition & 1 deletion pynetdicom/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@
else:
app_path = _APPS[args[0]]
app = importlib.import_module(app_path)
app.main(args)
app.main(args[1:])
10 changes: 4 additions & 6 deletions pynetdicom/apps/echoscp/echoscp.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@
__version__ = "0.7.0"


def _setup_argparser():
def _setup_argparser(args=None):
"""Setup the command line arguments"""
# Description
parser = argparse.ArgumentParser(
prog="echoscp",
description=(
"The echoscp application implements a Service Class "
"Provider (SCP) for the Verification SOP Class. It "
Expand Down Expand Up @@ -160,7 +161,7 @@ def _setup_argparser():
action="store_true",
)

return parser.parse_args()
return parser.parse_args(args)


def handle_echo(event):
Expand All @@ -173,10 +174,7 @@ def handle_echo(event):

def main(args=None):
"""Run the application."""
if args is not None:
sys.argv = args

args = _setup_argparser()
args = _setup_argparser(args)

if args.version:
print(f"echoscp.py v{__version__}")
Expand Down
10 changes: 4 additions & 6 deletions pynetdicom/apps/echoscu/echoscu.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@
__version__ = "0.7.0"


def _setup_argparser():
def _setup_argparser(args=None):
"""Setup the command line arguments"""
# Description
parser = argparse.ArgumentParser(
prog="echoscu",
description=(
"The echoscu application implements a Service Class User "
"(SCU) for the Verification Service Class. It sends a DICOM "
Expand Down Expand Up @@ -171,15 +172,12 @@ def _setup_argparser():
"--abort", help="abort association instead of releasing it", action="store_true"
)

return parser.parse_args()
return parser.parse_args(args)


def main(args=None):
"""Run the application."""
if args is not None:
sys.argv = args

args = _setup_argparser()
args = _setup_argparser(args)

if args.version:
print(f"echoscu.py v{__version__}")
Expand Down
10 changes: 4 additions & 6 deletions pynetdicom/apps/findscu/findscu.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@
__version__ = "0.2.0"


def _setup_argparser():
def _setup_argparser(args=None):
"""Setup the command line arguments"""
# Description
parser = argparse.ArgumentParser(
prog="findscu",
description=(
"The findscu application implements a Service Class User "
"(SCU) for the Query/Retrieve (QR) and Basic Worklist Management "
Expand Down Expand Up @@ -241,7 +242,7 @@ def _setup_argparser():
action="store_true",
)

ns = parser.parse_args()
ns = parser.parse_args(args)
if ns.version:
pass
elif not bool(ns.file) and not bool(ns.keyword):
Expand Down Expand Up @@ -275,10 +276,7 @@ def generate_filename():

def main(args=None):
"""Run the application."""
if args is not None:
sys.argv = args

args = _setup_argparser()
args = _setup_argparser(args)

if args.version:
print(f"findscu.py v{__version__}")
Expand Down
10 changes: 4 additions & 6 deletions pynetdicom/apps/getscu/getscu.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@
__version__ = "0.4.0"


def _setup_argparser():
def _setup_argparser(args):
"""Setup the command line arguments"""
# Description
parser = argparse.ArgumentParser(
prog="getscu",
description=(
"The getscu application implements a Service Class User "
"(SCU) for the Query/Retrieve (QR) Service Class. getscu only "
Expand Down Expand Up @@ -214,7 +215,7 @@ def _setup_argparser():
"--ignore", help="receive data but don't store it", action="store_true"
)

ns = parser.parse_args()
ns = parser.parse_args(args)
if ns.version:
pass
elif not bool(ns.file) and not bool(ns.keyword):
Expand All @@ -225,10 +226,7 @@ def _setup_argparser():

def main(args=None):
"""Run the application."""
if args is not None:
sys.argv = args

args = _setup_argparser()
args = _setup_argparser(args)

if args.version:
print(f"getscu.py v{__version__}")
Expand Down
10 changes: 4 additions & 6 deletions pynetdicom/apps/movescu/movescu.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@
__version__ = "0.4.0"


def _setup_argparser():
def _setup_argparser(args=None):
"""Setup the command line arguments"""
# Description
parser = argparse.ArgumentParser(
prog="movescu",
description=(
"The movescu application implements a Service Class User (SCU) "
"for the Query/Retrieve (QR) Service Class and (optionally) a "
Expand Down Expand Up @@ -247,7 +248,7 @@ def _setup_argparser():
"--ignore", help="receive data but don't store it", action="store_true"
)

ns = parser.parse_args()
ns = parser.parse_args(args)
if ns.version:
pass
elif not bool(ns.file) and not bool(ns.keyword):
Expand All @@ -258,10 +259,7 @@ def _setup_argparser():

def main(args=None):
"""Run the application."""
if args is not None:
sys.argv = args

args = _setup_argparser()
args = _setup_argparser(args)

if args.version:
print(f"movescu.py v{__version__}")
Expand Down
10 changes: 4 additions & 6 deletions pynetdicom/apps/qrscp/qrscp.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,11 @@ def _log_config(config, logger):
logger.debug("")


def _setup_argparser():
def _setup_argparser(args=None):
"""Setup the command line arguments"""
# Description
parser = argparse.ArgumentParser(
prog="qrscp",
description=(
"The qrscp application implements a Service Class Provider (SCP) "
"for the Verification, Storage and Query/Retrieve (QR) Service "
Expand Down Expand Up @@ -218,7 +219,7 @@ def _setup_argparser():
action="store_true",
)

return parser.parse_args()
return parser.parse_args(args)


def clean(db_path, instance_path, logger):
Expand Down Expand Up @@ -289,10 +290,7 @@ def clean(db_path, instance_path, logger):

def main(args=None):
"""Run the application."""
if args is not None:
sys.argv = args

args = _setup_argparser()
args = _setup_argparser(args)

if args.version:
print(f"qrscp.py v{__version__}")
Expand Down
9 changes: 4 additions & 5 deletions pynetdicom/apps/storescp/storescp.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@
__version__ = "0.6.0"


def _setup_argparser():
def _setup_argparser(args=None):
"""Setup the command line arguments"""
# Description
parser = argparse.ArgumentParser(
prog="storescp",
description=(
"The storescp application implements a Service Class "
"Provider (SCP) for the Storage and Verification SOP Classes. It "
Expand Down Expand Up @@ -185,15 +186,13 @@ def _setup_argparser():
"--no-echo", help="don't act as a verification SCP", action="store_true"
)

return parser.parse_args()
return parser.parse_args(args)


def main(args=None):
"""Run the application."""
if args is not None:
sys.argv = args
args = _setup_argparser(args)

args = _setup_argparser()
if args.version:
print(f"storescp.py v{__version__}")
sys.exit()
Expand Down
10 changes: 4 additions & 6 deletions pynetdicom/apps/storescu/storescu.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@
__version__ = "0.3.0"


def _setup_argparser():
def _setup_argparser(args=None):
"""Setup the command line arguments"""
# Description
parser = argparse.ArgumentParser(
prog="storescu",
description=(
"The storescu application implements a Service Class User "
"(SCU) for the Storage Service Class. For each DICOM "
Expand Down Expand Up @@ -189,7 +190,7 @@ def _setup_argparser():
action="store_true",
)

return parser.parse_args()
return parser.parse_args(args)


def get_contexts(fpaths, app_logger):
Expand Down Expand Up @@ -238,10 +239,7 @@ def get_contexts(fpaths, app_logger):

def main(args=None):
"""Run the application."""
if args is not None:
sys.argv = args

args = _setup_argparser()
args = _setup_argparser(args)

if args.version:
print(f"storescu.py v{__version__}")
Expand Down

0 comments on commit ec1aa5d

Please sign in to comment.