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

flux-jobs: support W presentation type, update cute output format #5179

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions doc/man1/flux-jobs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,11 @@ string, "0s", "0.0", "0:00:00", or epoch time to a hyphen. For example, normally
"{nodelist}" would output an empty string if the job has not yet run.
By specifying, "{nodelist:h}", a hyphen would be presented instead.

The special presentation type *W* can be used to adjust output alignment
for wide characters. It only works with left/right alignment formatting
of the form "(<|>)N", for example ``{id.emoji:>12W}``. It is used almost
exclusively for emoji based outputs.

The special suffix *+* can be used to indicate if a string was truncated
by including a ``+`` character when truncation occurs. If both *h* and
*+* are being used, then the *+* must appear after the *h*.
Expand Down
19 changes: 19 additions & 0 deletions src/bindings/python/flux/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import sys
import threading
import traceback
import unicodedata
from collections import namedtuple
from datetime import datetime, timedelta
from pathlib import Path, PurePosixPath
Expand Down Expand Up @@ -448,6 +449,24 @@ def format_field(self, value, spec):
basecases = empty_outputs()
value = "-" if str(value) in basecases else str(value)
spec = spec[:-1] + "s"

if spec.endswith("W") and isinstance(value, str):
match = re.search(r"^([<>])(\d+)W", spec)
if match:
align = match[1]
width = int(match[2])
widecount = 0
for chr in value:
if unicodedata.east_asian_width(chr) == "W":
widecount += 1
if width > widecount:
width -= widecount
spec = f"{align}{width}s"
# if spec was not modified above, need to convert to "W"
# conversion to "s"
if spec.endswith("W"):
spec = spec[:-1] + "s"

retval = super().format_field(value, spec)

if denote_truncation and len(retval) < len(str(value)):
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/flux-jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class FluxJobsConfig(UtilConfig):
"cute": {
"description": "Cute flux-jobs format string (default with emojis)",
"format": (
"{id.f58:>12} ?:{queue:<8.8} {username:<8.8} {name:<10.10+} "
"{id.emoji:>12W} ?:{queue:<8.8} {username:<8.8} {name:<10.10+} "
"{status_emoji:>5.5} {ntasks:>6} {nnodes:>6h} "
"{contextual_time!F:>8h} {contextual_info}"
),
Expand Down
13 changes: 12 additions & 1 deletion t/t2800-jobs-cmd.t
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ test_expect_success 'flux-jobs --format={id} works' '
test_cmp idsI.out inactive.ids
'

test_expect_success 'flux-jobs --format={id.f58},{id.hex},{id.dothex},{id.words} works' '
test_expect_success 'flux-jobs --format={id.dec/f58/hex/kvs/dothex/words} works' '
flux jobs -ano {id.dec},{id.f58},{id.hex},{id.kvs},{id.dothex},{id.words} \
| sort -n > ids.XX.out &&
for id in $(cat all.ids); do
Expand All @@ -485,6 +485,17 @@ test_expect_success 'flux-jobs --format={id.f58},{id.hex},{id.dothex},{id.words}
test_cmp ids.XX.expected ids.XX.out
'

# N.B. don't use test_cmp for match, there can be minor differences in spacing depending
# on terminal and font. Just do a grep.
test_expect_success 'flux-jobs --format={id.emoji},{id.emoji:>12W},{id.emoji:<12W} works' '
flux jobs -ano "{id.emoji},{id.emoji:>12W},{id.emoji:<12W}" \
> ids.emoji.out &&
for id in $(cat all.ids); do
idemoji=$(flux job id --to=emoji $id) &&
grep ${idemoji} ids.emoji.out
done
'

test_expect_success 'flux-jobs --format={userid},{username} works' '
flux jobs --no-header -a --format="{userid},{username}" > user.out &&
id=`id -u` &&
Expand Down