Skip to content

Commit

Permalink
fix: fix the tests and docs for the new gridtk list options
Browse files Browse the repository at this point in the history
  • Loading branch information
183amir committed Oct 29, 2024
1 parent 62022ed commit 861304b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 18 deletions.
26 changes: 19 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,15 +252,27 @@ or for `zsh` add the following line to your `~/.zshrc` file:
eval "$(_GRIDTK_COMPLETE=zsh_source gridtk)"
```

### Adjusting `gridtk list` Output to Fit Terminal Width
### Adjusting `gridtk list` Output

By default, the `gridtk list` output now adjusts to fit the terminal width, with truncation or ellipses for long content. This ensures that the output remains readable and does not span multiple lines. If you wish to view the full output without truncation, you can use the `--full-output` option:
By default, the `gridtk list` output adjusts to fit the terminal width, with wraping. There are two options: `--truncate` and `--full-output`.
The `--truncate` option truncates the output to fit the terminal width, while the `--full-output` option displays the full output without wrapping.

```bash
$ gridtk list
job-id slurm- nodes state job- output depende command
id name ncies
-------- -------- ------- -------------- ------ --------------- --------- --------------------
1 506976 None UNKNOWN (None) gridtk logs/gridtk.506 gridtk submit job.sh
976.out

$ gridtk list --full-output
job-id grid-id nodes state job-name output dependencies command
-------- --------- ------- ----------- ---------- ---------------------- -------------- --------------------
1 136132 None PENDING (0) gridtk logs/gridtk.136132.out gridtk submit job.sh
```
job-id slurm-id nodes state job-name output dependencies command
-------- ---------- ------- ------------- ---------- ---------------------- -------------- --------------------
1 506976 hcne01 COMPLETED (0) gridtk logs/gridtk.506976.out gridtk submit job.sh

This enhancement improves readability and allows you to quickly parse job-related information without resizing your terminal or handling multiline outputs for each job.
$ gridtk list --truncate
job-id slurm- nodes state job- output depende command
id name ncies
-------- -------- ------- ------------- ------ --------------- --------- --------------------
1 506976 hcne01 COMPLETED (0) gridtk logs/gridtk.... gridtk submit job.sh
```
17 changes: 9 additions & 8 deletions src/gridtk/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ def truncate_str(content: str, max_width: int) -> str:
for job in jobs:
table["job-id"].append(job.id)
table["slurm-id"].append(job.grid_id)
table["nodes"].append(job.nodes)
table["nodes"].append(str(job.nodes))
table["state"].append(f"{job.state} ({job.exit_code})")
table["job-name"].append(job.name)
output = job.output_files[0].resolve()
Expand Down Expand Up @@ -468,14 +468,15 @@ def truncate_str(content: str, max_width: int) -> str:
else:
maxcolwidths = [max_widths.get(key, 15) for key in table]

click.echo(
tabulate(
table,
headers="keys",
maxcolwidths=maxcolwidths,
maxheadercolwidths=None if full_output else 7,
if table:
click.echo(
tabulate(
table,
headers="keys",
maxcolwidths=maxcolwidths,
maxheadercolwidths=None if full_output else 7,
)
)
)
session.commit()


Expand Down
12 changes: 9 additions & 3 deletions tests/test_gridtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,11 @@ def test_submit_triple_dash(mock_check_output: Mock, runner):
@patch("subprocess.check_output")
def test_list_jobs(mock_check_output, runner):
with runner.isolated_filesystem():
# test when there are no jobs
result = runner.invoke(cli, ["list"])
assert_click_runner_result(result)
assert result.output == ""
# test when there are jobs
submit_job_id = 9876543
_submit_job(
runner=runner, mock_check_output=mock_check_output, job_id=submit_job_id
Expand Down Expand Up @@ -532,8 +537,9 @@ def test_list_jobs_with_truncation(mock_check_output, runner):
result = runner.invoke(cli, ["list"])
assert_click_runner_result(result)
assert str(submit_job_id) in result.output
assert "gridtk submit --- sleep" in result.output
assert "logs/gridtk.9876543.out" in result.output
assert "gridtk submit --wrap sleep" in result.output
# truncated log file name
assert "logs/gridtk.987 " in result.output
mock_check_output.assert_called_with(
["sacct", "-j", str(submit_job_id), "--json"], text=True
)
Expand All @@ -551,7 +557,7 @@ def test_list_jobs_with_full_output(mock_check_output, runner):
result = runner.invoke(cli, ["list", "--full-output"])
assert_click_runner_result(result)
assert str(submit_job_id) in result.output
assert "gridtk submit --- sleep" in result.output
assert "gridtk submit --wrap sleep" in result.output
assert "logs/gridtk.9876543.out" in result.output
mock_check_output.assert_called_with(
["sacct", "-j", str(submit_job_id), "--json"], text=True
Expand Down

0 comments on commit 861304b

Please sign in to comment.