graviti.manager.draft#

The implementation of the Draft and DraftManager.

Module Contents#

Classes#

Draft

The basic structure of the Graviti draft.

DraftManager

This class defines the operations on the draft in Graviti.

class graviti.manager.draft.Draft(dataset, response)[source]#

Bases: graviti.manager.sheets.Sheets

The basic structure of the Graviti draft.

Parameters
  • dataset (graviti.manager.dataset.Dataset) – Class Dataset instance.

  • response (Dict[str, Any]) –

    The response of the OpenAPI associated with the draft:

    {
        "id": <str>
        "number": <int>
        "state": <str>
        "title": <str>
        "description": <str>
        "branch": <str>
        "parent_commit_id": <Optional[str]>
        "creator": <str>
        "created_at": <str>
        "updated_at": <str>
    }
    

number#

The number of the draft.

state#

The draft state which includes “OPEN”, “CLOSED”, “COMMITTED”.

title#

The title of the draft.

description#

The draft description.

branch#

The based branch of the draft.

parent#

The parent of the draft.

creator#

The creator of the draft.

created_at#

The time when the draft is created.

updated_at#

The time of last update.

edit(self, *, title=None, description=None)[source]#

Update title and description of the draft.

Parameters
  • title (Optional[str]) – The title of the draft.

  • description (Optional[str]) – The description of the draft.

Return type

None

close(self)[source]#

Close the draft.

Return type

None

commit(self, title, description=None, update_dataset_head=True)[source]#

Commit the current draft.

Parameters
  • title (str) – The commit title.

  • description (Optional[str]) – The commit description.

  • update_dataset_head (bool) –

    Whether to update the dataset HEAD.

    • True (the default value): The dataset will be updated to the committed version. At this time, previous modifications to the dataset will be lost.
    • False: The HEAD of the dataset will not be updated. This can be set if the user needs to continue with some operations on the dataset.

Returns

The Branch instance.

Return type

graviti.manager.branch.Branch

Examples

The default scenario: update_dataset_head is True.

>>> dataset = ws.datasets.get("Graviti-dataset-demo")
>>> dataset.HEAD.name  # The version of the dataset is Branch("main").
"main"
>>> dataset.HEAD.commit_id
"524d110ecae7474eaec9471f4a6c28b0"
>>> draft = dataset.drafts.create("draft-4", branch="dev")
>>> draft.commit("commit-4")
Branch("dev")(
  (commit_id): '3db73ac2876a42c0bf43a0489ce1756a',
  (parent): Commit("1b21a40f03ab4cec814ec47ee0d10b24"),
  (title): 'commit-4',
  (committer): 'graviti-example',
  (committed_at): 2022-07-19 04:23:45+00:00
)
>>> dataset.HEAD.name  # The version of the dataset has been updated to Branch("dev").
"dev"
>>> dataset.HEAD.commit_id
"3db73ac2876a42c0bf43a0489ce1756a"

Set update_dataset_head to False.

>>> dataset = ws.datasets.get("Graviti-dataset-demo")
>>> dataset.HEAD.name  # The version of the dataset is Branch("main").
"main"
>>> dataset.HEAD.commit_id
"524d110ecae7474eaec9471f4a6c28b0"
>>> draft = dataset.drafts.create("draft-5", branch="dev")
>>> draft.commit("commit-5", update_dataset_head=False)
Branch("dev")(
  (commit_id): '781007a41d1641859c87cb00f8e32bf3',
  (parent): Commit("3db73ac2876a42c0bf43a0489ce1756a"),
  (title): 'commit-5',
  (committer): 'graviti-example',
  (committed_at): 2022-07-19 04:25:45+00:00
)
>>> dataset.HEAD.name  # The version of the dataset has not been updated.
"main"
>>> dataset.HEAD.commit_id
"524d110ecae7474eaec9471f4a6c28b0"
upload(self, jobs=8, quiet=False)[source]#

Upload the local dataset to Graviti.

Parameters
  • jobs (int) – The number of the max workers in multi-thread upload, the default is 8.

  • quiet (bool) – Set to True to stop showing the upload process bar.

Return type

None

class graviti.manager.draft.DraftManager(dataset)[source]#

This class defines the operations on the draft in Graviti.

Parameters

dataset (graviti.manager.dataset.Dataset) – Dataset instance.

create(self, title, description=None, branch=CURRENT_BRANCH)[source]#

Create a draft.

Parameters
  • title (str) – The draft title.

  • description (Optional[str]) – The draft description.

  • branch (str) – The branch name. The default value is the current branch of the dataset.

Returns

The Draft instance with the given title and description.

Raises

StatusError – When creating the draft without basing on a branch.

Return type

Draft

get(self, draft_number)[source]#

Get the certain draft with the given draft number.

Parameters

draft_number (int) – The required draft number.

Returns

The Draft instance with the given number.

Return type

Draft

list(self, state='OPEN', branch=ALL_BRANCHES)[source]#

List all the drafts.

Parameters
  • state (str) – The draft state which includes “OPEN”, “CLOSED”, “COMMITTED”, “ALL”. The default value is “OPEN”.

  • branch (str) – The branch name. The default value is all branches.

Returns

The LazyPagingList of drafts instances.

Return type

graviti.manager.lazy.LazyPagingList[Draft]