towhee.hub.operator_manager.OperatorManager

class towhee.hub.operator_manager.OperatorManager(author: str, repo: str, root: str = 'https://hub.towhee.io')[source]

Bases: RepoManager

The Repo Manager to manage the operator repos.

Parameters:
  • author (str) – The author of the repo.

  • repo (str) – The name of the repo.

  • root (str) – The root url where the repo located.

Methods

create

Create a repo under current account.

create_with_token

Create a repo under current account.

download

Download repo without git.

download_executor

Load the content from url and write into local files.

download_files

Download the given files.

exists

Check if a repo exists.

get_file_list

Get all the files in the current repo at the given commit.

get_repo_type

Get the repo type.

init_nnoperator

Initialize the files under file_dest by moving and updating the text under file_temp.

init_pyoperator

Initialize the files under file_dest by moving and updating the text under file_temp.

latest_commit

Grab the latest commit of a tag.

obtain_lfs_extensions

Download the .gitattributes file from the specified repo in order to figure out which files are being tracked by git-lfs.

Attributes

author

repo

root

__init__(author: str, repo: str, root: str = 'https://hub.towhee.io')[source]
create(password: str) None[source]

Create a repo under current account.

Parameters:

password (str) – Current author’s password.

Raises:

HTTPError – Raise error in request.

create_with_token(token: str) None[source]

Create a repo under current account.

Parameters:

token (str) – Current author’s token.

Raises:

HTTPError – Raise error in request.

download(local_repo_path: Union[str, Path] = PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/towhee/checkouts/main/towhee/doc/source'), tag: str = 'main', install_reqs: bool = True) None

Download repo without git.

Agrs:
local_repo_path (Union[str, Path]):

Thre local dir to download the files into.

tag (str):

The tag of the repo to download.

install_reqs (bool):

Whether to install packages from requirements.txt.

download_executor(tag: str, file_name: str, lfs_files: Tuple[str], local_repo_path: Union[str, Path]) None

Load the content from url and write into local files.

Parameters:
  • tag (str) – The tag name.

  • file_name (str) – The hub file paths.

  • lfs_files (`str) – The file extensions being tracked by git-lfs.

  • local_repo_path (Union[str, Path]) – The local directory to download to.

Raises:
  • (HTTPError) – Rasie error in request.

  • (OSError) – Raise error in writing file.

download_files(tag: str, file_list: List[str], lfs_files: List[str], local_repo_path: Union[str, Path], install_reqs: bool) None

Download the given files.

Agrs:
tag (str):

The tag of the repo to download.

file_list (List[str]):

The files to download

lfs_files (List[str]):

The lfs files extensions.

local_repo_path (Union[str, Path]):

Thre local dir to download the files into.

install_reqs (bool):

Whether to install packages from requirements.txt.

exists() bool

Check if a repo exists.

Returns:

(bool)

return True if the repository exists, else False.

get_file_list(commit: str) List[str]

Get all the files in the current repo at the given commit.

This is done through forming a git tree recursively and filtering out all the files.

Parameters:

commit (str) – The commit to base current existing files.

Returns:

(List[str])

The file paths for the repo

Raises:

(HTTPError) – Raise error in request.

get_repo_type()

Get the repo type.

Returns:

(int)

{2: ‘operator’, 3: ‘pipeline’}.

init_nnoperator(file_temp: Union[str, Path], file_dest: Union[str, Path]) None[source]

Initialize the files under file_dest by moving and updating the text under file_temp.

Parameters:
  • file_temp (Union[str, Path]) – The path to the template files.

  • file_dest (Union[str, Path]) – The path to the local repo to init.

Raises:
  • HTTPError – Raise error in request.

  • OSError – Raise error in writing file.

init_pyoperator(file_temp: Union[str, Path], file_dest: Union[str, Path]) None[source]

Initialize the files under file_dest by moving and updating the text under file_temp.

Parameters:
  • file_temp (Union[str, Path]) – The path to the template files.

  • file_dest (Union[str, Path]) – The path to the local repo to init.

Raises:
  • HTTPError – Raise error in request.

  • OSError – Raise error in writing file.

latest_commit(tag: str) str

Grab the latest commit of a tag.

Parameters:

tag (str) – The tag name.

Returns:

(str)

The latest commit hash cut down to 10 characters.

Raises:

(HTTPError) – Raise error in request.

obtain_lfs_extensions(tag: str) List[str]

Download the .gitattributes file from the specified repo in order to figure out which files are being tracked by git-lfs.

Lines that deal with git-lfs take on the following format:

```

*.extension filter=lfs merge=lfs …

```

Parameters:

tag (str) – The tag name.

Returns:

(List[str])

The list of file extentions tracked by git-lfs.