|
| 1 | +# pyright: reportUninitializedInstanceVariable=false |
1 | 2 | from typing import cast |
2 | | -import typing_extensions |
3 | 3 | from typing_extensions import override |
4 | 4 |
|
5 | 5 | import argparse |
6 | 6 | import os |
7 | 7 | import socket |
8 | 8 | import sys |
9 | 9 | import time |
| 10 | +import uuid |
10 | 11 |
|
11 | 12 | import openshift_client as oc |
12 | 13 |
|
|
19 | 20 |
|
20 | 21 |
|
21 | 22 | class CreateJobCommandArgs(argparse.Namespace): |
| 23 | + """This class serves two purposes: |
| 24 | +
|
| 25 | + 1. It provides type hints that permit a properly configured IDE (or type |
| 26 | + checker) to perform type checking on command line option values. |
| 27 | +
|
| 28 | + 2. It provides default values for command line options. |
| 29 | + """ |
| 30 | + |
22 | 31 | gpu: str = "v100" |
23 | 32 | image: str = "image-registry.openshift-image-registry.svc:5000/redhat-ods-applications/csw-run-f25:latest" |
24 | 33 | context: bool = True |
25 | 34 | name: str = "job" |
26 | | - job_id: int = os.getpid() |
| 35 | + job_id: str = uuid.uuid5(uuid.NAMESPACE_OID, f"{os.getpid()}-{time.time()}").hex |
27 | 36 | job_delete: bool = True |
28 | 37 | wait: bool = True |
29 | 38 | timeout: int = 60 * 15 * 4 |
30 | 39 | max_sec: int = 60 * 15 |
31 | 40 | gpu_numreq: int = 1 |
32 | 41 | gpu_numlim: int = 1 |
33 | 42 | verbose: int = 0 |
34 | | - command: list[str] = [] |
| 43 | + command: list[str] |
35 | 44 |
|
36 | 45 |
|
37 | 46 | class CreateJobCommand(Command): |
@@ -76,65 +85,64 @@ def build_parser(cls, subparsers: SubParserFactory): |
76 | 85 | p.add_argument( |
77 | 86 | "--gpu", |
78 | 87 | default=CreateJobCommandArgs.gpu, |
79 | | - help=f"Select GPU type (default {CreateJobCommandArgs.gpu})", |
| 88 | + help="Select GPU type", |
80 | 89 | ) |
81 | 90 | p.add_argument( |
82 | 91 | "--image", |
83 | 92 | default=CreateJobCommandArgs.image, |
84 | | - help=f"Specify container image for job (default {CreateJobCommandArgs.image})", |
| 93 | + help="Specify container image for job", |
85 | 94 | ) |
86 | 95 | p.add_argument( |
87 | 96 | "--context", |
88 | 97 | action=argparse.BooleanOptionalAction, |
89 | 98 | default=CreateJobCommandArgs.context, |
90 | | - help=f"Copy working directory (default {CreateJobCommandArgs.context})", |
| 99 | + help="Copy working directory", |
91 | 100 | ) |
92 | 101 | p.add_argument( |
93 | 102 | "--name", |
94 | 103 | default=CreateJobCommandArgs.name, |
95 | | - help=f"Base job name (default {CreateJobCommandArgs.name})", |
| 104 | + help="Base job name", |
96 | 105 | ) |
97 | 106 | p.add_argument( |
98 | 107 | "--job-id", |
99 | 108 | default=CreateJobCommandArgs.job_id, |
100 | | - type=int, |
101 | | - help="Job ID suffix (default current pid)", |
| 109 | + help="Job ID suffix", |
102 | 110 | ) |
103 | 111 | p.add_argument( |
104 | 112 | "--job-delete", |
105 | 113 | action=argparse.BooleanOptionalAction, |
106 | 114 | default=CreateJobCommandArgs.job_delete, |
107 | | - help=f"Delete job on completion (default {CreateJobCommandArgs.job_delete})", |
| 115 | + help="Delete job on completion", |
108 | 116 | ) |
109 | 117 | p.add_argument( |
110 | 118 | "--wait", |
111 | 119 | action=argparse.BooleanOptionalAction, |
112 | 120 | default=CreateJobCommandArgs.wait, |
113 | | - help=f"Wait for job completion (default {CreateJobCommandArgs.wait})", |
| 121 | + help="Wait for job completion", |
114 | 122 | ) |
115 | 123 | p.add_argument( |
116 | 124 | "--timeout", |
117 | 125 | default=CreateJobCommandArgs.timeout, |
118 | 126 | type=int, |
119 | | - help=f"Wait timeout in seconds (default {CreateJobCommandArgs.timeout})", |
| 127 | + help="Wait timeout in seconds", |
120 | 128 | ) |
121 | 129 | p.add_argument( |
122 | 130 | "--max-sec", |
123 | 131 | default=CreateJobCommandArgs.max_sec, |
124 | 132 | type=int, |
125 | | - help=f"Maximum execution time in seconds (default {CreateJobCommandArgs.max_sec})", |
| 133 | + help="Maximum execution time in seconds", |
126 | 134 | ) |
127 | 135 | p.add_argument( |
128 | 136 | "--gpu-numreq", |
129 | 137 | default=CreateJobCommandArgs.gpu_numreq, |
130 | 138 | type=int, |
131 | | - help=f"Number of GPUs requested (default {CreateJobCommandArgs.gpu_numreq})", |
| 139 | + help="Number of GPUs requested", |
132 | 140 | ) |
133 | 141 | p.add_argument( |
134 | 142 | "--gpu-numlim", |
135 | 143 | default=CreateJobCommandArgs.gpu_numlim, |
136 | 144 | type=int, |
137 | | - help=f"Number of GPUs limited (default {CreateJobCommandArgs.gpu_numlim})", |
| 145 | + help="Number of GPUs limited", |
138 | 146 | ) |
139 | 147 | p.add_argument( |
140 | 148 | "command", |
|
0 commit comments