Skip to content

Commit 70a08ce

Browse files
kiukchungfacebook-github-bot
authored andcommitted
(monarch/tools) define ANSI colors in monarch.tools.colors and use them in commands.py (#769)
Summary: Pull Request resolved: #769 X-link: #769 Extracts ANSI colors into constants in `monarch.tools.colors` for better code-readability. Reviewed By: highker Differential Revision: D79685004 fbshipit-source-id: 13bbc56dcb73d7a050e54109938552128a6886a3
1 parent 707f705 commit 70a08ce

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

python/monarch/tools/colors.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
# pyre-strict
8+
9+
import sys
10+
11+
# only print colors if outputting directly to a terminal
12+
if not sys.stdout.closed and sys.stdout.isatty():
13+
GREEN = "\033[32m"
14+
BLUE = "\033[34m"
15+
ORANGE = "\033[38:2:238:76:44m"
16+
GRAY = "\033[2m"
17+
CYAN = "\033[36m"
18+
ENDC = "\033[0m"
19+
else:
20+
GREEN = ""
21+
ORANGE = ""
22+
BLUE = ""
23+
GRAY = ""
24+
CYAN = ""
25+
ENDC = ""

python/monarch/tools/commands.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
from datetime import datetime, timedelta
1515
from typing import Any, Callable, Mapping, Optional, Union
1616

17+
from monarch.tools.colors import CYAN, ENDC
18+
1719
from monarch.tools.components.hyperactor import DEFAULT_NAME
1820

1921
from monarch.tools.config import ( # @manual=//monarch/python/monarch/tools/config/meta:defaults
@@ -280,6 +282,11 @@ async def get_or_create(
280282
server_handle = get_or_create(name="my_job_name", config)
281283
server_info = info(server_handle)
282284
285+
Args:
286+
name: the name of the server (job) to get or create
287+
config: configs used to create the job if one does not exist
288+
check_interval: how often to poll the status of the job when waiting for it to be ready
289+
283290
Returns: A `ServerSpec` containing information about either the existing or the newly
284291
created server.
285292
@@ -311,10 +318,10 @@ async def get_or_create(
311318
f"the new server `{new_server_handle}` has {server_info.state}"
312319
)
313320

314-
print(f"\x1b[36mNew job `{new_server_handle}` is ready to serve. \x1b[0m")
321+
print(f"{CYAN}New job `{new_server_handle}` is ready to serve.{ENDC}")
315322
return server_info
316323
else:
317-
print(f"\x1b[36mFound existing job `{server_handle}` ready to serve. \x1b[0m")
324+
print(f"{CYAN}Found existing job `{server_handle}` ready to serve.{ENDC}")
318325
return server_info
319326

320327

0 commit comments

Comments
 (0)