Skip to content

Commit

Permalink
feat: add custom key to projects table, backfilling based on current …
Browse files Browse the repository at this point in the history
…project name, and API support (#9134)
  • Loading branch information
corban-beaird authored Jun 10, 2024
1 parent a5cf959 commit 27e7307
Show file tree
Hide file tree
Showing 34 changed files with 2,885 additions and 1,542 deletions.
11 changes: 8 additions & 3 deletions harness/determined/cli/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,13 @@ def format_experiment(e: bindings.v1Experiment) -> List[Any]:
def render_project(project: bindings.v1Project) -> None:
values = [
project.id,
project.key,
project.name,
project.description,
project.numExperiments,
project.numActiveExperiments,
]
PROJECT_HEADERS = ["ID", "Name", "Description", "# Experiments", "# Active Experiments"]
PROJECT_HEADERS = ["ID", "Key", "Name", "Description", "# Experiments", "# Active Experiments"]
render.tabulate_or_csv(PROJECT_HEADERS, [values], False)


Expand Down Expand Up @@ -100,7 +101,7 @@ def create_project(args: argparse.Namespace) -> None:
sess = cli.setup_session(args)
w = api.workspace_by_name(sess, args.workspace_name)
content = bindings.v1PostProjectRequest(
name=args.name, description=args.description, workspaceId=w.id
name=args.name, description=args.description, workspaceId=w.id, key=args.key
)
p = bindings.post_PostProject(sess, body=content, workspaceId=w.id).project
if args.json:
Expand Down Expand Up @@ -154,7 +155,9 @@ def delete_project(args: argparse.Namespace) -> None:
def edit_project(args: argparse.Namespace) -> None:
sess = cli.setup_session(args)
(w, p) = project_by_name(sess, args.workspace_name, args.project_name)
updated = bindings.v1PatchProject(name=args.new_name, description=args.description)
updated = bindings.v1PatchProject(
name=args.new_name, description=args.description, key=args.key
)
new_p = bindings.patch_PatchProject(sess, body=updated, id=p.id).project

if args.json:
Expand Down Expand Up @@ -247,6 +250,7 @@ def unarchive_project(args: argparse.Namespace) -> None:
cli.Arg("workspace_name", type=str, help="name of the workspace"),
cli.Arg("name", type=str, help="name of the project"),
cli.Arg("--description", type=str, help="description of the project"),
cli.Arg("--key", type=str, help="key of the project"),
cli.Arg("--json", action="store_true", help="print as JSON"),
],
),
Expand Down Expand Up @@ -309,6 +313,7 @@ def unarchive_project(args: argparse.Namespace) -> None:
cli.Arg("project_name", type=str, help="name of the project"),
cli.Arg("--new_name", type=str, help="new name of the project"),
cli.Arg("--description", type=str, help="description of the project"),
cli.Arg("--key", type=str, help="key of the project"),
cli.Arg("--json", action="store_true", help="print as JSON"),
],
),
Expand Down
3 changes: 2 additions & 1 deletion harness/determined/cli/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from determined.common.api import bindings, errors
from determined.common.experimental import workspace

PROJECT_HEADERS = ["ID", "Name", "Description", "# Experiments", "# Active Experiments"]
PROJECT_HEADERS = ["ID", "Key", "Name", "Description", "# Experiments", "# Active Experiments"]
WORKSPACE_HEADERS = [
"ID",
"Name",
Expand Down Expand Up @@ -121,6 +121,7 @@ def list_workspace_projects(args: argparse.Namespace) -> None:
values = [
[
p.id,
p.key,
p.name,
p.description,
p.n_experiments,
Expand Down
69 changes: 69 additions & 0 deletions harness/determined/common/api/bindings.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions harness/determined/common/experimental/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Project:
Attributes:
id: (int) The ID of the project.
key: (Mutable, str) The key of the project.
archived: (Mutable, bool) True if experiment is archived, else false.
description: (Mutable, str) The description of the project.
n_active_experiments: (int) The number of active experiments in the project.
Expand Down Expand Up @@ -45,6 +46,7 @@ def __init__(
self.notes: Optional[List[Dict[str, str]]] = None
self.workspace_id: Optional[int] = None
self.username: Optional[str] = None
self.key: Optional[str] = None

@classmethod
def _from_bindings(
Expand All @@ -64,6 +66,7 @@ def _hydrate(self, project_bindings: bindings.v1Project) -> None:
self.notes = [note.to_json() for note in project_bindings.notes]
self.workspace_id = project_bindings.workspaceId
self.username = project_bindings.username
self.key = project_bindings.key

def reload(self) -> None:
resp = bindings.get_GetProject(session=self._session, id=self.id)
Expand Down Expand Up @@ -93,6 +96,17 @@ def set_description(self, description: str) -> None:

self.description = resp.project.description

def set_key(self, key: str) -> None:
"""Set the project's key locally and on master.
Args:
key: The new key to set.
"""
patch_body = bindings.v1PatchProject(key=key)
resp = bindings.patch_PatchProject(session=self._session, id=self.id, body=patch_body)

self.key = resp.project.key

def set_name(self, name: str) -> None:
"""Set the project's name locally and on master.
Expand Down
2 changes: 2 additions & 0 deletions harness/determined/common/streams/wire.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions harness/tests/common/streams/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ def test_reconnect() -> None:
user_id=1,
immutable=False,
state="",
key="value",
seq=1,
)
ws.expect_next(retval={"project": p1.to_json()})
Expand Down Expand Up @@ -171,6 +172,7 @@ def test_reconnect() -> None:
user_id=1,
immutable=False,
state="",
key="value",
seq=2,
)
ws.expect_next(retval={"project": p2.to_json()})
Expand Down Expand Up @@ -208,6 +210,7 @@ def test_reconnect() -> None:
user_id=1,
immutable=False,
state="",
key="value",
seq=3,
)
ws.expect_next(retval={"project": p3.to_json()})
Expand Down Expand Up @@ -246,6 +249,7 @@ def test_change_subscription() -> None:
user_id=1,
immutable=False,
state="",
key="value",
seq=1,
)
ws.expect_next(retval={"project": p1.to_json()})
Expand Down Expand Up @@ -282,6 +286,7 @@ def test_change_subscription() -> None:
user_id=1,
immutable=False,
state="",
key="value",
seq=1000, # Note the high seq here will be ignored since this is from the old subscription.
)
ws.expect_next(retval={"project": p1b.to_json()})
Expand All @@ -300,6 +305,7 @@ def test_change_subscription() -> None:
user_id=1,
immutable=False,
state="",
key="value",
seq=2,
)
ws.expect_next(retval={"project": p2.to_json()})
Expand Down
3 changes: 2 additions & 1 deletion harness/tests/fixtures/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"userId":2,
"workspaceName":"",
"state":"WORKSPACE_STATE_UNSPECIFIED",
"errorMessage":""
"errorMessage":"",
"key":"cap1"
}
}
Loading

0 comments on commit 27e7307

Please sign in to comment.