Skip to content

Commit a08bfd9

Browse files
authored
XpkConfig as a static singleton (#800)
* feat: XpkConfig as a static singleton fix: import * style: rename xpk_config_instance -> xpk_config
1 parent ef3ab86 commit a08bfd9

File tree

4 files changed

+15
-17
lines changed

4 files changed

+15
-17
lines changed

src/xpk/commands/config.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,14 @@
1414
limitations under the License.
1515
"""
1616

17-
from ..core.config import XpkConfig
17+
from ..core.config import xpk_config
1818
from ..utils.console import xpk_print
1919

20-
xpk_cfg = XpkConfig()
21-
2220

2321
def set_config(args):
24-
xpk_cfg.set(args.set_config_args[0], args.set_config_args[1])
22+
xpk_config.set(args.set_config_args[0], args.set_config_args[1])
2523

2624

2725
def get_config(args):
28-
value = xpk_cfg.get(args.get_config_key[0])
26+
value = xpk_config.get(args.get_config_key[0])
2927
xpk_print(value)

src/xpk/core/config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,6 @@ def get_all(
114114
return None
115115
val: dict[str, str] = config_yaml[CONFIGS_KEY]
116116
return val
117+
118+
119+
xpk_config = XpkConfig()

src/xpk/core/kjob.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
KJOB_SHELL_IMAGE,
3939
KJOB_SHELL_INTERACTIVE_COMMAND,
4040
KJOB_SHELL_WORKING_DIRECTORY,
41-
XpkConfig,
41+
xpk_config,
4242
)
4343
from .network import get_cluster_subnetworks
4444
from .system_characteristics import AcceleratorType, SystemCharacteristics
@@ -234,8 +234,7 @@ def get_pod_template_interactive_command() -> str:
234234
Returns:
235235
str - PodTemplate's interactive command
236236
"""
237-
config = XpkConfig()
238-
pod_command = config.get(KJOB_SHELL_INTERACTIVE_COMMAND)
237+
pod_command = xpk_config.get(KJOB_SHELL_INTERACTIVE_COMMAND)
239238
if pod_command is None or len(pod_command) == 0:
240239
pod_command = PodTemplateDefaults.INTERACTIVE_COMMAND.value
241240

@@ -287,11 +286,10 @@ def create_job_template_instance(
287286
Returns:
288287
exit_code > 0 if creating JobTemplate fails, 0 otherwise
289288
"""
290-
config = XpkConfig()
291-
job_image = config.get(KJOB_BATCH_IMAGE)
289+
job_image = xpk_config.get(KJOB_BATCH_IMAGE)
292290
if job_image is None or len(job_image) == 0:
293291
job_image = JobTemplateDefaults.IMAGE.value
294-
working_directory = config.get(KJOB_BATCH_WORKING_DIRECTORY)
292+
working_directory = xpk_config.get(KJOB_BATCH_WORKING_DIRECTORY)
295293
if working_directory is None or len(working_directory) == 0:
296294
working_directory = JobTemplateDefaults.WORKING_DIRECTORY.value
297295
resources = (
@@ -332,11 +330,10 @@ def create_pod_template_instance(service_account: str) -> int:
332330
Returns:
333331
exit_code > 0 if creating PodTemplate fails, 0 otherwise
334332
"""
335-
config = XpkConfig()
336-
pod_image = config.get(KJOB_SHELL_IMAGE)
333+
pod_image = xpk_config.get(KJOB_SHELL_IMAGE)
337334
if pod_image is None or len(pod_image) == 0:
338335
pod_image = PodTemplateDefaults.IMAGE.value
339-
working_directory = config.get(KJOB_SHELL_WORKING_DIRECTORY)
336+
working_directory = xpk_config.get(KJOB_SHELL_WORKING_DIRECTORY)
340337
if working_directory is None or len(working_directory) == 0:
341338
working_directory = PodTemplateDefaults.WORKING_DIRECTORY.value
342339

src/xpk/parser/cluster.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
cluster_describe,
2727
cluster_list,
2828
)
29-
from ..commands.config import xpk_cfg
29+
from ..core.config import xpk_config
3030
from ..core.system_characteristics import get_system_characteristics_keys_by_accelerator_type, AcceleratorType
3131
from ..core.config import CFG_BUCKET_KEY
3232
from ..core.vertex import DEFAULT_VERTEX_TENSORBOARD_NAME
@@ -131,7 +131,7 @@ def set_cluster_create_parser(cluster_create_parser: ArgumentParser):
131131
cluster_create_optional_arguments.add_argument(
132132
'--cluster-state-gcs-bucket',
133133
type=str,
134-
default=xpk_cfg.get(CFG_BUCKET_KEY),
134+
default=xpk_config.get(CFG_BUCKET_KEY),
135135
help='The name of the bucket to store cluster state.',
136136
required=False,
137137
)
@@ -390,7 +390,7 @@ def set_cluster_delete_parser(cluster_delete_parser: ArgumentParser):
390390
cluster_delete_optional_arguments.add_argument(
391391
'--cluster-state-gcs-bucket',
392392
type=str,
393-
default=xpk_cfg.get(CFG_BUCKET_KEY),
393+
default=xpk_config.get(CFG_BUCKET_KEY),
394394
help='The name of the bucket to store cluster state.',
395395
required=False,
396396
)

0 commit comments

Comments
 (0)