slurm-cli 1.0.4__tar.gz → 1.1.1__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 (30) hide show
  1. {slurm_cli-1.0.4 → slurm_cli-1.1.1}/PKG-INFO +1 -1
  2. {slurm_cli-1.0.4 → slurm_cli-1.1.1}/pyproject.toml +1 -1
  3. {slurm_cli-1.0.4 → slurm_cli-1.1.1}/src/slurm_cli/cli.py +191 -2
  4. {slurm_cli-1.0.4 → slurm_cli-1.1.1}/src/slurm_cli/utils/accounts.py +8 -5
  5. {slurm_cli-1.0.4 → slurm_cli-1.1.1}/src/slurm_cli/utils/associations.py +8 -5
  6. {slurm_cli-1.0.4 → slurm_cli-1.1.1}/src/slurm_cli/utils/autocomplete_helpers.py +10 -3
  7. {slurm_cli-1.0.4 → slurm_cli-1.1.1}/src/slurm_cli/utils/jobs.py +13 -7
  8. {slurm_cli-1.0.4 → slurm_cli-1.1.1}/src/slurm_cli/utils/nodes.py +10 -7
  9. slurm_cli-1.1.1/src/slurm_cli/utils/partition_stats.py +461 -0
  10. {slurm_cli-1.0.4 → slurm_cli-1.1.1}/src/slurm_cli/utils/partitions.py +10 -7
  11. {slurm_cli-1.0.4 → slurm_cli-1.1.1}/src/slurm_cli/utils/prefix_utils.py +4 -0
  12. {slurm_cli-1.0.4 → slurm_cli-1.1.1}/src/slurm_cli/utils/profiles.py +224 -13
  13. {slurm_cli-1.0.4 → slurm_cli-1.1.1}/src/slurm_cli/utils/qos.py +8 -6
  14. {slurm_cli-1.0.4 → slurm_cli-1.1.1}/src/slurm_cli/utils/reservations.py +16 -6
  15. slurm_cli-1.1.1/src/slurm_cli/utils/titles.py +170 -0
  16. {slurm_cli-1.0.4 → slurm_cli-1.1.1}/LICENSE +0 -0
  17. {slurm_cli-1.0.4 → slurm_cli-1.1.1}/README.md +0 -0
  18. {slurm_cli-1.0.4 → slurm_cli-1.1.1}/src/slurm_cli/__init__.py +0 -0
  19. {slurm_cli-1.0.4 → slurm_cli-1.1.1}/src/slurm_cli/py.typed +0 -0
  20. {slurm_cli-1.0.4 → slurm_cli-1.1.1}/src/slurm_cli/utils/__init__.py +0 -0
  21. {slurm_cli-1.0.4 → slurm_cli-1.1.1}/src/slurm_cli/utils/base_resource.py +0 -0
  22. {slurm_cli-1.0.4 → slurm_cli-1.1.1}/src/slurm_cli/utils/config.py +0 -0
  23. {slurm_cli-1.0.4 → slurm_cli-1.1.1}/src/slurm_cli/utils/coordinators.py +0 -0
  24. {slurm_cli-1.0.4 → slurm_cli-1.1.1}/src/slurm_cli/utils/events.py +0 -0
  25. {slurm_cli-1.0.4 → slurm_cli-1.1.1}/src/slurm_cli/utils/job_filter.py +0 -0
  26. {slurm_cli-1.0.4 → slurm_cli-1.1.1}/src/slurm_cli/utils/node_filter.py +0 -0
  27. {slurm_cli-1.0.4 → slurm_cli-1.1.1}/src/slurm_cli/utils/resources.py +0 -0
  28. {slurm_cli-1.0.4 → slurm_cli-1.1.1}/src/slurm_cli/utils/slurm_config.py +0 -0
  29. {slurm_cli-1.0.4 → slurm_cli-1.1.1}/src/slurm_cli/utils/users.py +0 -0
  30. {slurm_cli-1.0.4 → slurm_cli-1.1.1}/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.1.1
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.1.1"
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>"]
@@ -43,6 +43,21 @@ from .utils.job_filter import is_job_filter, resolve_job_filters, resolve_job_id
43
43
  from .utils.jobs import Job
44
44
  from .utils.node_filter import is_node_filter, resolve_node_filters, resolve_nodes_value
45
45
  from .utils.nodes import Node
46
+ from .utils.partition_stats import (
47
+ DEFAULT_COLUMNS as DEFAULT_PSTATS_COLUMNS,
48
+ FIELDS,
49
+ HEADERS as PSTATS_HEADERS,
50
+ USER_HEADERS,
51
+ compute_stats,
52
+ csv_lines,
53
+ flat_rows,
54
+ print_stats,
55
+ print_user_stats,
56
+ user_columns,
57
+ user_rows,
58
+ to_plain,
59
+ user_stats,
60
+ )
46
61
  from .utils.partitions import Partition
47
62
  from .utils.prefix_utils import ( # get_all_resource_names,
48
63
  COMMANDS,
@@ -55,7 +70,16 @@ from .utils.prefix_utils import ( # get_all_resource_names,
55
70
  get_resource_help,
56
71
  get_resources_epilog,
57
72
  )
58
- from .utils.profiles import is_profile_help, show_all_profile_fields, show_profile_help
73
+ from .utils.profiles import (
74
+ extract_fields_from_template,
75
+ get_header_config,
76
+ get_profile_config,
77
+ is_profile_help,
78
+ set_header_override,
79
+ show_all_profile_fields,
80
+ show_profile_help,
81
+ sort_data,
82
+ )
59
83
  from .utils.qos import Qos
60
84
  from .utils.reservations import Reservation
61
85
  from .utils.resources import Resource
@@ -218,6 +242,13 @@ def resolve_command_alias(command: str) -> str:
218
242
  return canonical
219
243
 
220
244
 
245
+ def apply_header_option(
246
+ header: Optional[str], header_flag: bool = False, no_header: bool = False
247
+ ) -> None:
248
+ """Set the command-line header mode (None leaves profiles/env in charge)."""
249
+ set_header_override("none" if no_header else header or ("full" if header_flag else None))
250
+
251
+
221
252
  def common_options(func):
222
253
  """Decorator to add common options to commands.
223
254
 
@@ -267,6 +298,18 @@ def common_options(func):
267
298
  is_flag=True,
268
299
  help="Use pretty output format (overrides global)",
269
300
  )(func)
301
+ func = click.option(
302
+ "--no-header", "no_header", is_flag=True, help="Same as --header=none"
303
+ )(func)
304
+ func = click.option(
305
+ "-H", "header_flag", is_flag=True, help="Same as --header=full"
306
+ )(func)
307
+ func = click.option(
308
+ "--header",
309
+ type=click.Choice(["none", "full", "short", "trunc"]),
310
+ default=None,
311
+ help="Header line for custom formats (full, short, trunc, none)",
312
+ )(func)
270
313
  func = click.option(
271
314
  "--style",
272
315
  type=click.Choice(["pretty", "json", "csv"]),
@@ -830,6 +873,25 @@ def show_command_help_with_resources(
830
873
  help="Inline profile string (overrides --profile). "
831
874
  "Format: resource.columns=col1,col2;resource.styles.field=style",
832
875
  )
876
+ @click.option(
877
+ "--header",
878
+ type=click.Choice(["none", "full", "short", "trunc"]),
879
+ default=None,
880
+ help="Header line for custom formats: full titles, short titles, "
881
+ "titles truncated to the column width, or none (SLURM_CLI_HEADER)",
882
+ )
883
+ @click.option(
884
+ "-H",
885
+ "header_flag",
886
+ is_flag=True,
887
+ help="Same as --header=full",
888
+ )
889
+ @click.option(
890
+ "--no-header",
891
+ "no_header",
892
+ is_flag=True,
893
+ help="Same as --header=none",
894
+ )
833
895
  @click.option(
834
896
  "--list-fields",
835
897
  default=None,
@@ -857,8 +919,12 @@ def main(
857
919
  cache_timeout: int,
858
920
  profile: str,
859
921
  profile_str: str,
922
+ header: Optional[str] = None,
923
+ header_flag: bool = False,
924
+ no_header: bool = False,
860
925
  ) -> None:
861
926
  """Slurm CLI - A tool for Slurm cluster management."""
927
+ apply_header_option(header, header_flag, no_header) # also resets it
862
928
  # Handle convenience flags
863
929
  if pretty:
864
930
  style = "pretty"
@@ -961,6 +1027,7 @@ def register_commands() -> None:
961
1027
  main.add_command(top, name="top")
962
1028
  main.add_command(requeue, name="requeue")
963
1029
  main.add_command(suspend, name="suspend")
1030
+ main.add_command(pstats, name="pstats")
964
1031
 
965
1032
  # Modify help text to show aliases inline
966
1033
  show.help = "Show information about Slurm resources (aliases: get, list, ls)"
@@ -990,6 +1057,7 @@ def register_commands() -> None:
990
1057
  dwstat.help = "Show DataWarp/burst buffer status"
991
1058
  topology.help = "Show network topology information"
992
1059
  suspend.help = "Suspend running jobs (aliases: sus)"
1060
+ pstats.help = "Show partition statistics: nodes, jobs, users, resources"
993
1061
  help.help = "Show help information"
994
1062
 
995
1063
 
@@ -1082,6 +1150,10 @@ def show(
1082
1150
  force_update = get_force_update(ctx)
1083
1151
  profile = get_profile(ctx, profile)
1084
1152
  profile_str = get_profile_str(ctx, profile_str)
1153
+ if kwargs.get("header") or kwargs.get("header_flag") or kwargs.get("no_header"):
1154
+ apply_header_option(
1155
+ kwargs.get("header"), kwargs.get("header_flag"), kwargs.get("no_header")
1156
+ )
1085
1157
  if isinstance(field, str):
1086
1158
  field = (field,)
1087
1159
  canonical_resource, field_result, data = ensure_resource_name(
@@ -1338,7 +1410,22 @@ def show(
1338
1410
  # Jobs support job filters
1339
1411
  if field:
1340
1412
  has_filters = any(is_job_filter(f) for f in field)
1341
- if has_filters:
1413
+ simple = {"user", "account", "partition", "state", "name"}
1414
+ if has_filters and all(
1415
+ f.partition("=")[0].lower() in simple and "=" in f for f in field
1416
+ ):
1417
+ # One table from scontrol data; unlike squeue it keeps
1418
+ # completed jobs that are still known to slurmctld
1419
+ Job.show(
1420
+ field=" ".join(field),
1421
+ style=style,
1422
+ force_cache_update=force_update,
1423
+ delimiter=delimiter,
1424
+ zebra=zebra,
1425
+ profile=profile,
1426
+ profile_str=profile_str,
1427
+ )
1428
+ elif has_filters:
1342
1429
  resolved_jobs, _ = resolve_job_ids(list(field), verbose)
1343
1430
  if not resolved_jobs:
1344
1431
  console.print("[yellow]No jobs matched filters[/yellow]")
@@ -3621,6 +3708,108 @@ def _scontrol_simple(cmd_name: str, verbose: bool, dry_run: bool) -> None:
3621
3708
  console.print("[red]Error: scontrol not found[/red]")
3622
3709
 
3623
3710
 
3711
+ @click.command(context_settings=CONTEXT_SETTINGS)
3712
+ @click.argument("partitions", nargs=-1)
3713
+ @click.option("--users", "-u", is_flag=True, help="Per-user job counts")
3714
+ @click.option("--accounts", "-a", is_flag=True, help="Per-account job counts")
3715
+ @click.option("--states", "-s", is_flag=True, help="Detailed node/job states")
3716
+ @click.option(
3717
+ "--by-user",
3718
+ "-U",
3719
+ is_flag=True,
3720
+ help="User-centric view: jobs by state group per user, split by partition",
3721
+ )
3722
+ @common_options
3723
+ @click.pass_context
3724
+ def pstats(
3725
+ ctx: click.Context,
3726
+ partitions: Tuple[str, ...],
3727
+ users: bool = False,
3728
+ accounts: bool = False,
3729
+ states: bool = False,
3730
+ by_user: bool = False,
3731
+ profile_str: Optional[str] = None,
3732
+ profile: Optional[str] = None,
3733
+ delimiter: Optional[str] = None,
3734
+ zebra: Optional[bool] = None,
3735
+ csv: bool = False,
3736
+ json: bool = False,
3737
+ pretty: bool = False,
3738
+ style: Optional[str] = None,
3739
+ header: Optional[str] = None,
3740
+ header_flag: bool = False,
3741
+ no_header: bool = False,
3742
+ ) -> None:
3743
+ """Partition statistics: node states, jobs, users, CPU/GPU/memory usage.
3744
+
3745
+ Optionally restrict to the given PARTITIONS. Data is always fetched live.
3746
+ """
3747
+ style = style or ("json" if json else "csv" if csv else None)
3748
+ style = get_output_style(ctx, style)
3749
+ profile_str = get_profile_str(ctx, profile_str)
3750
+ if is_profile_help(profile_str):
3751
+ show_profile_help("pstats")
3752
+ return
3753
+ if header or header_flag or no_header:
3754
+ apply_header_option(header, header_flag, no_header)
3755
+ columns, styles, template, sort_field, sort_asc = get_profile_config(
3756
+ get_profile(ctx, profile), "pstats", profile_str
3757
+ )
3758
+ mode, titles = get_header_config(
3759
+ get_profile(ctx, profile),
3760
+ "pstats",
3761
+ profile_str,
3762
+ USER_HEADERS if by_user else PSTATS_HEADERS,
3763
+ )
3764
+ nodes = Resource.cached_resource("nodes", True) or {}
3765
+ jobs = (Resource.cached_resource("jobs", True) or {}).get("jobs", [])
3766
+ parts = Resource.cached_resource("partitions", True) or {}
3767
+ if by_user:
3768
+ ustats = user_stats(jobs, list(partitions))
3769
+ if style == "json":
3770
+ import json as jsonlib
3771
+
3772
+ console.print_json(jsonlib.dumps(ustats, indent=2))
3773
+ return
3774
+ # a "partition" field asks for one row per partition+user pair
3775
+ used = columns if isinstance(columns, list) else []
3776
+ used = used + (extract_fields_from_template(template) if template else [])
3777
+ urows = sort_data(
3778
+ user_rows(ustats, "partition" in used), sort_field, sort_asc
3779
+ )
3780
+ ucols = user_columns(urows) if columns in (None, "*") else columns
3781
+ # partition names are fields too; their title is the name itself
3782
+ known = set(USER_HEADERS) | set(PSTATS_HEADERS) | set(FIELDS)
3783
+ titles = {**{c: f"{c}|{c}" for c in ucols if c not in known}, **titles}
3784
+ if style == "csv":
3785
+ for line in csv_lines(
3786
+ urows, ucols, get_delimiter(ctx, delimiter), titles, mode
3787
+ ):
3788
+ print(line)
3789
+ else:
3790
+ print_user_stats(
3791
+ urows, ucols, template, styles, get_zebra(ctx, zebra), mode, titles
3792
+ )
3793
+ return
3794
+ stats = compute_stats(nodes, jobs, parts, list(partitions))
3795
+ columns = DEFAULT_PSTATS_COLUMNS if columns in (None, "*") else columns
3796
+ rows = sort_data(flat_rows(stats), sort_field, sort_asc)
3797
+ if style == "json":
3798
+ import json as jsonlib
3799
+
3800
+ console.print_json(jsonlib.dumps(to_plain(stats), indent=2, default=list))
3801
+ elif style == "csv":
3802
+ for line in csv_lines(
3803
+ rows, columns, get_delimiter(ctx, delimiter), titles, mode
3804
+ ):
3805
+ print(line)
3806
+ else:
3807
+ print_stats(
3808
+ stats, rows, columns, template, styles, users, accounts, states,
3809
+ get_zebra(ctx, zebra), mode, titles,
3810
+ ) # fmt: skip
3811
+
3812
+
3624
3813
  @click.command(context_settings=CONTEXT_SETTINGS)
3625
3814
  @click.option("--verbose", "-v", is_flag=True, help="Enable verbose output")
3626
3815
  @click.option("--dry-run", is_flag=True, help="Show command without executing")
@@ -9,7 +9,8 @@ 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
+ header_kwargs,
13
14
  get_profile_config,
14
15
  sort_data,
15
16
  sort_hierarchical_data,
@@ -461,10 +462,12 @@ _slurm_cli_accounts_autocomplete() {{
461
462
  else: # pretty style
462
463
  # If template is specified, use template-based output
463
464
  if template:
464
- for account in accounts:
465
- output = format_with_template(
466
- template, account, resource="accounts"
467
- )
465
+ for output in format_rows(
466
+ template,
467
+ accounts,
468
+ resource="accounts",
469
+ **header_kwargs(profile, "accounts", profile_str),
470
+ ):
468
471
  console.print(output)
469
472
  else:
470
473
  # Create a rich table
@@ -11,7 +11,8 @@ 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
+ header_kwargs,
15
16
  get_profile_config,
16
17
  sort_data,
17
18
  sort_hierarchical_data,
@@ -619,10 +620,12 @@ _slurm_cli_associations_autocomplete() {{
619
620
  else: # pretty style
620
621
  # If template is specified, use template-based output
621
622
  if template:
622
- for assoc in associations:
623
- output = format_with_template(
624
- template, assoc, resource="associations"
625
- )
623
+ for output in format_rows(
624
+ template,
625
+ associations,
626
+ resource="associations",
627
+ **header_kwargs(profile, "associations", profile_str),
628
+ ):
626
629
  console.print(output)
627
630
  else:
628
631
  # Create a rich table
@@ -125,8 +125,14 @@ _slurm_parse_keyval_ext() {{
125
125
  _val=""
126
126
  _op=""
127
127
 
128
+ # "key=<TAB>": bash makes the operator its own word, key is the previous word
129
+ if [[ $cur == "=" ]]; then
130
+ _key="${{prev,,}}"
131
+ _key="${{_key%[-+]}}"
132
+ _op="="
133
+ return 0
128
134
  # Check cur for key+=val, key-=val, or key=val
129
- if [[ $cur == *[-+]=* ]] || [[ $cur == *=* ]]; then
135
+ elif [[ $cur == *[-+]=* ]] || [[ $cur == *=* ]]; then
130
136
  _key="${{cur%%[-+]*=*}}"
131
137
  _key="${{_key%%=*}}"
132
138
  _key="${{_key,,}}"
@@ -167,8 +173,9 @@ _slurm_complete_value() {{
167
173
  COMPREPLY=($(compgen -W "$words" -- "$val"))
168
174
 
169
175
  # Only add key+op prefix when cur contains = (bash didn't split)
170
- # If bash split on =, the key= is already on command line
171
- if [[ $cur == *=* && ${{#COMPREPLY[@]}} -gt 0 ]]; then
176
+ # If bash split on =, the key= is already on command line; a cur that is
177
+ # just an operator ("key=<TAB>" makes "=" its own word) is such a case
178
+ if [[ $cur == *=* && $cur != [-+]= && $cur != "=" && ${{#COMPREPLY[@]}} -gt 0 ]]; then
172
179
  COMPREPLY=("${{COMPREPLY[@]/#/$key$op}}")
173
180
  fi
174
181
  }}
@@ -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, header_kwargs, sort_data
13
13
  from .utils import console
14
14
 
15
15
 
@@ -431,22 +431,24 @@ class Job(BaseSlurmResource):
431
431
  result = [j for j in result if str(j.get("job_id", "")) == value]
432
432
  elif key_lower == "user":
433
433
  result = [
434
- j for j in result if value_lower in j.get("user_name", "").lower()
434
+ j for j in result if value_lower == j.get("user_name", "").lower()
435
435
  ]
436
436
  elif key_lower == "account":
437
437
  result = [
438
- j for j in result if value_lower in j.get("account", "").lower()
438
+ j for j in result if value_lower == j.get("account", "").lower()
439
439
  ]
440
440
  elif key_lower == "partition":
441
441
  result = [
442
- j for j in result if value_lower in j.get("partition", "").lower()
442
+ j
443
+ for j in result
444
+ if value_lower in j.get("partition", "").lower().split(",")
443
445
  ]
444
446
  elif key_lower == "state":
445
447
  result = [
446
448
  j for j in result if value_lower in j.get("job_state", "").lower()
447
449
  ]
448
450
  elif key_lower == "name":
449
- result = [j for j in result if value_lower in j.get("name", "").lower()]
451
+ result = [j for j in result if value_lower == j.get("name", "").lower()]
450
452
  elif key_lower == "nodes":
451
453
  result = [
452
454
  j for j in result if value_lower in j.get("nodes", "").lower()
@@ -546,8 +548,12 @@ class Job(BaseSlurmResource):
546
548
  print(delimiter.join(row))
547
549
  elif template:
548
550
  # Template-based output
549
- for job in jobs:
550
- console.print(format_with_template(template, job))
551
+ for output in format_rows(
552
+ template,
553
+ jobs,
554
+ **header_kwargs(profile, "jobs", profile_str),
555
+ ):
556
+ console.print(output)
551
557
  else:
552
558
  # Pretty table output
553
559
  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, header_kwargs, sort_data
13
13
  from .utils import console
14
14
 
15
15
 
@@ -416,12 +416,15 @@ _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(
423
+ template_cfg,
424
+ prepared,
425
+ resource="nodes",
426
+ **header_kwargs(profile, "nodes", profile_str),
427
+ ):
425
428
  console.print(output)
426
429
  elif columns_cfg and columns_cfg != "*" and style == "pretty":
427
430
  # Use column-based table output (e.g., compact, minimal)