Skip to content
This repository has been archived by the owner on Nov 23, 2023. It is now read-only.

Commit

Permalink
fix: Parse argument values starting with hyphen
Browse files Browse the repository at this point in the history
It is not possible to configure AWS Batch job definition parameters to
pass `--key=Ref::some_argument`
<https://docs.aws.amazon.com/batch/latest/userguide/job_definition_parameters.html#parameters=>,
and `argparse` has a long-standing issue re. not being able to handle
`--key -value`-type key/value pairs
<python/cpython#53580>. The only known
workaround is to use the deprecated `optparse` module.
  • Loading branch information
l0b0 committed Jun 13, 2022
1 parent 9987a37 commit 4b24e1d
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions geostore/check_files_checksums/task.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
from argparse import ArgumentParser, Namespace
from logging import Logger
from optparse import OptionParser, Values # pylint: disable=deprecated-module

from linz_logger import get_log

Expand All @@ -23,17 +23,23 @@
LOGGER: Logger = get_log()


def parse_arguments() -> Namespace:
argument_parser = ArgumentParser()
argument_parser.add_argument(DATASET_ID_ARGUMENT, required=True)
argument_parser.add_argument(NEW_VERSION_ID_ARGUMENT, required=True)
argument_parser.add_argument(CURRENT_VERSION_ID_ARGUMENT, required=True)
argument_parser.add_argument(DATASET_PREFIX_ARGUMENT, required=True)
argument_parser.add_argument(FIRST_ITEM_ARGUMENT, type=int, required=True)
argument_parser.add_argument(RESULTS_TABLE_NAME_ARGUMENT, required=True)
argument_parser.add_argument(ASSETS_TABLE_NAME_ARGUMENT, required=True)
argument_parser.add_argument(S3_ROLE_ARN_ARGUMENT, required=True)
return argument_parser.parse_args()
def parse_arguments() -> Values:
parser = OptionParser()
parser.add_option(DATASET_ID_ARGUMENT)
parser.add_option(NEW_VERSION_ID_ARGUMENT)
parser.add_option(CURRENT_VERSION_ID_ARGUMENT)
parser.add_option(DATASET_PREFIX_ARGUMENT)
parser.add_option(FIRST_ITEM_ARGUMENT, type=int)
parser.add_option(RESULTS_TABLE_NAME_ARGUMENT)
parser.add_option(ASSETS_TABLE_NAME_ARGUMENT)
parser.add_option(S3_ROLE_ARN_ARGUMENT)
(options, _args) = parser.parse_args()

for option in parser.option_list:
if option.dest is not None:
assert hasattr(options, option.dest)

return options


def main() -> None:
Expand Down

0 comments on commit 4b24e1d

Please sign in to comment.