dtu-hpc-cli 1.5.0__tar.gz → 1.5.2__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.
- {dtu_hpc_cli-1.5.0 → dtu_hpc_cli-1.5.2}/PKG-INFO +2 -2
- {dtu_hpc_cli-1.5.0 → dtu_hpc_cli-1.5.2}/README.md +1 -1
- {dtu_hpc_cli-1.5.0 → dtu_hpc_cli-1.5.2}/dtu_hpc_cli/__init__.py +16 -4
- {dtu_hpc_cli-1.5.0 → dtu_hpc_cli-1.5.2}/dtu_hpc_cli/client/base.py +1 -1
- {dtu_hpc_cli-1.5.0 → dtu_hpc_cli-1.5.2}/dtu_hpc_cli/client/local.py +3 -2
- {dtu_hpc_cli-1.5.0 → dtu_hpc_cli-1.5.2}/dtu_hpc_cli/client/ssh.py +3 -3
- dtu_hpc_cli-1.5.2/dtu_hpc_cli/jobs.py +55 -0
- {dtu_hpc_cli-1.5.0 → dtu_hpc_cli-1.5.2}/dtu_hpc_cli/remove.py +24 -1
- {dtu_hpc_cli-1.5.0 → dtu_hpc_cli-1.5.2}/pyproject.toml +1 -1
- dtu_hpc_cli-1.5.0/dtu_hpc_cli/jobs.py +0 -36
- {dtu_hpc_cli-1.5.0 → dtu_hpc_cli-1.5.2}/dtu_hpc_cli/client/__init__.py +0 -0
- {dtu_hpc_cli-1.5.0 → dtu_hpc_cli-1.5.2}/dtu_hpc_cli/config.py +0 -0
- {dtu_hpc_cli-1.5.0 → dtu_hpc_cli-1.5.2}/dtu_hpc_cli/constants.py +0 -0
- {dtu_hpc_cli-1.5.0 → dtu_hpc_cli-1.5.2}/dtu_hpc_cli/editor.py +0 -0
- {dtu_hpc_cli-1.5.0 → dtu_hpc_cli-1.5.2}/dtu_hpc_cli/error.py +0 -0
- {dtu_hpc_cli-1.5.0 → dtu_hpc_cli-1.5.2}/dtu_hpc_cli/get_command.py +0 -0
- {dtu_hpc_cli-1.5.0 → dtu_hpc_cli-1.5.2}/dtu_hpc_cli/get_options.py +0 -0
- {dtu_hpc_cli-1.5.0 → dtu_hpc_cli-1.5.2}/dtu_hpc_cli/history.py +0 -0
- {dtu_hpc_cli-1.5.0 → dtu_hpc_cli-1.5.2}/dtu_hpc_cli/install.py +0 -0
- {dtu_hpc_cli-1.5.0 → dtu_hpc_cli-1.5.2}/dtu_hpc_cli/open_error.py +0 -0
- {dtu_hpc_cli-1.5.0 → dtu_hpc_cli-1.5.2}/dtu_hpc_cli/open_output.py +0 -0
- {dtu_hpc_cli-1.5.0 → dtu_hpc_cli-1.5.2}/dtu_hpc_cli/queues.py +0 -0
- {dtu_hpc_cli-1.5.0 → dtu_hpc_cli-1.5.2}/dtu_hpc_cli/resubmit.py +0 -0
- {dtu_hpc_cli-1.5.0 → dtu_hpc_cli-1.5.2}/dtu_hpc_cli/run.py +0 -0
- {dtu_hpc_cli-1.5.0 → dtu_hpc_cli-1.5.2}/dtu_hpc_cli/start_time.py +0 -0
- {dtu_hpc_cli-1.5.0 → dtu_hpc_cli-1.5.2}/dtu_hpc_cli/stats.py +0 -0
- {dtu_hpc_cli-1.5.0 → dtu_hpc_cli-1.5.2}/dtu_hpc_cli/submit.py +0 -0
- {dtu_hpc_cli-1.5.0 → dtu_hpc_cli-1.5.2}/dtu_hpc_cli/sync.py +0 -0
- {dtu_hpc_cli-1.5.0 → dtu_hpc_cli-1.5.2}/dtu_hpc_cli/types.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: dtu-hpc-cli
|
|
3
|
-
Version: 1.5.
|
|
3
|
+
Version: 1.5.2
|
|
4
4
|
Summary: CLI to make it easier to work with the HPC cluster at the Technical University of Denmark (DTU).
|
|
5
5
|
License: MIT
|
|
6
6
|
Author: Christoffer Koo Øhrstrøm
|
|
@@ -68,7 +68,7 @@ You can call it using the `dtu` command, which has the these subcommands:
|
|
|
68
68
|
* **get-options**: Print options from a previously submitted job.
|
|
69
69
|
* **history**: Shows a list of the jobs that you have submitted and the options/commands that you used.
|
|
70
70
|
* **install**: Calls the installation commands in your configuration. NB. this command will install your project on the HPC - not on your local machine.
|
|
71
|
-
* **jobs**: Shows a list of running and pending jobs. It calls `
|
|
71
|
+
* **jobs**: Shows a list of running and pending jobs. It calls `bjobs` on the HPC.
|
|
72
72
|
* **open-error**: Show the error log of a given job ID in your default text editor.
|
|
73
73
|
* **open-output**: Show the output log of a given job ID in your default text editor.
|
|
74
74
|
* **queues**: List all queues or show job statistics for a single queue. It calls `bqueues` or `classtat` on the HPC.
|
|
@@ -45,7 +45,7 @@ You can call it using the `dtu` command, which has the these subcommands:
|
|
|
45
45
|
* **get-options**: Print options from a previously submitted job.
|
|
46
46
|
* **history**: Shows a list of the jobs that you have submitted and the options/commands that you used.
|
|
47
47
|
* **install**: Calls the installation commands in your configuration. NB. this command will install your project on the HPC - not on your local machine.
|
|
48
|
-
* **jobs**: Shows a list of running and pending jobs. It calls `
|
|
48
|
+
* **jobs**: Shows a list of running and pending jobs. It calls `bjobs` on the HPC.
|
|
49
49
|
* **open-error**: Show the error log of a given job ID in your default text editor.
|
|
50
50
|
* **open-output**: Show the output log of a given job ID in your default text editor.
|
|
51
51
|
* **queues**: List all queues or show job statistics for a single queue. It calls `bqueues` or `classtat` on the HPC.
|
|
@@ -34,7 +34,7 @@ from dtu_hpc_cli.types import Duration
|
|
|
34
34
|
from dtu_hpc_cli.types import Memory
|
|
35
35
|
from dtu_hpc_cli.types import Time
|
|
36
36
|
|
|
37
|
-
__version__ = "1.5.
|
|
37
|
+
__version__ = "1.5.2"
|
|
38
38
|
|
|
39
39
|
cli = typer.Typer(pretty_exceptions_show_locals=False)
|
|
40
40
|
|
|
@@ -234,9 +234,10 @@ def jobs(
|
|
|
234
234
|
node: str | None = None,
|
|
235
235
|
queue: str | None = None,
|
|
236
236
|
stats: Annotated[JobsStats, typer.Option()] = None,
|
|
237
|
+
full_name: Annotated[bool, typer.Option(help="Show the full job name instead of a truncated one.")] = True,
|
|
237
238
|
):
|
|
238
239
|
"""List running and pending jobs."""
|
|
239
|
-
list_config = JobsConfig(node=node, queue=queue, stats=stats)
|
|
240
|
+
list_config = JobsConfig(node=node, queue=queue, stats=stats, full_name=full_name)
|
|
240
241
|
execute_jobs(list_config)
|
|
241
242
|
|
|
242
243
|
|
|
@@ -259,9 +260,20 @@ def queues(queue: Annotated[str, typer.Argument()] = None):
|
|
|
259
260
|
|
|
260
261
|
|
|
261
262
|
@cli.command()
|
|
262
|
-
def remove(
|
|
263
|
+
def remove(
|
|
264
|
+
job_ids: Annotated[List[str], typer.Argument()] = None,
|
|
265
|
+
all_jobs: Annotated[bool, typer.Option("--all")] = False,
|
|
266
|
+
from_history: bool = False,
|
|
267
|
+
):
|
|
263
268
|
"""Remove jobs from the queue."""
|
|
264
|
-
|
|
269
|
+
if not all_jobs and job_ids is None:
|
|
270
|
+
raise typer.BadParameter("Provide job IDs or use --all to remove all jobs.")
|
|
271
|
+
elif all_jobs and job_ids is not None:
|
|
272
|
+
raise typer.BadParameter("Cannot provide job IDs when using --all.")
|
|
273
|
+
|
|
274
|
+
if job_ids is None:
|
|
275
|
+
job_ids = []
|
|
276
|
+
config = RemoveConfig(all=all_jobs, from_history=from_history, job_ids=job_ids)
|
|
265
277
|
execute_remove(config)
|
|
266
278
|
|
|
267
279
|
|
|
@@ -12,7 +12,7 @@ class Client(abc.ABC):
|
|
|
12
12
|
self.close()
|
|
13
13
|
|
|
14
14
|
@abc.abstractmethod
|
|
15
|
-
def run(self, command: str, cwd: str | None = None) -> tuple[int, str]:
|
|
15
|
+
def run(self, command: str, cwd: str | None = None, silent: bool = False) -> tuple[int, str]:
|
|
16
16
|
pass
|
|
17
17
|
|
|
18
18
|
@abc.abstractmethod
|
|
@@ -10,7 +10,7 @@ class LocalClient(Client):
|
|
|
10
10
|
def close(self):
|
|
11
11
|
pass
|
|
12
12
|
|
|
13
|
-
def run(self, command: str, cwd: str | None = None) -> tuple[int, str]:
|
|
13
|
+
def run(self, command: str, cwd: str | None = None, silent: bool = False) -> tuple[int, str]:
|
|
14
14
|
# Ignore the cwd parameter since we assume that the user is running the command from the correct directory.
|
|
15
15
|
outputs = []
|
|
16
16
|
with subprocess.Popen(
|
|
@@ -23,7 +23,8 @@ class LocalClient(Client):
|
|
|
23
23
|
universal_newlines=True,
|
|
24
24
|
) as process:
|
|
25
25
|
for line in process.stdout:
|
|
26
|
-
|
|
26
|
+
if not silent:
|
|
27
|
+
typer.echo(line, nl=False)
|
|
27
28
|
outputs.append(line)
|
|
28
29
|
returncode = process.wait()
|
|
29
30
|
output = "".join(outputs)
|
|
@@ -20,13 +20,13 @@ class SSHClient(Client):
|
|
|
20
20
|
def close(self):
|
|
21
21
|
self.client.close()
|
|
22
22
|
|
|
23
|
-
def run(self, command: str, cwd: str | None = None) -> tuple[int, str]:
|
|
23
|
+
def run(self, command: str, cwd: str | None = None, silent: bool = False) -> tuple[int, str]:
|
|
24
24
|
command = f'bash -l -c "{command}"'
|
|
25
25
|
if cwd is not None:
|
|
26
26
|
with self.client.cd(cwd):
|
|
27
|
-
result = self.client.run(command, warn=True)
|
|
27
|
+
result = self.client.run(command, warn=True, hide=silent)
|
|
28
28
|
else:
|
|
29
|
-
result = self.client.run(command, warn=True)
|
|
29
|
+
result = self.client.run(command, warn=True, hide=silent)
|
|
30
30
|
return result.exited, result.stdout
|
|
31
31
|
|
|
32
32
|
def remove(self, path: str):
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import dataclasses
|
|
2
|
+
import enum
|
|
3
|
+
|
|
4
|
+
from dtu_hpc_cli.client import get_client
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class JobsStats(enum.StrEnum):
|
|
8
|
+
cpu = "cpu"
|
|
9
|
+
memory = "memory"
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@dataclasses.dataclass
|
|
13
|
+
class JobsConfig:
|
|
14
|
+
node: str | None
|
|
15
|
+
queue: str | None
|
|
16
|
+
stats: JobsStats | None
|
|
17
|
+
full_name: bool = True
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
CPU_FIELDS = ["cpu_used", "run_time", "nexec_host", "slots"]
|
|
21
|
+
MEMORY_FIELDS = ["mem", "max_mem", "avg_mem", "memlimit"]
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def execute_jobs(config: JobsConfig):
|
|
25
|
+
command = ["bjobs"]
|
|
26
|
+
|
|
27
|
+
# In -o format, a bare field name has unlimited width while "field:" uses the recommended (truncated) width.
|
|
28
|
+
job_name_field = "job_name" if config.full_name else "job_name:"
|
|
29
|
+
base_fields = ["jobid", job_name_field, "stat", "queue", "exec_host"]
|
|
30
|
+
|
|
31
|
+
match config.stats:
|
|
32
|
+
case JobsStats.cpu:
|
|
33
|
+
fields = base_fields + CPU_FIELDS
|
|
34
|
+
case JobsStats.memory:
|
|
35
|
+
fields = base_fields + MEMORY_FIELDS
|
|
36
|
+
case _:
|
|
37
|
+
fields = None
|
|
38
|
+
|
|
39
|
+
if fields is not None:
|
|
40
|
+
# Single quotes because the SSH client wraps the command in double quotes.
|
|
41
|
+
command.extend(["-o", f"'{' '.join(fields)}'"])
|
|
42
|
+
elif config.full_name:
|
|
43
|
+
# Wide format prevents bjobs from truncating the job name (and other fields) in the default output.
|
|
44
|
+
command.append("-w")
|
|
45
|
+
|
|
46
|
+
if config.node is not None:
|
|
47
|
+
command.extend(["-m", config.node])
|
|
48
|
+
|
|
49
|
+
if config.queue is not None:
|
|
50
|
+
command.extend(["-q", config.queue])
|
|
51
|
+
|
|
52
|
+
command = " ".join(command)
|
|
53
|
+
|
|
54
|
+
with get_client() as client:
|
|
55
|
+
client.run(command)
|
|
@@ -8,6 +8,7 @@ from dtu_hpc_cli.history import load_history
|
|
|
8
8
|
|
|
9
9
|
@dataclasses.dataclass
|
|
10
10
|
class RemoveConfig:
|
|
11
|
+
all: bool
|
|
11
12
|
from_history: bool
|
|
12
13
|
job_ids: list[str]
|
|
13
14
|
|
|
@@ -20,6 +21,17 @@ def execute_remove(config: RemoveConfig):
|
|
|
20
21
|
|
|
21
22
|
|
|
22
23
|
def expand_job_ids(config: RemoveConfig) -> list[str]:
|
|
24
|
+
if config.all:
|
|
25
|
+
job_ids = get_all_job_ids()
|
|
26
|
+
if len(job_ids) == 0:
|
|
27
|
+
typer.echo("No jobs to remove.")
|
|
28
|
+
raise typer.Exit()
|
|
29
|
+
typer.echo("The following jobs will be removed (because --all flag is used):")
|
|
30
|
+
for job_id in job_ids:
|
|
31
|
+
typer.echo(f" * {job_id}")
|
|
32
|
+
typer.confirm("\nRemove all jobs (enter to remove)?", abort=True, default=True)
|
|
33
|
+
return job_ids
|
|
34
|
+
|
|
23
35
|
if not config.from_history:
|
|
24
36
|
return config.job_ids
|
|
25
37
|
|
|
@@ -35,9 +47,20 @@ def expand_job_ids(config: RemoveConfig) -> list[str]:
|
|
|
35
47
|
new_job_ids = job_ids - requested_ids
|
|
36
48
|
job_ids = sorted(job_ids)
|
|
37
49
|
if len(new_job_ids) != 0:
|
|
38
|
-
typer.echo("The following jobs will be removed (because --from-history flag
|
|
50
|
+
typer.echo("The following jobs will be removed (because --from-history flag is used):")
|
|
39
51
|
for job_id in job_ids:
|
|
40
52
|
typer.echo(f" * {job_id}")
|
|
41
53
|
typer.confirm("\nRemove these jobs (enter to remove)?", abort=True, default=True)
|
|
42
54
|
|
|
43
55
|
return job_ids
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def get_all_job_ids() -> list[str]:
|
|
59
|
+
with get_client() as client:
|
|
60
|
+
_, output = client.run("bjobs -noheader -o jobid", silent=True)
|
|
61
|
+
|
|
62
|
+
# bjobs prints "No unfinished job found" (possibly merged into stdout) when there are no jobs,
|
|
63
|
+
# so only keep lines that are actual job IDs.
|
|
64
|
+
job_ids = [line.strip() for line in output.splitlines() if line.strip().isdigit()]
|
|
65
|
+
|
|
66
|
+
return job_ids
|
|
@@ -5,10 +5,10 @@ license = "MIT"
|
|
|
5
5
|
name = "dtu-hpc-cli"
|
|
6
6
|
readme = "README.md"
|
|
7
7
|
repository = "https://github.com/ChrisFugl/DTU-HPC-CLI"
|
|
8
|
-
version = "1.5.0"
|
|
9
8
|
|
|
10
9
|
[project]
|
|
11
10
|
name = "dtu-hpc-cli"
|
|
11
|
+
version = "1.5.2"
|
|
12
12
|
|
|
13
13
|
[project.urls]
|
|
14
14
|
Changelog = "https://github.com/ChrisFugl/DTU-HPC-CLI/CHANGELOG.md"
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import dataclasses
|
|
2
|
-
import enum
|
|
3
|
-
|
|
4
|
-
from dtu_hpc_cli.client import get_client
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
class JobsStats(enum.StrEnum):
|
|
8
|
-
cpu = "cpu"
|
|
9
|
-
memory = "memory"
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
@dataclasses.dataclass
|
|
13
|
-
class JobsConfig:
|
|
14
|
-
node: str | None
|
|
15
|
-
queue: str | None
|
|
16
|
-
stats: JobsStats | None
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
def execute_jobs(config: JobsConfig):
|
|
20
|
-
command = ["bstat"]
|
|
21
|
-
match config.stats:
|
|
22
|
-
case JobsStats.cpu:
|
|
23
|
-
command.append("-C")
|
|
24
|
-
case JobsStats.memory:
|
|
25
|
-
command.append("-M")
|
|
26
|
-
|
|
27
|
-
if config.node is not None:
|
|
28
|
-
command.extend(["-n", config.node])
|
|
29
|
-
|
|
30
|
-
if config.queue is not None:
|
|
31
|
-
command.extend(["-q", config.queue])
|
|
32
|
-
|
|
33
|
-
command = " ".join(command)
|
|
34
|
-
|
|
35
|
-
with get_client() as client:
|
|
36
|
-
client.run(command)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|