Skip to content

Commit

Permalink
feat(client): design structure and interfaces of squashAndMergeJob
Browse files Browse the repository at this point in the history
  • Loading branch information
graczhual committed Dec 16, 2021
1 parent 775f1d4 commit c32ee57
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 1 deletion.
11 changes: 10 additions & 1 deletion tensorbay/client/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from tensorbay.client.segment import _STRATEGIES, FusionSegmentClient, SegmentClient
from tensorbay.client.statistics import Statistics
from tensorbay.client.status import Status
from tensorbay.client.version import JobMixin, VersionControlMixin
from tensorbay.client.version import JobMixin, SquashAndMerge, VersionControlMixin
from tensorbay.dataset import AuthData, Data, Frame, FusionSegment, Notes, RemoteData, Segment
from tensorbay.exception import (
FrameError,
Expand Down Expand Up @@ -216,6 +216,15 @@ def cache_enabled(self) -> bool:
"""
return bool(self._cache_path) and not self.status.is_draft

@property
def squash_and_merges(self) -> SquashAndMerge:
"""Get class :class:`~tensorbay.client.version.SquashAndMerge`.
Return:
Required :class:`~tensorbay.client.version.SquashAndMerge`.
"""

def enable_cache(self, cache_path: str = "") -> None:
"""Enable cache when open the remote data of the dataset.
Expand Down
14 changes: 14 additions & 0 deletions tensorbay/client/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from typing import Any, Dict, Optional, Tuple, Type, TypeVar

from tensorbay.client.struct import Draft
from tensorbay.utility import AttrsMixin, ReprMixin, ReprType, attr, camel, common_loads


Expand Down Expand Up @@ -118,3 +119,16 @@ def update(self, until_complete: bool = False) -> None:
until_complete: Whether to update job information until it is complete.
"""


class SquashAndMergeJob(Job):
"""This class defines :class:`SquashAndMergeJob`."""

@property
def result(self) -> Optional[Draft]:
"""Get the result of the SquashAndMergeJob.
Return:
The draft obtained from SquashAndMergeJob.
"""
108 changes: 108 additions & 0 deletions tensorbay/client/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from typing import Any, Dict, Generator, Optional, Union

from tensorbay.client.job import SquashAndMergeJob
from tensorbay.client.lazy import PagingList
from tensorbay.client.requests import Client
from tensorbay.client.status import Status
Expand Down Expand Up @@ -659,3 +660,110 @@ def _generate_jobs(
The generator of job info.
"""


class SquashAndMerge(JobMixin):
"""This class defines :class:`SquashAndMerge`.
Arguments:
dataset_id: Dataset ID.
client: The :class:`~tensorbay.client.requests.Client`.
status: The version control status of the dataset.
"""

def __init__(
self,
dataset_id: str,
client: Client,
status: Status,
) -> None:
self._dataset_id = dataset_id
self._client = client
self._status = status

def create_job(
self,
title: str = "",
description: str = "",
*,
draft_title: str,
source_branch_name: str,
target_branch_name: Optional[str] = None,
draft_description: str = "",
strategy: Optional[str] = "abort",
) -> SquashAndMergeJob:
"""Create a :class:`SquashAndMergeJob`.
Squash commits in source branch, then merge into target branch by creating a new draft.
If the target branch name is not given, the draft will be based on the branch name stored
in the dataset client. And during merging, the conflicts between branches can be resolved
in three different strategies: "abort", "override" and "skip".
Arguments:
title: The SquashAndMergeJob title.
description: The SquashAndMergeJob description.
draft_title: The draft title.
source_branch_name: The name of the branch to be squashed.
target_branch_name: The target branch name of the merge operation.
draft_description: The draft description.
strategy: The strategy of handling the branch conflict. There are three options:
1. "abort": abort the opetation;
2. "override": the squashed branch will override the target branch;
3. "skip": keep the origin branch.
Raises:# flake8: noqa: F402
StatusError: When squashing and merging without basing on a branch.
Return:
The SquashAndMergeJob.
"""

def get_job(self, job_id: str) -> SquashAndMergeJob:
"""Get a :class:`SquashAndMergeJob`.
Arguments:
job_id: The SquashAndMergeJob id.
Return:
The SquashAndMergeJob.
"""

def list_jobs(self, status: Optional[str] = None) -> PagingList[SquashAndMergeJob]:
"""List the SquashAndMergeJob.
Arguments:
status: The SquashAndMergeJob status which includes "QUEUING", "PROCESSING", "SUCCESS",
"FAIL", "ABORT" and None. None means all kinds of status.
Return:
The PagingList of SquashAndMergeJob.
"""

def abort_job(self, job_id: str) -> None:
"""Abort a :class:`SquashAndMergeJob`.
Arguments:
job_id: The SquashAndMergeJob id.
"""

def retry_job(self, job_id: str) -> None:
"""Retry a :class:`SquashAndMergeJob`.
Arguments:
job_id: The SquashAndMergeJob id.
"""

def delete_job(self, job_id: str) -> None:
"""Delete a :class:`SquashAndMergeJob`.
Arguments:
job_id: The SquashAndMergeJob id.
"""

0 comments on commit c32ee57

Please sign in to comment.