slurm-cli 1.0.4__tar.gz → 1.0.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. {slurm_cli-1.0.4 → slurm_cli-1.0.5}/PKG-INFO +1 -1
  2. {slurm_cli-1.0.4 → slurm_cli-1.0.5}/pyproject.toml +1 -1
  3. {slurm_cli-1.0.4 → slurm_cli-1.0.5}/src/slurm_cli/utils/accounts.py +4 -5
  4. {slurm_cli-1.0.4 → slurm_cli-1.0.5}/src/slurm_cli/utils/associations.py +4 -5
  5. {slurm_cli-1.0.4 → slurm_cli-1.0.5}/src/slurm_cli/utils/jobs.py +3 -3
  6. {slurm_cli-1.0.4 → slurm_cli-1.0.5}/src/slurm_cli/utils/nodes.py +5 -7
  7. {slurm_cli-1.0.4 → slurm_cli-1.0.5}/src/slurm_cli/utils/partitions.py +5 -7
  8. {slurm_cli-1.0.4 → slurm_cli-1.0.5}/src/slurm_cli/utils/profiles.py +47 -10
  9. {slurm_cli-1.0.4 → slurm_cli-1.0.5}/src/slurm_cli/utils/qos.py +3 -6
  10. {slurm_cli-1.0.4 → slurm_cli-1.0.5}/src/slurm_cli/utils/reservations.py +7 -6
  11. {slurm_cli-1.0.4 → slurm_cli-1.0.5}/LICENSE +0 -0
  12. {slurm_cli-1.0.4 → slurm_cli-1.0.5}/README.md +0 -0
  13. {slurm_cli-1.0.4 → slurm_cli-1.0.5}/src/slurm_cli/__init__.py +0 -0
  14. {slurm_cli-1.0.4 → slurm_cli-1.0.5}/src/slurm_cli/cli.py +0 -0
  15. {slurm_cli-1.0.4 → slurm_cli-1.0.5}/src/slurm_cli/py.typed +0 -0
  16. {slurm_cli-1.0.4 → slurm_cli-1.0.5}/src/slurm_cli/utils/__init__.py +0 -0
  17. {slurm_cli-1.0.4 → slurm_cli-1.0.5}/src/slurm_cli/utils/autocomplete_helpers.py +0 -0
  18. {slurm_cli-1.0.4 → slurm_cli-1.0.5}/src/slurm_cli/utils/base_resource.py +0 -0
  19. {slurm_cli-1.0.4 → slurm_cli-1.0.5}/src/slurm_cli/utils/config.py +0 -0
  20. {slurm_cli-1.0.4 → slurm_cli-1.0.5}/src/slurm_cli/utils/coordinators.py +0 -0
  21. {slurm_cli-1.0.4 → slurm_cli-1.0.5}/src/slurm_cli/utils/events.py +0 -0
  22. {slurm_cli-1.0.4 → slurm_cli-1.0.5}/src/slurm_cli/utils/job_filter.py +0 -0
  23. {slurm_cli-1.0.4 → slurm_cli-1.0.5}/src/slurm_cli/utils/node_filter.py +0 -0
  24. {slurm_cli-1.0.4 → slurm_cli-1.0.5}/src/slurm_cli/utils/prefix_utils.py +0 -0
  25. {slurm_cli-1.0.4 → slurm_cli-1.0.5}/src/slurm_cli/utils/resources.py +0 -0
  26. {slurm_cli-1.0.4 → slurm_cli-1.0.5}/src/slurm_cli/utils/slurm_config.py +0 -0
  27. {slurm_cli-1.0.4 → slurm_cli-1.0.5}/src/slurm_cli/utils/users.py +0 -0
  28. {slurm_cli-1.0.4 → slurm_cli-1.0.5}/src/slurm_cli/utils/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: slurm-cli
3
- Version: 1.0.4
3
+ Version: 1.0.5
4
4
  Summary: A CLI tool for Slurm cluster management with autocomplete functionality
5
5
  License: MIT
6
6
  License-File: LICENSE
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "slurm-cli"
3
- version = "1.0.4"
3
+ version = "1.0.5"
4
4
  description = "A CLI tool for Slurm cluster management with autocomplete functionality"
5
5
  authors = ["Sergey Zhumatiy <szhumatiy@gmail.com>"]
6
6
  maintainers = ["Sergey Zhumatiy <szhumatiy@gmail.com>"]
@@ -9,7 +9,7 @@ from rich.table import Table
9
9
 
10
10
  from .base_resource import BaseSlurmResource
11
11
  from .profiles import (
12
- format_with_template,
12
+ format_rows,
13
13
  get_profile_config,
14
14
  sort_data,
15
15
  sort_hierarchical_data,
@@ -461,10 +461,9 @@ _slurm_cli_accounts_autocomplete() {{
461
461
  else: # pretty style
462
462
  # If template is specified, use template-based output
463
463
  if template:
464
- for account in accounts:
465
- output = format_with_template(
466
- template, account, resource="accounts"
467
- )
464
+ for output in format_rows(
465
+ template, accounts, resource="accounts"
466
+ ):
468
467
  console.print(output)
469
468
  else:
470
469
  # Create a rich table
@@ -11,7 +11,7 @@ from rich.table import Table
11
11
 
12
12
  from .base_resource import BaseSlurmResource
13
13
  from .profiles import (
14
- format_with_template,
14
+ format_rows,
15
15
  get_profile_config,
16
16
  sort_data,
17
17
  sort_hierarchical_data,
@@ -619,10 +619,9 @@ _slurm_cli_associations_autocomplete() {{
619
619
  else: # pretty style
620
620
  # If template is specified, use template-based output
621
621
  if template:
622
- for assoc in associations:
623
- output = format_with_template(
624
- template, assoc, resource="associations"
625
- )
622
+ for output in format_rows(
623
+ template, associations, resource="associations"
624
+ ):
626
625
  console.print(output)
627
626
  else:
628
627
  # Create a rich table
@@ -9,7 +9,7 @@ from rich.box import SIMPLE_HEAVY
9
9
  from rich.table import Table
10
10
 
11
11
  from .base_resource import BaseSlurmResource
12
- from .profiles import format_with_template, get_profile_config, sort_data
12
+ from .profiles import format_rows, get_profile_config, sort_data
13
13
  from .utils import console
14
14
 
15
15
 
@@ -546,8 +546,8 @@ class Job(BaseSlurmResource):
546
546
  print(delimiter.join(row))
547
547
  elif template:
548
548
  # Template-based output
549
- for job in jobs:
550
- console.print(format_with_template(template, job))
549
+ for output in format_rows(template, jobs):
550
+ console.print(output)
551
551
  else:
552
552
  # Pretty table output
553
553
  table = Table(
@@ -9,7 +9,7 @@ from rich.markup import escape
9
9
  from rich.table import Table
10
10
 
11
11
  from .base_resource import BaseSlurmResource
12
- from .profiles import format_with_template, get_profile_config, sort_data
12
+ from .profiles import format_rows, get_profile_config, sort_data
13
13
  from .utils import console
14
14
 
15
15
 
@@ -416,12 +416,10 @@ _slurm_cli_nodes_autocomplete() {{
416
416
  elif template_cfg and style == "pretty":
417
417
  # Use template-based output (e.g., oneline profile)
418
418
  nodes_to_show = {name: data[name]} if name and name in data else data
419
- for node_name, node_data in sorted(nodes_to_show.items()):
420
- # Prepare data with name included
421
- prepared = {"name": node_name, **node_data}
422
- output = format_with_template(
423
- template_cfg, prepared, resource="nodes"
424
- )
419
+ prepared = [
420
+ {"name": n, **d} for n, d in sorted(nodes_to_show.items())
421
+ ]
422
+ for output in format_rows(template_cfg, prepared, resource="nodes"):
425
423
  console.print(output)
426
424
  elif columns_cfg and columns_cfg != "*" and style == "pretty":
427
425
  # Use column-based table output (e.g., compact, minimal)
@@ -9,7 +9,7 @@ from rich.markup import escape
9
9
  from rich.table import Table
10
10
 
11
11
  from .base_resource import BaseSlurmResource
12
- from .profiles import format_with_template, get_profile_config, sort_data
12
+ from .profiles import format_rows, get_profile_config, sort_data
13
13
 
14
14
  # from .resources import Resource, ResourceType
15
15
  from .utils import console
@@ -453,12 +453,10 @@ class Partition(BaseSlurmResource):
453
453
  elif template_cfg and style == "pretty":
454
454
  # Use template-based output (e.g., oneline profile)
455
455
  partitions_to_show = {name: data[name]} if name and name in data else data
456
- for part_name, part_data in sorted(partitions_to_show.items()):
457
- # Prepare data with PartitionName included
458
- prepared = {"PartitionName": part_name, **part_data}
459
- output = format_with_template(
460
- template_cfg, prepared, resource="partitions"
461
- )
456
+ prepared = [
457
+ {"PartitionName": n, **d} for n, d in sorted(partitions_to_show.items())
458
+ ]
459
+ for output in format_rows(template_cfg, prepared, resource="partitions"):
462
460
  console.print(output)
463
461
  elif columns_cfg and columns_cfg != "*" and style == "pretty":
464
462
  # Use column-based table output (e.g., compact, minimal)
@@ -39,7 +39,7 @@ Template syntax:
39
39
  import os
40
40
  import re
41
41
  from pathlib import Path
42
- from typing import Any, Callable, Dict, List, Optional, Tuple, Union
42
+ from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple, Union
43
43
 
44
44
  # Profile file locations (in order of precedence, later overrides earlier)
45
45
  PROFILE_FILES = [
@@ -951,11 +951,16 @@ def is_field_empty(
951
951
  return False
952
952
 
953
953
 
954
+ # {field} or {field:[-+=]N[!][+]}
955
+ FIELD_PATTERN = re.compile(r"\{(\w+)(?::([-+=]?)(\d+)(!?)(\+?))?\}")
956
+
957
+
954
958
  def format_with_template(
955
959
  template: str,
956
960
  data: Dict[str, Any],
957
961
  value_formatter: Optional[Callable[[str, Any], str]] = None,
958
962
  resource: Optional[str] = None,
963
+ min_widths: Optional[Dict[str, int]] = None,
959
964
  ) -> str:
960
965
  """Format data using a template string.
961
966
 
@@ -967,6 +972,11 @@ def format_with_template(
967
972
 
968
973
  Template syntax:
969
974
  {field} - replaced with field value
975
+ {field:WIDTH} - padded to WIDTH; WIDTH = [-|+|=]N[!][+]
976
+ '-' left (default), '+' right, '=' center;
977
+ '!' truncates longer values;
978
+ '+' postfix: N is a minimum, the actual width is
979
+ the max over all rows (see format_rows)
970
980
  {?field TEXT} - show TEXT only if field is not empty
971
981
  TEXT can contain {field} placeholders
972
982
 
@@ -996,10 +1006,7 @@ def format_with_template(
996
1006
  result = conditional_pattern.sub(replace_conditional, result)
997
1007
 
998
1008
  # Now process regular {field} placeholders
999
- field_pattern = re.compile(r"\{(\w+)\}")
1000
-
1001
- def replace_field(match: re.Match) -> str:
1002
- field = match.group(1)
1009
+ def render(field: str) -> str:
1003
1010
  value = data.get(field)
1004
1011
 
1005
1012
  if value is None:
@@ -1022,7 +1029,34 @@ def format_with_template(
1022
1029
 
1023
1030
  return str(value) if value != "" else "-"
1024
1031
 
1025
- return field_pattern.sub(replace_field, result)
1032
+ def replace_field(match: re.Match) -> str:
1033
+ text = render(match.group(1))
1034
+ if match.group(3) is None:
1035
+ return text
1036
+ align, width = match.group(2), int(match.group(3))
1037
+ if match.group(5): # minimum width: widest value over all rows
1038
+ if min_widths is not None:
1039
+ key = match.group(0)
1040
+ min_widths[key] = max(min_widths.get(key, width), len(text))
1041
+ width = min_widths[key]
1042
+ width = max(width, len(text))
1043
+ elif match.group(4):
1044
+ text = text[:width]
1045
+ return {"+": text.rjust, "=": text.center}.get(align, text.ljust)(width)
1046
+
1047
+ return FIELD_PATTERN.sub(replace_field, result)
1048
+
1049
+
1050
+ def format_rows(template: str, rows: Iterable[Dict[str, Any]], **kwargs) -> List[str]:
1051
+ """Format every row; '+'-postfix widths ({f:10+}) are shared by all rows."""
1052
+ rows = list(rows)
1053
+ widths: Dict[str, int] = {}
1054
+ for row in rows: # first pass only collects widths
1055
+ format_with_template(template, row, min_widths=widths, **kwargs)
1056
+ return [
1057
+ format_with_template(template, row, min_widths=widths, **kwargs)
1058
+ for row in rows
1059
+ ]
1026
1060
 
1027
1061
 
1028
1062
  def extract_fields_from_template(template: str) -> List[str]:
@@ -1035,10 +1069,8 @@ def extract_fields_from_template(template: str) -> List[str]:
1035
1069
  List of field names found in the template
1036
1070
  """
1037
1071
  # Match both regular {field} and conditional {?field ...}
1038
- pattern = re.compile(r"\{(\w+)\}|\{\?(\w+)\s+")
1039
- matches = pattern.findall(template)
1040
- # Flatten and filter empty strings
1041
- return [m[0] or m[1] for m in matches if m[0] or m[1]]
1072
+ pattern = re.compile(r"\{(\w+)(?::[-+=]?\d+!?\+?)?\}|\{\?(\w+)\s+")
1073
+ return [m[0] or m[1] for m in pattern.findall(template)]
1042
1074
 
1043
1075
 
1044
1076
  def _get_resource_fields() -> Dict[str, Dict[str, str]]:
@@ -1130,9 +1162,13 @@ def show_profile_help(resource: str) -> bool:
1130
1162
  print()
1131
1163
  print("Template syntax:")
1132
1164
  print(" {field} - Show field value")
1165
+ print(" {field:WIDTH} - Pad field; WIDTH=[-|+|=]N[!][+] (see below)")
1133
1166
  print(" {?field TEXT} - Show TEXT only if field is not empty")
1134
1167
  print(" [color]...[/] - Rich markup for colors")
1135
1168
  print(" \\n - Newline")
1169
+ print("WIDTH: prefix - left (default), + right, = center; N is the width;")
1170
+ print(" postfix ! truncates longer values; postfix + makes N a minimum")
1171
+ print(" (actual width = widest value over all rows). Example: {name:-12+}")
1136
1172
  print()
1137
1173
  print("Example:")
1138
1174
  print(' --profile-str "[cyan]{name}[/] - description"')
@@ -1165,6 +1201,7 @@ def show_all_profile_fields() -> None:
1165
1201
  print(" field- - Sort descending by field")
1166
1202
  print("\nTemplate syntax:")
1167
1203
  print(" {field} - Show field value")
1204
+ print(" {field:WIDTH} - Pad field; WIDTH=[-|+|=]N[!][+]")
1168
1205
  print(" {?field TEXT} - Show TEXT only if field is not empty")
1169
1206
  print(" [color]...[/] - Rich markup for colors")
1170
1207
  print(" \\n - Newline")
@@ -8,7 +8,7 @@ from rich.box import SIMPLE_HEAVY
8
8
  from rich.table import Table
9
9
 
10
10
  from .base_resource import BaseSlurmResource
11
- from .profiles import format_with_template, get_profile_config, sort_data
11
+ from .profiles import format_rows, get_profile_config, sort_data
12
12
  from .utils import console
13
13
 
14
14
  # QoS configuration options (sacctmgr field names)
@@ -392,11 +392,8 @@ class Qos(BaseSlurmResource):
392
392
  console.print_json(json.dumps({"qos": qos_list}, indent=2))
393
393
  elif template_cfg and style == "pretty":
394
394
  # Use template-based output
395
- for qos in qos_list:
396
- prepared = cls._prepare_template_data(qos)
397
- output = format_with_template(
398
- template_cfg, prepared, resource="qos"
399
- )
395
+ prepared = [cls._prepare_template_data(q) for q in qos_list]
396
+ for output in format_rows(template_cfg, prepared, resource="qos"):
400
397
  console.print(output)
401
398
  elif style in ["csv", "pretty"]:
402
399
  # Column definitions (used by both CSV and pretty styles)
@@ -8,7 +8,7 @@ from typing import Any, Dict, Optional, Union
8
8
  from rich.markup import escape
9
9
 
10
10
  from .base_resource import BaseSlurmResource
11
- from .profiles import format_with_template, get_profile_config, sort_data
11
+ from .profiles import format_rows, format_with_template, get_profile_config, sort_data
12
12
 
13
13
  # from .resources import Resource
14
14
  from .utils import console
@@ -307,11 +307,12 @@ class Reservation(BaseSlurmResource):
307
307
  )
308
308
  console.print(output)
309
309
  else:
310
- for res_name, res_data in data.items():
311
- prepared = cls._prepare_template_data(res_name, res_data)
312
- output = format_with_template(
313
- template, prepared, resource="reservations"
314
- )
310
+ prepared = [
311
+ cls._prepare_template_data(n, d) for n, d in data.items()
312
+ ]
313
+ for output in format_rows(
314
+ template, prepared, resource="reservations"
315
+ ):
315
316
  console.print(output)
316
317
  else: # default pretty style
317
318
  if name:
File without changes
File without changes