From 2e9ee8c0052d96045588e617c9e5de017f30454a Mon Sep 17 00:00:00 2001 From: tvalentyn Date: Wed, 21 Apr 2021 20:18:29 -0700 Subject: [PATCH] [BEAM-2085] Fixups for Python resource hints. (#14605) --- sdks/python/apache_beam/options/pipeline_options.py | 1 + sdks/python/apache_beam/transforms/resources.py | 10 ++++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/sdks/python/apache_beam/options/pipeline_options.py b/sdks/python/apache_beam/options/pipeline_options.py index e9cbd96b9a29..449c7d336bda 100644 --- a/sdks/python/apache_beam/options/pipeline_options.py +++ b/sdks/python/apache_beam/options/pipeline_options.py @@ -447,6 +447,7 @@ def _add_argparse_args(cls, parser): parser.add_argument( '--resource_hint', + '--resource_hints', dest='resource_hints', action='append', default=[], diff --git a/sdks/python/apache_beam/transforms/resources.py b/sdks/python/apache_beam/transforms/resources.py index 10a32855e80e..e201b6488764 100644 --- a/sdks/python/apache_beam/transforms/resources.py +++ b/sdks/python/apache_beam/transforms/resources.py @@ -94,7 +94,7 @@ def register_resource_hint( @staticmethod def _parse_str(value): if not isinstance(value, str): - raise ValueError() + raise ValueError("Input must be a string.") return value.encode('ascii') @staticmethod @@ -102,7 +102,7 @@ def _parse_int(value): if isinstance(value, str): value = int(value) if not isinstance(value, int): - raise ValueError() + raise ValueError("Input must be an integer.") return str(value).encode('ascii') @staticmethod @@ -113,7 +113,7 @@ def _parse_storage_size_str(value): return ResourceHint._parse_int(value) if not isinstance(value, str): - raise ValueError() + raise ValueError("Input must be a string or integer.") value = value.strip().replace(" ", "") units = { @@ -131,9 +131,11 @@ def _parse_storage_size_str(value): } match = re.match(r'.*?(\D+)$', value) if not match: - raise ValueError() + raise ValueError("Unrecognized value pattern.") suffix = match.group(1) + if suffix not in units: + raise ValueError("Unrecognized unit.") multiplier = units[suffix] value = value[:-len(suffix)]