Skip to content

Commit

Permalink
fix(work): added pipeline name reformatting
Browse files Browse the repository at this point in the history
  • Loading branch information
shinybrar committed Mar 16, 2023
1 parent 1e40eef commit b3f791b
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions chime_frb_api/workflow/work.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,15 +383,31 @@ class Config:
@root_validator
def post_init(cls, values: Dict[str, Any]):
"""Initialize work attributes after validation."""
# Change pipeline to be lowercase and replace spaces/underscores with dashes
# Check if the pipeline name has uppercase, spaces, or underscores
if values["pipeline"].isupper():
warn(SyntaxWarning("pipeline reformatted to lowercase"), stacklevel=2)
values["pipeline"] = values["pipeline"].lower()
# Check if the pipeline name has any character that is uppercase
reformatted: bool = False
for char in values["pipeline"]:
if char.isupper():
values["pipeline"] = values["pipeline"].lower()
reformatted = True
break

if " " or "_" in values["pipeline"]:
warn(SyntaxWarning("pipeline reformatted to use dashes"), stacklevel=2)
values["pipeline"] = values["pipeline"].replace(" ", "-")
values["pipeline"] = values["pipeline"].replace("_", "-")
reformatted = True

# Check if the pipeline has any character that is not alphanumeric or dash
for char in values["pipeline"]:
if not char.isalnum() and char not in ["-"]:
raise ValueError(
"pipeline name can only contain letters, numbers & dashes"
)

if reformatted:
warn(
SyntaxWarning(f"pipeline reformatted to {values['pipeline']}"),
stacklevel=2,
)

# Set creation time if not already set
if values.get("creation") is None:
Expand Down

0 comments on commit b3f791b

Please sign in to comment.