Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion devops/scripts/benchmarks/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,12 @@ def validate_and_parse_env_args(env_args):
)
parser.add_argument(
"--save",
type=str,
type=lambda save: Validate.save_name(
save,
throw=argparse.ArgumentTypeError(
"Specified save name is not within characters [a-zA-Z0-9_-]."
),
),
help="Save the results for comparison under a specified name.",
)
parser.add_argument(
Expand Down
20 changes: 15 additions & 5 deletions devops/scripts/benchmarks/utils/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,17 @@ def runner_name(runner_name: str, throw: Exception = None):
"""
Returns True if runner_name is clean (no illegal characters).
"""
return validate_on_re(runner_name, r"^[a-zA-Z0-9_]+$", throw=throw)
return validate_on_re(runner_name.strip(), r"^[a-zA-Z0-9_]+$", throw=throw)

@staticmethod
def save_name(save: str, throw: Exception = None):
"""
Returns True if save is within [a-zA-Z0-9_-].

If throw argument is specified: return save as is if save satisfies
aforementioned regex, otherwise raise error defined by throw.
"""
return validate_on_re(save.strip(), r"^[a-zA-Z0-9_-]+$", throw=throw)

@staticmethod
def timestamp(t: str, throw: Exception = None):
Expand All @@ -37,7 +47,7 @@ def timestamp(t: str, throw: Exception = None):
format, otherwise raise error defined by throw.
"""
return validate_on_re(
t,
t.strip(),
r"^\d{4}(0[1-9]|1[0-2])([0-2][0-9]|3[01])_([01][0-9]|2[0-3])[0-5][0-9][0-5][0-9]$",
throw=throw,
)
Expand All @@ -51,7 +61,7 @@ def github_repo(repo: str, throw: Exception = None):
aforementioned format, otherwise raise error defined by throw.
"""
return validate_on_re(
re.sub(r"^https?://github.com/", "", repo),
re.sub(r"^https?://github.com/", "", repo.strip()),
r"^[a-zA-Z0-9_-]{1,39}/[a-zA-Z0-9_.-]{1,100}$",
throw=throw,
)
Expand All @@ -67,6 +77,6 @@ def commit_hash(commit: str, throw: Exception = None, trunc: int = 40):
"""
commit_re = r"^[a-f0-9]{7,40}$"
if throw is None:
return validate_on_re(commit, commit_re)
return validate_on_re(commit.strip(), commit_re)
else:
return validate_on_re(commit, commit_re, throw=throw)[:trunc]
return validate_on_re(commit.strip(), commit_re, throw=throw)[:trunc]