Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when parsing variable names with spaces #810

Closed
jwarner8 opened this issue Aug 23, 2024 · 2 comments
Closed

Error when parsing variable names with spaces #810

jwarner8 opened this issue Aug 23, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@jwarner8
Copy link
Contributor

Describe the bug

If variable names include spaces, CYLC cannot parse this into the workflow (spaces are not permitted).

How to reproduce

Etc. for variable "Turbulent mixing height after boundary layer", produces the following error during validation:

GraphParseError: Illegal graph node: collate_deterministic_domain_surface_histogram_series_.Turbulent mixing height after boundary layer

Expected behaviour

Could add another parser that replaces spaces with an underscore.

Environment

  • Version: [e.g. from cset --version]
  • Browser (if UI issue): [e.g. Chrome, Firefox]
@jwarner8 jwarner8 added the bug Something isn't working label Aug 23, 2024
@jfrost-mo
Copy link
Member

jfrost-mo commented Aug 23, 2024

This is fixed in #765, as I've added a proper task name sanitiser:

def sanitise_task_name(s: str):
"""Sanitise a string to be used as a Cylc task name.
Rules per
https://cylc.github.io/cylc-doc/stable/html/user-guide/writing-workflows/runtime.html#cylc.flow.unicode_rules.TaskNameValidator
The rules for valid task and family names:
* must start with: alphanumeric
* can only contain: alphanumeric, _, -, +, %, @
* cannot start with: _cylc
* cannot be: root
Note that actually there are a few more characters supported, see:
https://github.com/cylc/cylc-flow/issues/6288
"""
# Ensure we have a string.
if not isinstance(s, str):
s = str(s)
# Ensure the first character is alphanumeric.
if not s[0].isalnum():
s = f"sanitised_{s}"
# Specifically replace `.` with `p`, as in 3p5.
s = s.replace(".", "p")
# Replace invalid characters with underscores.
s = "".join(c if c.isalnum() or c in "-+%@" else "_" for c in s)
# Ensure the name is not a reserved name.
if s.lower() == "root":
s = f"sanitised_{s}"
# Ensure the name does not start with "_cylc".
if s.lower().startswith("_cylc"):
s = f"sanitised_{s}"
return s

@jwarner8
Copy link
Contributor Author

Nice! Upcoming fix in #765 so closing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants