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

feat!: Make callbacks and public_key attributes public #5

Merged
merged 3 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "slurmutils"
version = "0.2.0"
version = "0.3.0"
description = "Utilities and APIs for interfacing with the Slurm workload manager."
repository = "https://github.com/canonical/slurmutils"
authors = ["Jason C. Nucciarone <[email protected]>"]
Expand Down
8 changes: 4 additions & 4 deletions slurmutils/editors/_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def parse_model(line: str, pocket: Union[Dict, List], model) -> None:
# Word in front of the first `=` denotes the parent configuration knob key.
option, value = token.split("=", maxsplit=1)
if hasattr(model, attr := _pascal2snake(option)):
if attr in model._callbacks and (callback := model._callbacks[attr].parse) is not None:
if attr in model.callbacks and (callback := model.callbacks[attr].parse) is not None:
holder.update({option: callback(value)})
else:
holder.update({option: value})
Expand Down Expand Up @@ -195,7 +195,7 @@ def marshal_model(
# rely on a mutable default in the function signature.
ignore = set()

if primary_key := model._primary_key:
if primary_key := model.primary_key:
attr = _pascal2snake(primary_key)
primary_value = getattr(model, attr)
data = {primary_key: primary_value, **model.dict()[primary_value]}
Expand All @@ -206,8 +206,8 @@ def marshal_model(
if option not in ignore:
if hasattr(model, attr := _pascal2snake(option)):
if (
attr in model._callbacks
and (callback := model._callbacks[attr].marshal) is not None
attr in model.callbacks
and (callback := model.callbacks[attr].marshal) is not None
):
value = callback(value)

Expand Down
4 changes: 2 additions & 2 deletions slurmutils/models/_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def __repr__(self):

@property
@abstractmethod
def _primary_key(self) -> Optional[str]:
def primary_key(self) -> Optional[str]:
"""Primary key for data model.

A primary key is required for data models that have a unique identifier
Expand All @@ -245,7 +245,7 @@ def _primary_key(self) -> Optional[str]:

@property
@abstractmethod
def _callbacks(self) -> MappingProxyType:
def callbacks(self) -> MappingProxyType:
"""Store callbacks.

This map will be queried during parsing and marshalling to determine if
Expand Down
24 changes: 12 additions & 12 deletions slurmutils/models/slurm.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ def __init__(self, **kwargs):
super().__init__()
self._register.update({kwargs.pop("NodeName"): {**kwargs}})

_primary_key = "NodeName"
_callbacks = MappingProxyType(
primary_key = "NodeName"
callbacks = MappingProxyType(
{
"cpu_spec_list": CommaSeparatorCallback,
"features": CommaSeparatorCallback,
Expand Down Expand Up @@ -91,8 +91,8 @@ class DownNodes(BaseModel):
the slurm.conf manpage. `man slurm.conf.5`
"""

_primary_key = None
_callbacks = MappingProxyType(
primary_key = None
callbacks = MappingProxyType(
{
"down_nodes": CommaSeparatorCallback,
"reason": ReasonCallback,
Expand All @@ -115,8 +115,8 @@ def __init__(self, **kwargs):
super().__init__()
self._register.update({kwargs.pop("FrontendName"): {**kwargs}})

_primary_key = "FrontendName"
_callbacks = MappingProxyType(
primary_key = "FrontendName"
callbacks = MappingProxyType(
{
"allow_groups": CommaSeparatorCallback,
"allow_users": CommaSeparatorCallback,
Expand Down Expand Up @@ -148,8 +148,8 @@ def __init__(self, **kwargs):
super().__init__()
self._register.update({kwargs.pop("NodeSet"): {**kwargs}})

_primary_key = "NodeSet"
_callbacks = MappingProxyType({"nodes": CommaSeparatorCallback})
primary_key = "NodeSet"
callbacks = MappingProxyType({"nodes": CommaSeparatorCallback})

node_set = property(*primary_key_descriptors())
feature = property(*_nodeset_descriptors("Feature"))
Expand All @@ -167,8 +167,8 @@ def __init__(self, **kwargs):
super().__init__()
self._register.update({kwargs.pop("PartitionName"): {**kwargs}})

_primary_key = "PartitionName"
_callbacks = MappingProxyType(
primary_key = "PartitionName"
callbacks = MappingProxyType(
{
"alloc_nodes": CommaSeparatorCallback,
"allow_accounts": CommaSeparatorCallback,
Expand Down Expand Up @@ -465,8 +465,8 @@ class SlurmConfig(BaseModel):
the slurm.conf manpage. `man slurm.conf.5`
"""

_primary_key = None
_callbacks = MappingProxyType(
primary_key = None
callbacks = MappingProxyType(
{
"acct_storage_external_host": CommaSeparatorCallback,
"acct_storage_param": SlurmDictCallback,
Expand Down
4 changes: 2 additions & 2 deletions slurmutils/models/slurmdbd.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class SlurmdbdConfig(BaseModel):
the slurmdbd.conf manpage. `man slurmdbd.conf.5`
"""

_primary_key = None
_callbacks = MappingProxyType(
primary_key = None
callbacks = MappingProxyType(
{
"auth_alt_types": CommaSeparatorCallback,
"auth_alt_parameters": SlurmDictCallback,
Expand Down
5 changes: 1 addition & 4 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,8 @@ commands =
description = Publish slurmutils to PyPI using poetry.
allowlist_externals =
/usr/bin/rm
/usr/bin/poetry
deps =
twine
setuptools
wheel
poetry
commands =
rm -rf {toxinidir}/dist
poetry build
Expand Down
Loading