|
33 | 33 | import yaml |
34 | 34 |
|
35 | 35 | from . import api, exceptions, utils |
| 36 | +from .project_versions import ProjectVersion |
36 | 37 | from .projects import Project |
37 | 38 | from .schemas import BaselineModelSchema, DatasetSchema, ModelSchema |
38 | 39 | from .tasks import TaskType |
@@ -473,7 +474,7 @@ def add_model( |
473 | 474 |
|
474 | 475 | def add_baseline_model( |
475 | 476 | self, |
476 | | - project_id: int, |
| 477 | + project_id: str, |
477 | 478 | task_type: TaskType, |
478 | 479 | model_config_file_path: Optional[str] = None, |
479 | 480 | force: bool = False, |
@@ -994,7 +995,7 @@ class probabilities. For example, for a binary classification |
994 | 995 | task_type=task_type, |
995 | 996 | ) |
996 | 997 |
|
997 | | - def commit(self, message: str, project_id: int, force: bool = False): |
| 998 | + def commit(self, message: str, project_id: str, force: bool = False): |
998 | 999 | """Adds a commit message to staged resources. |
999 | 1000 |
|
1000 | 1001 | Parameters |
@@ -1081,7 +1082,7 @@ def commit(self, message: str, project_id: int, force: bool = False): |
1081 | 1082 |
|
1082 | 1083 | print("Committed!") |
1083 | 1084 |
|
1084 | | - def push(self, project_id: int, task_type: TaskType): |
| 1085 | + def push(self, project_id: str, task_type: TaskType) -> Optional[ProjectVersion]: |
1085 | 1086 | """Pushes the commited resources to the platform. |
1086 | 1087 |
|
1087 | 1088 | Notes |
@@ -1124,15 +1125,17 @@ def push(self, project_id: int, task_type: TaskType): |
1124 | 1125 | f"\t - Date: {commit['date']}" |
1125 | 1126 | ) |
1126 | 1127 | payload = {"commit": {"message": commit["message"]}} |
1127 | | - self.api.upload( |
| 1128 | + response_body = self.api.upload( |
1128 | 1129 | endpoint=f"projects/{project_id}/versions", |
1129 | 1130 | file_path=tar_file_path, |
1130 | 1131 | object_name="tarfile", |
1131 | 1132 | body=payload, |
1132 | 1133 | ) |
| 1134 | + project_version = ProjectVersion(json=response_body, client=self) |
1133 | 1135 |
|
1134 | 1136 | self._post_push_cleanup(project_dir=project_dir) |
1135 | 1137 | print("Pushed!") |
| 1138 | + return project_version |
1136 | 1139 |
|
1137 | 1140 | def _ready_for_push(self, project_dir: str, task_type: TaskType) -> bool: |
1138 | 1141 | """Checks if the project's staging area is ready to be pushed to the platform. |
@@ -1183,7 +1186,7 @@ def _post_push_cleanup(self, project_dir: str) -> None: |
1183 | 1186 | shutil.rmtree(project_dir) |
1184 | 1187 | os.makedirs(project_dir, exist_ok=True) |
1185 | 1188 |
|
1186 | | - def export(self, destination_dir: str, project_id: int, task_type: TaskType): |
| 1189 | + def export(self, destination_dir: str, project_id: str, task_type: TaskType): |
1187 | 1190 | """Exports the commited resources as a tarfile to the location specified |
1188 | 1191 | by ``destination_dir``. |
1189 | 1192 |
|
@@ -1229,7 +1232,7 @@ def export(self, destination_dir: str, project_id: int, task_type: TaskType): |
1229 | 1232 | self._post_push_cleanup(project_dir=project_dir) |
1230 | 1233 | print("Exported tarfile!") |
1231 | 1234 |
|
1232 | | - def status(self, project_id: int): |
| 1235 | + def status(self, project_id: str): |
1233 | 1236 | """Shows the state of the staging area. |
1234 | 1237 |
|
1235 | 1238 | Examples |
@@ -1277,7 +1280,7 @@ def status(self, project_id: int): |
1277 | 1280 | print(f"\t {commit['message']}") |
1278 | 1281 | print("Use the `push` method to push your changes to the platform.") |
1279 | 1282 |
|
1280 | | - def restore(self, *resource_names: str, project_id: int): |
| 1283 | + def restore(self, *resource_names: str, project_id: str): |
1281 | 1284 | """Removes the resource specified by ``resource_name`` from the staging area. |
1282 | 1285 |
|
1283 | 1286 | Parameters |
@@ -1328,7 +1331,7 @@ def restore(self, *resource_names: str, project_id: int): |
1328 | 1331 | os.remove(f"{project_dir}/commit.yaml") |
1329 | 1332 |
|
1330 | 1333 | def _stage_resource( |
1331 | | - self, resource_name: str, resource_dir: str, project_id: int, force: bool |
| 1334 | + self, resource_name: str, resource_dir: str, project_id: str, force: bool |
1332 | 1335 | ): |
1333 | 1336 | """Adds the resource specified by `resource_name` to the project's staging directory. |
1334 | 1337 |
|
@@ -1370,3 +1373,43 @@ def _stage_resource( |
1370 | 1373 | shutil.copytree(resource_dir, project_dir + "/" + resource_name) |
1371 | 1374 |
|
1372 | 1375 | print(f"Staged the `{resource_name}` resource!") |
| 1376 | + |
| 1377 | + def load_project_version(self, version_id: str) -> Project: |
| 1378 | + """Loads an existing project version from the Openlayer platform. Can be used |
| 1379 | + to check the status of the project version and the number of passing, failing |
| 1380 | + and skipped goals. |
| 1381 | +
|
| 1382 | + Parameters |
| 1383 | + ---------- |
| 1384 | + id : str |
| 1385 | + UUID of the project to be loaded. You can find the UUID of a project by |
| 1386 | + navigating to the project's page on the Openlayer platform. |
| 1387 | +
|
| 1388 | + .. note:: |
| 1389 | + When you run :obj:`push`, it will return the project version object, |
| 1390 | + which you can use to check your goal statuses. |
| 1391 | +
|
| 1392 | + Returns |
| 1393 | + ------- |
| 1394 | + ProjectVersion |
| 1395 | + An object that is used to check for upload progress and goal statuses. |
| 1396 | + Also contains other useful information about a project version. |
| 1397 | +
|
| 1398 | + Examples |
| 1399 | + -------- |
| 1400 | + Instantiate the client and load the project version: |
| 1401 | +
|
| 1402 | + >>> import openlayer |
| 1403 | + >>> client = openlayer.OpenlayerClient('YOUR_API_KEY_HERE') |
| 1404 | + >>> |
| 1405 | + >>> version = client.load_project_version(id='YOUR_PROJECT_ID_HERE') |
| 1406 | + >>> version.wait_for_completion() |
| 1407 | + >>> version.print_goal_report() |
| 1408 | +
|
| 1409 | + With the ProjectVersion object loaded, you are able to check progress and |
| 1410 | + goal statuses. |
| 1411 | + """ |
| 1412 | + endpoint = f"versions/{version_id}" |
| 1413 | + version_data = self.api.get_request(endpoint) |
| 1414 | + version = ProjectVersion(version_data, self) |
| 1415 | + return version |
0 commit comments