Skip to content

Commit

Permalink
review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
alexhroom committed Nov 12, 2024
1 parent 871ea62 commit 94e0b38
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions rascal2/widgets/project/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,23 +304,25 @@ def validate_draft_project(self):
layer_attrs.remove("name")
layer_attrs.remove("hydrate_with")
# ensure all layer parameters have been filled in, and all names are layers that exist
valid_params = [p.name for p in self.draft_project["parameters"]]
for i, layer in enumerate(self.draft_project["layers"]):
missing_params = [p for p in layer_attrs if getattr(layer, p) == ""]
invalid_params = [
(p, v)
for p in layer_attrs
if (v := getattr(layer, p)) not in [p.name for p in self.draft_project["parameters"]]
and p not in missing_params
]
missing_params = []
invalid_params = []
for attr in layer_attrs:
param = getattr(layer, attr)
if param == "":
missing_params.append(attr)
elif param not in valid_params:
invalid_params.append((attr, param))

if missing_params:
noun = "a parameter" if len(missing_params) == 1 else "parameters"
msg = f"Layer '{layer.name}' (row {i+1}) is missing {noun}: {', '.join(missing_params)}"
errors.append(msg)
if invalid_params:
noun = "an invalid value" if len(invalid_params) == 1 else "invalid values"
msg = (
f"Layer '{layer.name}' (row {i+1}) has {noun}: "
f"{', '.join(f'"{v}" for parameter {p}' for p, v in invalid_params)}"
msg = f"Layer '{layer.name}' (row {i+1}) has {noun}: " "{0}".format(
",\n ".join(f'"{v}" for parameter {p}' for p, v in invalid_params)
)
errors.append(msg)

Expand Down

0 comments on commit 94e0b38

Please sign in to comment.