Skip to content

Commit d88972d

Browse files
aivanoufacebook-github-bot
authored andcommitted
Remove AppDef builder methods (#81)
Summary: Pull Request resolved: #81 The diff removes ``of``, ``get_metadata`` and ``add_metadata`` methods from the ``AppDef`` class Reviewed By: kiukchung Differential Revision: D29176342 fbshipit-source-id: 99d1af4296f50213394980a5f9456c9b604aec7f
1 parent ed150e2 commit d88972d

File tree

5 files changed

+7
-22
lines changed

5 files changed

+7
-22
lines changed

torchx/cli/test/cmd_describe_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def get_test_app(self) -> AppDef:
2626
num_replicas=2,
2727
nnodes="2:3",
2828
)
29-
return AppDef("my_train_job").of(trainer)
29+
return AppDef("my_train_job", roles=[trainer])
3030

3131
def test_run(self) -> None:
3232
parser = argparse.ArgumentParser()

torchx/components/dist.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,4 @@ def ddp(
6363
max_restarts=0,
6464
)
6565

66-
return specs.AppDef(name).of(ddp_role)
66+
return specs.AppDef(name, roles=[ddp_role])

torchx/runner/api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ def dryrun(
236236
# input validation
237237
if not app.roles:
238238
raise ValueError(
239-
f"No roles for app: {app.name}. Did you forget to call app.of(roles..)?"
239+
f"No roles for app: {app.name}. Did you forget to add roles to AppDef?"
240240
)
241241

242242
for role in app.roles:
@@ -394,7 +394,7 @@ def describe(self, app_handle: AppHandle) -> Optional[AppDef]:
394394
if not app:
395395
desc = scheduler.describe(app_id)
396396
if desc:
397-
app = AppDef(name=app_id).of(*desc.roles)
397+
app = AppDef(name=app_id, roles=desc.roles)
398398
return app
399399

400400
def log_lines(

torchx/specs/api.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -280,21 +280,6 @@ class AppDef:
280280
roles: List[Role] = field(default_factory=list)
281281
metadata: Dict[str, str] = field(default_factory=dict)
282282

283-
def of(self, *roles: Role) -> "AppDef":
284-
self.roles += [*roles]
285-
return self
286-
287-
def add_metadata(self, key: str, value: str) -> "AppDef":
288-
"""
289-
Adds metadata to the application.
290-
.. note:: If the key already exists, this method overwrites the metadata value.
291-
"""
292-
self.metadata[key] = value
293-
return self
294-
295-
def get_metadata(self, key: str) -> Optional[str]:
296-
return self.metadata.get(key)
297-
298283

299284
class AppState(int, Enum):
300285
"""

torchx/specs/test/api_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,9 @@ def test_application_default(self) -> None:
194194
self.assertEqual(0, len(app.roles))
195195

196196
def test_getset_metadata(self) -> None:
197-
app = AppDef(name="test_app").add_metadata("test_key", "test_value")
198-
self.assertEqual("test_value", app.get_metadata("test_key"))
199-
self.assertEqual(None, app.get_metadata("non_existent"))
197+
app = AppDef(name="test_app", metadata={"test_key": "test_value"})
198+
self.assertEqual("test_value", app.metadata["test_key"])
199+
self.assertEqual(None, app.metadata.get("non_existent"))
200200

201201

202202
class RunConfigTest(unittest.TestCase):

0 commit comments

Comments
 (0)