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

[Enhancement]: Support mapping "yes"/"no" to Python boolean values #22

Open
NucciTheBoss opened this issue Sep 20, 2024 · 0 comments
Open
Labels
Good first issue An issue that does not require domain-specific knowledge to solve. Type: Enhancement Proposes a new feature to be added to the project.

Comments

@NucciTheBoss
Copy link
Member

Slurm configuration format uses "yes"/"no" to represent boolean values, similar to how older versions of YAML did. However, working with the 'Slurmy' boolean values in Python is not straight forward as they are treated as strings when parsed in from Slurm configuration files. To evaluate whether that values are boolean, you must use string operations rather than boolean operations.

if config.constrain_ram_space == "yes":
    print("no more ram for you 0_0")

This isn't ideal as this isn't a True/False evaluation. config.constrain_ram_space can be set to anything here, not just the opposite of "yes" which is "no":

config.constrain_ram_space = "well maybe"
if config.constrain_ram_space == "yes":
    print("no more ram for you 0_0")

cgroupconfig.dump(config, "/etc/slurm/cgroup.conf")  #=> Sadness

The editor won't catch this which will eventually result in borking Slurm.

We should support mapping these values to Python booleans. It should be too difficult as all you need to do is just add a callback in the callback module that just converts the Slurm boolens back and forth:

def to_bool(v: str) -> bool:
    return v.lower() == "yes"


def from_bool(v: bool) -> str:
    return "yes" if v else "no"
@NucciTheBoss NucciTheBoss added Good first issue An issue that does not require domain-specific knowledge to solve. Type: Enhancement Proposes a new feature to be added to the project. labels Sep 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Good first issue An issue that does not require domain-specific knowledge to solve. Type: Enhancement Proposes a new feature to be added to the project.
Projects
None yet
Development

No branches or pull requests

1 participant