diff --git a/gazu/context.py b/gazu/context.py index 1e39d02..8ba9340 100644 --- a/gazu/context.py +++ b/gazu/context.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from . import user as gazu_user from . import project as gazu_project from . import asset as gazu_asset @@ -6,7 +8,7 @@ from . import scene as gazu_scene -def all_open_projects(user_context=False): +def all_open_projects(user_context: bool = False) -> list[dict]: """ Return the list of projects for which the user has a task. """ @@ -16,7 +18,9 @@ def all_open_projects(user_context=False): return gazu_project.all_open_projects() -def all_assets_for_project(project, user_context=False): +def all_assets_for_project( + project: str | dict, user_context: bool = False +) -> list[dict]: """ Return the list of assets for which the user has a task. """ @@ -26,7 +30,9 @@ def all_assets_for_project(project, user_context=False): return gazu_asset.all_assets_for_project(project) -def all_asset_types_for_project(project, user_context=False): +def all_asset_types_for_project( + project: str | dict, user_context: bool = False +) -> list[dict]: """ Return the list of asset types for which the user has a task. """ @@ -37,8 +43,8 @@ def all_asset_types_for_project(project, user_context=False): def all_assets_for_asset_type_and_project( - project, asset_type, user_context=False -): + project: str | dict, asset_type: str | dict, user_context: bool = False +) -> list[dict]: """ Return the list of assets for given project and asset_type and for which the user has a task. @@ -51,7 +57,9 @@ def all_assets_for_asset_type_and_project( return gazu_asset.all_assets_for_project_and_type(project, asset_type) -def all_task_types_for_asset(asset, user_context=False): +def all_task_types_for_asset( + asset: str | dict, user_context: bool = False +) -> list[dict]: """ Return the list of tasks for given asset and current user. """ @@ -61,7 +69,9 @@ def all_task_types_for_asset(asset, user_context=False): return gazu_task.all_task_types_for_asset(asset) -def all_task_types_for_shot(shot, user_context=False): +def all_task_types_for_shot( + shot: str | dict, user_context: bool = False +) -> list[dict]: """ Return the list of tasks for given shot and current user. """ @@ -71,7 +81,9 @@ def all_task_types_for_shot(shot, user_context=False): return gazu_task.all_task_types_for_shot(shot) -def all_task_types_for_scene(scene, user_context=False): +def all_task_types_for_scene( + scene: str | dict, user_context: bool = False +) -> list[dict]: """ Return the list of tasks for given scene and current user. """ @@ -81,7 +93,9 @@ def all_task_types_for_scene(scene, user_context=False): return gazu_task.all_task_types_for_scene(scene) -def all_task_types_for_sequence(sequence, user_context=False): +def all_task_types_for_sequence( + sequence: str | dict, user_context: bool = False +) -> list[dict]: """ Return the list of tasks for given sequence and current user. """ @@ -91,7 +105,9 @@ def all_task_types_for_sequence(sequence, user_context=False): return gazu_task.all_task_types_for_sequence(sequence) -def all_sequences_for_project(project, user_context=False): +def all_sequences_for_project( + project: str | dict, user_context: bool = False +) -> list[dict]: """ Return the list of sequences for given project and current user. """ @@ -101,7 +117,9 @@ def all_sequences_for_project(project, user_context=False): return gazu_shot.all_sequences_for_project(project) -def all_scenes_for_project(project, user_context=False): +def all_scenes_for_project( + project: str | dict, user_context: bool = False +) -> list[dict]: """ Return the list of scenes for given project and current user. """ @@ -111,7 +129,9 @@ def all_scenes_for_project(project, user_context=False): return gazu_scene.all_scenes(project) -def all_shots_for_sequence(sequence, user_context=False): +def all_shots_for_sequence( + sequence: str | dict, user_context: bool = False +) -> list[dict]: """ Return the list of shots for given sequence and current user. """ @@ -121,7 +141,9 @@ def all_shots_for_sequence(sequence, user_context=False): return gazu_shot.all_shots_for_sequence(sequence) -def all_scenes_for_sequence(sequence, user_context=False): +def all_scenes_for_sequence( + sequence: str | dict, user_context: bool = False +) -> list[dict]: """ Return the list of scenes for given sequence and current user. """ @@ -131,7 +153,9 @@ def all_scenes_for_sequence(sequence, user_context=False): return gazu_scene.all_scenes_for_sequence(sequence) -def all_sequences_for_episode(episode, user_context=False): +def all_sequences_for_episode( + episode: str | dict, user_context: bool = False +) -> list[dict]: """ Return the list of shots for given sequence and current user. """ @@ -141,7 +165,9 @@ def all_sequences_for_episode(episode, user_context=False): return gazu_shot.all_sequences_for_episode(episode) -def all_episodes_for_project(project, user_context=False): +def all_episodes_for_project( + project: str | dict, user_context: bool = False +) -> list[dict]: """ Return the list of shots for given sequence and current user. """ diff --git a/gazu/edit.py b/gazu/edit.py index d7922e1..1ef8600 100644 --- a/gazu/edit.py +++ b/gazu/edit.py @@ -1,6 +1,9 @@ +from __future__ import annotations + from . import client as raw from .cache import cache +from .client import KitsuClient from .helpers import normalize_model_parameter from gazu.sorting import sort_by_name @@ -8,7 +11,7 @@ @cache -def get_edit(edit_id, client=default): +def get_edit(edit_id: str, client: KitsuClient = default) -> dict: """ Args: edit_id (str): ID of claimed edit. @@ -20,7 +23,9 @@ def get_edit(edit_id, client=default): @cache -def get_edit_by_name(project, edit_name, client=default): +def get_edit_by_name( + project: str | dict, edit_name: str, client: KitsuClient = default +) -> dict | None: """ Args: project (str / dict): The project dict or the project ID. @@ -38,7 +43,7 @@ def get_edit_by_name(project, edit_name, client=default): @cache -def get_edit_url(edit, client=default): +def get_edit_url(edit: str | dict, client: KitsuClient = default) -> str: """ Args: edit (str / dict): The edit dict or the edit ID. @@ -62,7 +67,9 @@ def get_edit_url(edit, client=default): @cache -def all_edits_for_project(project, client=default): +def all_edits_for_project( + project: str | dict, client: KitsuClient = default +) -> list[dict]: """ Args: project (str / dict): The project dict or the project ID. @@ -76,7 +83,9 @@ def all_edits_for_project(project, client=default): @cache -def all_previews_for_edit(edit, client=default): +def all_previews_for_edit( + edit: str | dict, client: KitsuClient = default +) -> list[dict]: """ Args: edit (str / dict): The edit dict or the edit ID. @@ -89,13 +98,13 @@ def all_previews_for_edit(edit, client=default): def new_edit( - project, - name, - description=None, - data={}, - episode=None, - client=default, -): + project: str | dict, + name: str, + description: str | None = None, + data: dict = {}, + episode: str | dict | None = None, + client: KitsuClient = default, +) -> dict: """ Create an edit for given project (and episode if given). Allow to set metadata too. @@ -128,12 +137,20 @@ def new_edit( return edit -def remove_edit(edit, force=False, client=default): +def remove_edit( + edit: str | dict, force: bool = False, client: KitsuClient = default +) -> str: """ Remove given edit from database. + If the Edit has tasks linked to it, this will by default mark the + Edit as canceled. Deletion can be forced regardless of task links + with the `force` parameter. + Args: - edit (dict / str): Edit to remove. + edit (str / dict): Edit to remove. + force (bool): Whether to force deletion of the edit regardless of + whether it has links to tasks. """ edit = normalize_model_parameter(edit) path = "data/edits/%s" % edit["id"] @@ -143,7 +160,7 @@ def remove_edit(edit, force=False, client=default): return raw.delete(path, params, client=client) -def update_edit(edit, client=default): +def update_edit(edit: dict, client: KitsuClient = default) -> dict: """ Save given edit data into the API. Metadata are fully replaced by the ones set on given edit. @@ -157,13 +174,15 @@ def update_edit(edit, client=default): return raw.put("data/entities/%s" % edit["id"], edit, client=client) -def update_edit_data(edit, data={}, client=default): +def update_edit_data( + edit: str | dict, data: dict = {}, client: KitsuClient = default +) -> dict: """ Update the metadata for the provided edit. Keys that are not provided are not changed. Args: - edit (dict / ID): The edit dict or ID to save in database. + edit (str / dict): The edit dict or ID to save in database. data (dict): Free field to set metadata of any kind. Returns: diff --git a/gazu/encoder.py b/gazu/encoder.py index 655705c..b5aedd7 100644 --- a/gazu/encoder.py +++ b/gazu/encoder.py @@ -1,6 +1,8 @@ import json import datetime +from typing import Any + class CustomJSONEncoder(json.JSONEncoder): """ @@ -8,7 +10,7 @@ class CustomJSONEncoder(json.JSONEncoder): The standard does not want to assum how you handle dates. """ - def default(self, obj): + def default(self, obj: Any) -> Any: if isinstance(obj, datetime.datetime): return obj.isoformat() diff --git a/gazu/entity.py b/gazu/entity.py index 2f23f04..bd45706 100644 --- a/gazu/entity.py +++ b/gazu/entity.py @@ -1,6 +1,9 @@ +from __future__ import annotations + from . import client as raw from .cache import cache +from .client import KitsuClient from .sorting import sort_by_name from .helpers import normalize_model_parameter @@ -8,7 +11,7 @@ @cache -def all_entities(client=default): +def all_entities(client: KitsuClient = default) -> list[dict]: """ Returns: list: Retrieve all entities @@ -17,7 +20,7 @@ def all_entities(client=default): @cache -def all_entity_types(client=default): +def all_entity_types(client: KitsuClient = default) -> list[dict]: """ Returns: list: Entity types listed in database. @@ -26,7 +29,7 @@ def all_entity_types(client=default): @cache -def get_entity(entity_id, client=default): +def get_entity(entity_id: str, client: KitsuClient = default) -> dict: """ Args: entity_id (str): ID of claimed entity. @@ -39,11 +42,15 @@ def get_entity(entity_id, client=default): @cache -def get_entity_by_name(entity_name, project=None, client=default): +def get_entity_by_name( + entity_name: str, + project: str | dict | None = None, + client: KitsuClient = default, +) -> dict | None: """ Args: - name (str): The name of the claimed entity. - project (str, dict): Project ID or dict. + entity_name (str): The name of the claimed entity. + project (str / dict): Project ID or dict. Returns: Retrieve entity matching given name (and project if given). @@ -56,10 +63,13 @@ def get_entity_by_name(entity_name, project=None, client=default): @cache -def get_entity_type(entity_type_id, client=default): +def get_entity_type( + entity_type_id: str, client: KitsuClient = default +) -> dict: """ Args: entity_type_id (str): ID of claimed entity type. + Returns: Retrieve entity type matching given ID (It can be an entity type of any kind). @@ -68,7 +78,9 @@ def get_entity_type(entity_type_id, client=default): @cache -def get_entity_type_by_name(entity_type_name, client=default): +def get_entity_type_by_name( + entity_type_name: str, client: KitsuClient = default +) -> dict | None: """ Args: entity_type_name (str): The name of the claimed entity type @@ -82,17 +94,17 @@ def get_entity_type_by_name(entity_type_name, client=default): @cache -def guess_from_path(project_id, path, sep="/"): +def guess_from_path(project_id: str, path: str, sep: str = "/") -> list[dict]: """ Get list of possible project file tree templates matching a file path and data ids corresponding to template tokens. Args: project_id (str): Project id of given file - file_path (str): Path to a file + path (str): Path to a file sep (str): File path separator, defaults to "/" Returns: - list: dictionnaries with the corresponding entities and template name. + list: dictionaries with the corresponding entities and template name. """ return raw.post( "/data/entities/guess_from_path", @@ -100,38 +112,52 @@ def guess_from_path(project_id, path, sep="/"): ) -def new_entity_type(name, client=default): +def new_entity_type(name: str, client: KitsuClient = default) -> dict: """ Creates an entity type with the given name. Args: - name (str, client=default): The name of the entity type + name (str): The name of the entity type Returns: dict: The created entity type + + Raises: + gazu.exception.ParameterException: + If an entity type with that name already exists. """ data = {"name": name} return raw.create("entity-types", data, client=client) -def remove_entity_type(entity_type, client=default): +def remove_entity_type( + entity_type: str | dict, client: KitsuClient = default +) -> str: """ Remove given entity type from database. Args: - entity_type (dict / str): Entity type to remove. + entity_type (str / dict): Entity type to remove. """ entity_type = normalize_model_parameter(entity_type) path = "data/entity-types/%s" % entity_type["id"] return raw.delete(path, client=client) -def remove_entity(entity, force=False, client=default): +def remove_entity( + entity: str | dict, force: bool = False, client: KitsuClient = default +) -> str: """ Remove given entity from database. + If the Entity has tasks linked to it, this will by default mark the + Entity as canceled. Deletion can be forced regardless of task links + with the `force` parameter. + Args: entity (dict): Entity to remove. + force (bool): Whether to force deletion of the entity regardless of + whether it has links to tasks. """ entity = normalize_model_parameter(entity) path = "data/entities/%s" % entity["id"] @@ -141,10 +167,13 @@ def remove_entity(entity, force=False, client=default): return raw.delete(path, params, client=client) -def all_entities_with_tasks_linked_to_entity(entity, client=default): +def all_entities_with_tasks_linked_to_entity( + entity: str | dict, client: KitsuClient = default +) -> list[dict]: """ Args: - entity (dict): Entity to get linked entities. + entity (str / dict): Entity to get linked entities. + Returns: list: Retrieve all entities linked to given entity. """ diff --git a/gazu/events.py b/gazu/events.py index 0bace91..3290aef 100644 --- a/gazu/events.py +++ b/gazu/events.py @@ -4,10 +4,12 @@ import signal import socketio +from typing import Any, Callable + from engineio.base_client import signal_handler from .exception import AuthFailedException -from .client import default_client, get_event_host, make_auth_header +from .client import default_client, get_event_host, KitsuClient, make_auth_header if os.name == "nt": @@ -25,23 +27,23 @@ def WindowsSignalHandler(event): class EventsNamespace(socketio.ClientNamespace): - def on_connect(self): + def on_connect(self) -> None: pass - def on_disconnect(self): + def on_disconnect(self) -> None: pass - def on_error(self, data): + def on_error(self, data: str) -> str: return connect_error(data) def init( - client=default_client, - ssl_verify=False, - reconnection=True, - logger=False, - **kwargs -): + client: KitsuClient = default_client, + ssl_verify: bool = False, + reconnection: bool = True, + logger: bool = False, + **kwargs: Any +) -> socketio.Client: """ Init configuration for SocketIO client. @@ -61,13 +63,15 @@ def init( return event_client -def connect_error(data): +def connect_error(data: str) -> str: print("The connection failed!") print(data) return data -def add_listener(event_client, event_name, event_handler): +def add_listener( + event_client: socketio.Client, event_name: str, event_handler: Callable +) -> socketio.Client: """ Set a listener that reacts to a given event. """ @@ -75,7 +79,7 @@ def add_listener(event_client, event_name, event_handler): return event_client -def run_client(event_client): +def run_client(event_client: socketio.Client) -> socketio.Client: """ Run event client (it blocks current thread). It listens to all events configured. diff --git a/gazu/files.py b/gazu/files.py index 7392d56..76f2ed5 100644 --- a/gazu/files.py +++ b/gazu/files.py @@ -1,13 +1,20 @@ +from __future__ import annotations + +from typing_extensions import Literal + +import requests + from . import client as raw from .cache import cache +from .client import KitsuClient from .helpers import normalize_model_parameter default = raw.default_client @cache -def all_output_types(client=default): +def all_output_types(client: KitsuClient = default) -> list[dict]: """ Returns: list: Output types listed in database. @@ -16,7 +23,9 @@ def all_output_types(client=default): @cache -def all_output_types_for_entity(entity, client=default): +def all_output_types_for_entity( + entity: str | dict, client: KitsuClient = default +) -> list[dict]: """ Args: entity (str / dict): The entity dict or the entity ID. @@ -32,8 +41,8 @@ def all_output_types_for_entity(entity, client=default): @cache def all_output_types_for_asset_instance( - asset_instance, temporal_entity, client=default -): + asset_instance: dict, temporal_entity: dict, client: KitsuClient = default +) -> list[dict]: """ Returns: list: Output types for given asset instance and entity (shot or scene). @@ -46,7 +55,9 @@ def all_output_types_for_asset_instance( @cache -def get_output_type(output_type_id, client=default): +def get_output_type( + output_type_id: str, client: KitsuClient = default +) -> dict: """ Args: output_type_id (str): ID of claimed output type. @@ -58,7 +69,9 @@ def get_output_type(output_type_id, client=default): @cache -def get_output_type_by_name(output_type_name, client=default): +def get_output_type_by_name( + output_type_name: str, client: KitsuClient = default +) -> dict | None: """ Args: output_type_name (str): name of claimed output type. @@ -71,7 +84,9 @@ def get_output_type_by_name(output_type_name, client=default): ) -def new_output_type(name, short_name, client=default): +def new_output_type( + name: str, short_name: str, client: KitsuClient = default +) -> dict: """ Create a new output type in database. @@ -91,7 +106,9 @@ def new_output_type(name, short_name, client=default): @cache -def get_output_file(output_file_id, client=default): +def get_output_file( + output_file_id: str, client: KitsuClient = default +) -> dict: """ Args: output_file_id (str): ID of claimed output file. @@ -104,21 +121,26 @@ def get_output_file(output_file_id, client=default): @cache -def get_output_file_by_path(path, client=default): +def get_output_file_by_path( + path: str, client: KitsuClient = default +) -> dict | None: """ Args: path (str): Path of claimed output file. Returns: - dict: Output file matching given path. + dict: Output file matching given path, or None if there are no matches. """ return raw.fetch_first("output-files", {"path": path}, client=client) @cache def get_all_working_files_for_entity( - entity, task=None, name=None, client=default -): + entity: str | dict, + task: str | dict | None = None, + name: str | None = None, + client: KitsuClient = default, +) -> list[dict]: """ Retrieves all the working files of a given entity and specied parameters """ @@ -136,7 +158,9 @@ def get_all_working_files_for_entity( @cache -def get_preview_file(preview_file_id, client=default): +def get_preview_file( + preview_file_id: str, client: KitsuClient = default +) -> dict: """ Args: preview_file_id (str): ID of claimed preview file. @@ -147,12 +171,23 @@ def get_preview_file(preview_file_id, client=default): return raw.fetch_one("preview-files", preview_file_id, client=client) -def remove_preview_file(preview_file, force=False, client=default): +def remove_preview_file( + preview_file: str | dict, + force: bool = False, + client: KitsuClient = default, +) -> str: """ Remove given preview file from database. + Depending on the configuration of the Kitsu server, the stored files linked + to the preview file may or may not be removed on deletion of a preview file. + The `force=True` parameter can be used to force deletion of the files + regardless of server config. + Args: preview_file (str / dict): The preview_file dict or ID. + force (bool): Whether to force deletion of the files linked to the + preview file in storage. """ preview_file = normalize_model_parameter(preview_file) params = {} @@ -166,12 +201,14 @@ def remove_preview_file(preview_file, force=False, client=default): @cache -def get_all_preview_files_for_task(task, client=default): +def get_all_preview_files_for_task( + task: str | dict, client: KitsuClient = default +) -> list[dict]: """ Retrieves all the preview files for a given task. Args: - task (str, id): Target task + task (str / dict): Target task, as ID string or model dict. """ task = normalize_model_parameter(task) return raw.fetch_all( @@ -180,12 +217,14 @@ def get_all_preview_files_for_task(task, client=default): @cache -def get_all_attachment_files_for_task(task, client=default): +def get_all_attachment_files_for_task( + task: str | dict, client: KitsuClient = default +) -> list[dict]: """ Retrieves all the attachment files for a given task. Args: - task (str, id): Target task + task (str / dict): Target task, as ID string or model dict. """ task = normalize_model_parameter(task) return raw.fetch_all( @@ -194,14 +233,14 @@ def get_all_attachment_files_for_task(task, client=default): def all_output_files_for_entity( - entity, - output_type=None, - task_type=None, - name=None, - representation=None, - file_status=None, - client=default, -): + entity: str | dict, + output_type: str | dict | None = None, + task_type: str | dict | None = None, + name: str | None = None, + representation: str | None = None, + file_status: str | dict | None = None, + client: KitsuClient = default, +) -> list[dict]: """ Args: entity (str / dict): The entity dict or ID. @@ -239,15 +278,15 @@ def all_output_files_for_entity( @cache def all_output_files_for_asset_instance( - asset_instance, - temporal_entity=None, - task_type=None, - output_type=None, - name=None, - representation=None, - file_status=None, - client=default, -): + asset_instance: str | dict, + temporal_entity: str | dict | None = None, + task_type: str | dict | None = None, + output_type: str | dict | None = None, + name: str | None = None, + representation: str | None = None, + file_status: str | dict | None = None, + client: KitsuClient = default, +) -> list[dict]: """ Args: asset_instance (str / dict): The instance dict or ID. @@ -289,17 +328,17 @@ def all_output_files_for_asset_instance( def all_output_files_for_project( - project, - output_type=None, - task_type=None, - name=None, - representation=None, - file_status=None, - client=default, -): + project: str | dict, + output_type: str | dict | None = None, + task_type: str | dict | None = None, + name: str | None = None, + representation: str | None = None, + file_status: str | dict | None = None, + client: KitsuClient = default, +) -> list[dict]: """ Args: - entity (str / dict): The entity dict or ID. + project (str / dict): The project dict or ID. output_type (str / dict): The output type dict or ID. task_type (str / dict): The task type dict or ID. name (str): The file name @@ -335,16 +374,16 @@ def all_output_files_for_project( @cache -def all_softwares(client=default): +def all_softwares(client: KitsuClient = default) -> list[dict]: """ Returns: - dict: Software versions listed in database. + list[dict]: Software versions listed in database. """ return raw.fetch_all("softwares", client=client) @cache -def get_software(software_id, client=default): +def get_software(software_id: str, client: KitsuClient = default) -> dict: """ Args: software_id (str): ID of claimed output type. @@ -356,7 +395,9 @@ def get_software(software_id, client=default): @cache -def get_software_by_name(software_name, client=default): +def get_software_by_name( + software_name: str, client: KitsuClient = default +) -> dict | None: """ Args: software_name (str): Name of claimed output type. @@ -367,7 +408,12 @@ def get_software_by_name(software_name, client=default): return raw.fetch_first("softwares", {"name": software_name}, client=client) -def new_software(name, short_name, file_extension, client=default): +def new_software( + name: str, + short_name: str, + file_extension: str, + client: KitsuClient = default, +) -> dict: """ Create a new software in datatabase. @@ -393,23 +439,23 @@ def new_software(name, short_name, file_extension, client=default): @cache def build_working_file_path( - task, - name="main", - mode="working", - software=None, - revision=1, - sep="/", - client=default, -): + task: str | dict, + name: str = "main", + mode: str = "working", + software: str | dict | None = None, + revision: int = 1, + sep: str = "/", + client: KitsuClient = default, +) -> str: """ From the file path template configured at the project level and arguments, it builds a file path location where to store related DCC file. Args: - task (str / id): Task related to working file. + task (str / dict): Task related to working file. name (str): Additional suffix for the working file name. mode (str): Allow to select a template inside the template. - software (str / id): Software at the origin of the file. + software (str / dict): Software at the origin of the file. revision (int): File revision. sep (str): OS separator. @@ -433,30 +479,30 @@ def build_working_file_path( @cache def build_entity_output_file_path( - entity, - output_type, - task_type, - name="main", - mode="output", - representation="", - revision=0, - nb_elements=1, - sep="/", - client=default, -): + entity: str | dict, + output_type: str | dict, + task_type: str | dict, + name: str = "main", + mode: str = "output", + representation: str = "", + revision: int = 0, + nb_elements: int = 1, + sep: str = "/", + client: KitsuClient = default, +) -> str: """ From the file path template configured at the project level and arguments, it builds a file path location where to store related DCC output file. Args: - entity (str / id): Entity for which an output file is needed. - output_type (str / id): Output type of the generated file. - task_type (str / id): Task type related to output file. + entity (str / dict): Entity for which an output file is needed. + output_type (str / dict): Output type of the generated file. + task_type (str / dict): Task type related to output file. name (str): Additional suffix for the working file name. mode (str): Allow to select a template inside the template. representation (str): Allow to select a template inside the template. revision (int): File revision. - nb_elements (str): To represent an image sequence, the amount of file is + nb_elements (int): To represent an image sequence, the amount of file is needed. sep (str): OS separator. @@ -489,32 +535,32 @@ def build_entity_output_file_path( @cache def build_asset_instance_output_file_path( - asset_instance, - temporal_entity, - output_type, - task_type, - name="main", - representation="", - mode="output", - revision=0, - nb_elements=1, - sep="/", - client=default, -): + asset_instance: str | dict, + temporal_entity: str | dict, + output_type: str | dict, + task_type: str | dict, + name: str = "main", + representation: str = "", + mode: str = "output", + revision: int = 0, + nb_elements: int = 1, + sep: str = "/", + client: KitsuClient = default, +) -> str: """ From the file path template configured at the project level and arguments, it builds a file path location where to store related DCC output file. Args: - asset_instance_id entity (str / id): Asset instance for which a file + asset_instance_id entity (str / dict): Asset instance for which a file is required. - temporal entity (str / id): Temporal entity scene or shot in which + temporal entity (str / dict): Temporal entity scene or shot in which the asset instance appeared. - output_type (str / id): Output type of the generated file. - task_type (str / id): Task type related to output file. + output_type (str / dict): Output type of the generated file. + task_type (str / dict): Task type related to output file. name (str): Additional suffix for the working file name. - mode (str): Allow to select a template inside the template. representation (str): Allow to select a template inside the template. + mode (str): Allow to select a template inside the template. revision (int): File revision. nb_elements (str): To represent an image sequence, the amount of file is needed. @@ -551,28 +597,28 @@ def build_asset_instance_output_file_path( def new_working_file( - task, - name="main", - mode="working", - software=None, - comment="", - person=None, - revision=0, - sep="/", - client=default, -): + task: str | dict, + name: str = "main", + mode: str = "working", + software: str | dict | None = None, + comment: str = "", + person: str | dict | None = None, + revision: int = 0, + sep: str = "/", + client: KitsuClient = default, +) -> dict: """ Create a new working_file for given task. It generates and store the expected path for given task and options. It sets a revision number (last revision + 1). Args: - task (str / id): Task related to working file. + task (str / dict): Task related to working file. name (str): Additional suffix for the working file name. mode (str): Allow to select a template inside the template. - software (str / id): Software at the origin of the file. + software (str / dict): Software at the origin of the file. comment (str): Comment related to created revision. - person (str / id): Author of the file. + person (str / dict): Author of the file. revision (int): File revision. sep (str): OS separator. @@ -600,38 +646,38 @@ def new_working_file( def new_entity_output_file( - entity, - output_type, - task_type, - comment, - working_file=None, - person=None, - name="main", - mode="output", - revision=0, - nb_elements=1, - representation="", - sep="/", - file_status_id=None, - client=default, -): + entity: str | dict, + output_type: str | dict, + task_type: str | dict, + comment: str, + working_file: str | dict | None = None, + person: str | dict | None = None, + name: str = "main", + mode: str = "output", + revision: int = 0, + nb_elements: int = 1, + representation: str = "", + sep: str = "/", + file_status_id: str | None = None, + client: KitsuClient = default, +) -> dict: """ Create a new output file for given entity, task type and output type. It generates and store the expected path and sets a revision number (last revision + 1). Args: - entity (str / id): Entity for which an output file is needed. - output_type (str / id): Output type of the generated file. - task_type (str / id): Task type related to output file. + entity (str / dict): Entity for which an output file is needed. + output_type (str / dict): Output type of the generated file. + task_type (str / dict): Task type related to output file. comment (str): Comment related to created revision. - working_file (str / id): Working file which is the source of the + working_file (str / dict): Working file which is the source of the generated file. - person (str / id): Author of the file. + person (str / dict): Author of the file. name (str): Additional suffix for the working file name. mode (str): Allow to select a template inside the template. revision (int): File revision. - nb_elements (str): To represent an image sequence, the amount of file is + nb_elements (int): To represent an image sequence, the amount of file is needed. representation (str): Differientate file extensions. It can be useful to build folders based on extensions like abc, jpg, etc. @@ -639,7 +685,7 @@ def new_entity_output_file( file_status_id (id): The id of the file status to set at creation Returns: - Created output file. + dict: Created output file. """ entity = normalize_model_parameter(entity) output_type = normalize_model_parameter(output_type) @@ -671,42 +717,45 @@ def new_entity_output_file( def new_asset_instance_output_file( - asset_instance, - temporal_entity, - output_type, - task_type, - comment, - name="master", - mode="output", - working_file=None, - person=None, - revision=0, - nb_elements=1, - representation="", - sep="/", - file_status_id=None, - client=default, -): + asset_instance: str | dict, + temporal_entity: str | dict, + output_type: str | dict, + task_type: str | dict, + comment: str, + name: str = "master", + mode: str = "output", + working_file: str | dict | None = None, + person: str | dict | None = None, + revision: int = 0, + nb_elements: int = 1, + representation: str = "", + sep: str = "/", + file_status_id: str | dict | None = None, + client: KitsuClient = default, +) -> dict: """ Create a new output file for given asset instance, temporal entity, task type and output type. It generates and store the expected path and sets a revision number (last revision + 1). Args: - entity (str / id): Entity for which an output file is needed. - output_type (str / id): Output type of the generated file. - task_type (str / id): Task type related to output file. + asset_instance (str / dict): Asset instance for which an output file + is needed. + temporal_entity (str / dict): Temporal entity for which an output file + is needed. + output_type (str / dict): Output type of the generated file. + task_type (str / dict): Task type related to output file. comment (str): Comment related to created revision. - working_file (str / id): Working file which is the source of the - generated file. - person (str / id): Author of the file. + working_file (str / dict): Working file which is the source of the + generated file. + person (str / dict): Author of the file. name (str): Additional suffix for the working file name. mode (str): Allow to select a template inside the template. revision (int): File revision. - nb_elements (str): To represent an image sequence, the amount of file - needed. - representation (str): Differientate file extensions. It can be useful - to build folders based on extensions like abc, jpg, cetc. + nb_elements (int): To represent an image sequence, the amount of file + needed. + representation (str): Differentiate file extensions. It can be useful + to build folders based on extensions like abc, jpg, cetc. sep (str): OS separator. file_status_id (id): The id of the file status to set at creation @@ -747,19 +796,26 @@ def new_asset_instance_output_file( def get_next_entity_output_revision( - entity, output_type, task_type, name="main", client=default -): + entity: str | dict, + output_type: str | dict, + task_type: str | dict, + name: str = "main", + client: KitsuClient = default, +) -> int: """ Args: entity (str / dict): The entity dict or ID. output_type (str / dict): The entity dict or ID. task_type (str / dict): The entity dict or ID. + name (str): Get version for output file with the given name. Returns: - int: Next revision of ouput files available for given entity, output + int: Next revision of output files available for given entity, output type and task type. """ entity = normalize_model_parameter(entity) + output_type = normalize_model_parameter(output_type) + task_type = normalize_model_parameter(task_type) path = "data/entities/%s/output-files/next-revision" % entity["id"] data = { "name": name, @@ -771,13 +827,13 @@ def get_next_entity_output_revision( def get_next_asset_instance_output_revision( - asset_instance, - temporal_entity, - output_type, - task_type, - name="master", - client=default, -): + asset_instance: str | dict, + temporal_entity: str | dict, + output_type: str | dict, + task_type: str | dict, + name: str = "master", + client: KitsuClient = default, +) -> int: """ Args: asset_instance (str / dict): The asset instance dict or ID. @@ -806,14 +862,18 @@ def get_next_asset_instance_output_revision( def get_last_entity_output_revision( - entity, output_type, task_type, name="master", client=default -): + entity: str | dict, + output_type: str | dict, + task_type: str | dict, + name: str = "master", + client: KitsuClient = default, +) -> int: """ Args: - entity (str / dict, client=default): The entity dict or ID. - output_type (str / dict, client=default): The entity dict or ID. - task_type (str / dict, client=default): The entity dict or ID. - name (str, client=default): The output name + entity (str / dict): The entity dict or ID. + output_type (str / dict): The entity dict or ID. + task_type (str / dict): The entity dict or ID. + name (str): The output name Returns: int: Last revision of ouput files for given entity, output type and task @@ -831,13 +891,13 @@ def get_last_entity_output_revision( def get_last_asset_instance_output_revision( - asset_instance, - temporal_entity, - output_type, - task_type, - name="master", - client=default, -): + asset_instance: str | dict, + temporal_entity: str | dict, + output_type: str | dict, + task_type: str | dict, + name: str = "master", + client: KitsuClient = default, +) -> int: """ Generate last output revision for given asset instance. """ @@ -860,14 +920,14 @@ def get_last_asset_instance_output_revision( @cache def get_last_output_files_for_entity( - entity, - output_type=None, - task_type=None, - name=None, - representation=None, - file_status=None, - client=default, -): + entity: str | dict, + output_type: str | dict | None = None, + task_type: str | dict | None = None, + name: str | None = None, + representation: str | None = None, + file_status: str | dict | None = None, + client: KitsuClient = default, +) -> list[dict]: """ Args: entity (str / dict): The entity dict or ID. @@ -907,15 +967,15 @@ def get_last_output_files_for_entity( @cache def get_last_output_files_for_asset_instance( - asset_instance, - temporal_entity, - task_type=None, - output_type=None, - name=None, - representation=None, - file_status=None, - client=default, -): + asset_instance: str | dict, + temporal_entity: str | dict, + task_type: str | dict | None = None, + output_type: str | dict | None = None, + name: str | None = None, + representation: str | None = None, + file_status: str | dict | None = None, + client: KitsuClient = default, +) -> list[dict]: """ Args: asset_instance (str / dict): The asset instance dict or ID. @@ -959,7 +1019,9 @@ def get_last_output_files_for_asset_instance( @cache -def get_working_files_for_task(task, client=default): +def get_working_files_for_task( + task: str | dict, client: KitsuClient = default +) -> list[dict]: """ Args: task (str / dict): The task dict or the task ID. @@ -973,7 +1035,9 @@ def get_working_files_for_task(task, client=default): @cache -def get_last_working_files(task, client=default): +def get_last_working_files( + task: str | dict, client: KitsuClient = default +) -> dict: """ Args: task (str / dict): The task dict or the task ID. @@ -988,7 +1052,9 @@ def get_last_working_files(task, client=default): @cache -def get_last_working_file_revision(task, name="main", client=default): +def get_last_working_file_revision( + task: str | dict, name: str = "main", client: KitsuClient = default +) -> dict: """ Args: task (str / dict): The task dict or the task ID. @@ -996,7 +1062,7 @@ def get_last_working_file_revision(task, name="main", client=default): Returns: dict: Last revisions stored in the API for given task and given file - name suffx. + name suffix. """ task = normalize_model_parameter(task) path = "data/tasks/%s/working-files/last-revisions" % task["id"] @@ -1005,7 +1071,9 @@ def get_last_working_file_revision(task, name="main", client=default): @cache -def get_working_file(working_file_id, client=default): +def get_working_file( + working_file_id: str, client: KitsuClient = default +) -> dict: """ Args: working_file_id (str): ID of claimed working file. @@ -1016,7 +1084,9 @@ def get_working_file(working_file_id, client=default): return raw.fetch_one("working-files", working_file_id, client=client) -def update_comment(working_file, comment, client=default): +def update_comment( + working_file: str | dict, comment: str, client: KitsuClient = default +) -> dict: """ Update the file comment in database for given working file. @@ -1034,7 +1104,9 @@ def update_comment(working_file, comment, client=default): ) -def update_modification_date(working_file, client=default): +def update_modification_date( + working_file: str | dict, client: KitsuClient = default +) -> dict: """ Update modification date of given working file with current time (now). @@ -1051,12 +1123,15 @@ def update_modification_date(working_file, client=default): ) -def update_output_file(output_file, data, client=default): +def update_output_file( + output_file: str | dict, data: dict, client: KitsuClient = default +) -> dict: """ Update the data of given output file. Args: output_file (str / dict): The output file dict or ID. + data (dict): Data to update on the output file. Returns: dict: Modified output file @@ -1066,7 +1141,9 @@ def update_output_file(output_file, data, client=default): return raw.put(path, data, client=client) -def set_project_file_tree(project, file_tree_name, client=default): +def set_project_file_tree( + project: str | dict, file_tree_name: str, client: KitsuClient = default +) -> dict: """ (Deprecated) Set given file tree template on given project. This template will be used to generate file paths. The template is selected from sources. @@ -1085,7 +1162,9 @@ def set_project_file_tree(project, file_tree_name, client=default): return raw.post(path, data, client=client) -def update_project_file_tree(project, file_tree, client=default): +def update_project_file_tree( + project: str | dict, file_tree: dict, client: KitsuClient = default +) -> dict: """ Set given dict as file tree template on given project. This template will be used to generate file paths. @@ -1103,20 +1182,29 @@ def update_project_file_tree(project, file_tree, client=default): return raw.put(path, data, client=client) -def upload_working_file(working_file, file_path, client=default): +def upload_working_file( + working_file: str | dict, file_path: str, client: KitsuClient = default +) -> dict: """ Save given file in working file storage. Args: working_file (str / dict): The working file dict or ID. file_path (str): Location on hard drive where to save the file. + + Returns: + (dict): the working file model dictionary. """ working_file = normalize_model_parameter(working_file) url_path = "/data/working-files/%s/file" % working_file["id"] return raw.upload(url_path, file_path, client=client) -def download_working_file(working_file, file_path=None, client=default): +def download_working_file( + working_file: str | dict, + file_path: str | None = None, + client: KitsuClient = default, +) -> requests.Response: """ Download given working file and save it at given location. @@ -1137,7 +1225,9 @@ def download_working_file(working_file, file_path=None, client=default): ) -def download_preview_file(preview_file, file_path, client=default): +def download_preview_file( + preview_file: str | dict, file_path: str, client: KitsuClient = default +) -> requests.Response: """ Download given preview file and save it at given location. @@ -1152,7 +1242,9 @@ def download_preview_file(preview_file, file_path, client=default): ) -def get_preview_file_url(preview_file, client=default): +def get_preview_file_url( + preview_file: str | dict, client: KitsuClient = default +) -> str: """ Return given preview file URL @@ -1171,7 +1263,9 @@ def get_preview_file_url(preview_file, client=default): ) -def get_attachment_file(attachment_file_id, client=default): +def get_attachment_file( + attachment_file_id: str, client: KitsuClient = default +) -> dict: """ Return attachment file object corresponding to given ID. @@ -1181,7 +1275,9 @@ def get_attachment_file(attachment_file_id, client=default): return raw.fetch_one("attachment-files", attachment_file_id, client=client) -def download_attachment_file(attachment_file, file_path, client=default): +def download_attachment_file( + attachment_file: str | dict, file_path: str, client: KitsuClient = default +) -> requests.Response: """ Download given attachment file and save it at given location. @@ -1199,7 +1295,9 @@ def download_attachment_file(attachment_file, file_path, client=default): ) -def download_preview_file_thumbnail(preview_file, file_path, client=default): +def download_preview_file_thumbnail( + preview_file: str | dict, file_path: str, client: KitsuClient = default +) -> requests.Response: """ Download given preview file thumbnail and save it at given location. @@ -1216,7 +1314,9 @@ def download_preview_file_thumbnail(preview_file, file_path, client=default): ) -def download_preview_file_cover(preview_file, file_path, client=default): +def download_preview_file_cover( + preview_file: str | dict, file_path: str, client: KitsuClient = default +) -> requests.Response: """ Download given preview file cover and save it at given location. Args: @@ -1231,9 +1331,12 @@ def download_preview_file_cover(preview_file, file_path, client=default): ) -def download_person_avatar(person, file_path, client=default): +def download_person_avatar( + person: str | dict, file_path: str, client: KitsuClient = default +) -> requests.Response: """ Download given person's avatar and save it at given location. + Args: person (str / dict): The person dict or ID. file_path (str): Location on hard drive where to save the file. @@ -1246,13 +1349,19 @@ def download_person_avatar(person, file_path, client=default): ) -def upload_person_avatar(person, file_path, client=default): +def upload_person_avatar( + person: str | dict, file_path: str, client: KitsuClient = default +) -> dict[Literal["thumbnail_path"], str]: """ Upload given file as person avatar. Args: person (str / dict): The person dict or the person ID. file_path (str): Path of the file to upload as avatar. + + Returns: + dict: Dictionary with a key of 'thumbnail_path' and a value of the + path to the static image file, relative to the host url. """ path = ( "/pictures/thumbnails/persons/%s" @@ -1261,9 +1370,12 @@ def upload_person_avatar(person, file_path, client=default): return raw.upload(path, file_path, client=client) -def download_project_avatar(project, file_path, client=default): +def download_project_avatar( + project: str | dict, file_path: str, client: KitsuClient = default +) -> requests.Response: """ Download given project's avatar and save it at given location. + Args: project (str / dict): The project dict or ID. file_path (str): Location on hard drive where to save the file. @@ -1276,13 +1388,19 @@ def download_project_avatar(project, file_path, client=default): ) -def upload_project_avatar(project, file_path, client=default): +def upload_project_avatar( + project: str | dict, file_path: str, client: KitsuClient = default +) -> dict[Literal["thumbnail_path"], str]: """ Upload given file as project avatar. Args: project (str / dict): The project dict or ID. file_path (str): Path of the file to upload as avatar. + + Returns: + dict: Dictionary with a key of 'thumbnail_path' and a value of the + path to the static image file, relative to the host url. """ path = ( "/pictures/thumbnails/projects/%s" @@ -1291,9 +1409,12 @@ def upload_project_avatar(project, file_path, client=default): return raw.upload(path, file_path, client=client) -def download_organisation_avatar(organisation, file_path, client=default): +def download_organisation_avatar( + organisation: str | dict, file_path: str, client: KitsuClient = default +) -> requests.Response: """ Download given organisation's avatar and save it at given location. + Args: organisation (str / dict): The organisation dict or ID. file_path (str): Location on hard drive where to save the file. @@ -1306,13 +1427,19 @@ def download_organisation_avatar(organisation, file_path, client=default): ) -def upload_organisation_avatar(organisation, file_path, client=default): +def upload_organisation_avatar( + organisation: str | dict, file_path: str, client: KitsuClient = default +) -> dict[Literal["thumbnail_path"], str]: """ Upload given file as organisation avatar. Args: organisation (str / dict): The organisation dict or ID. file_path (str): Path of the file to upload as avatar. + + Returns: + dict: Dictionary with a key of 'thumbnail_path' and a value of the + path to the static image file, relative to the host url. """ path = ( "/pictures/thumbnails/organisations/%s" @@ -1321,12 +1448,15 @@ def upload_organisation_avatar(organisation, file_path, client=default): return raw.upload(path, file_path, client=client) -def update_preview(preview_file, data, client=default): +def update_preview( + preview_file: str | dict, data: dict, client: KitsuClient = default +) -> dict: """ Update the data of given preview file. Args: preview_file (str / dict): The preview file dict or ID. + data (dict): Data to update on the prevew file. Returns: dict: Modified preview file @@ -1336,9 +1466,17 @@ def update_preview(preview_file, data, client=default): return raw.put(path, data, client=client) -def new_file_status(name, color, client=default): +def new_file_status( + name: str, color: str, client: KitsuClient = default +) -> dict: """ Create a new file status if not existing yet. + + If the file status already exists, the existing record will be returned. + + Args: + name (str): the name of the status to create. + color (str): The color for the status as a Hex string, e.g "#00FF00". """ data = {"name": name, "color": color} status = get_file_status_by_name(name, client=client) @@ -1349,7 +1487,7 @@ def new_file_status(name, color, client=default): @cache -def get_file_status(status_id, client=default): +def get_file_status(status_id: str, client: KitsuClient = default) -> dict: """ Return file status object corresponding to given ID. @@ -1360,7 +1498,9 @@ def get_file_status(status_id, client=default): @cache -def get_file_status_by_name(name, client=default): +def get_file_status_by_name( + name: str, client: KitsuClient = default +) -> dict | None: """ Return file status object corresponding to given name diff --git a/gazu/playlist.py b/gazu/playlist.py index edd1e02..6d0f8f7 100644 --- a/gazu/playlist.py +++ b/gazu/playlist.py @@ -1,15 +1,22 @@ +from __future__ import annotations + +import requests + +from typing_extensions import Literal + from . import client as raw from .helpers import normalize_model_parameter from .sorting import sort_by_name from .cache import cache +from .client import KitsuClient default = raw.default_client @cache -def all_playlists(client=default): +def all_playlists(client: KitsuClient = default) -> list[dict]: """ Returns: list: All playlists for all projects. @@ -18,7 +25,9 @@ def all_playlists(client=default): @cache -def all_shots_for_playlist(playlist, client=default): +def all_shots_for_playlist( + playlist: str | dict, client: KitsuClient = default +) -> list[dict]: """ Args: playlist (str / dict): The playlist dict or the playlist ID. @@ -32,10 +41,13 @@ def all_shots_for_playlist(playlist, client=default): @cache -def all_playlists_for_project(project, client=default, page=1): +def all_playlists_for_project( + project: str | dict, client: KitsuClient = default, page: int = 1 +) -> list[dict]: """ Args: project (str / dict): The project dict or the project ID. + page (int): Page number for pagination Returns: list: All playlists for the given project @@ -51,16 +63,16 @@ def all_playlists_for_project(project, client=default, page=1): @cache -def all_playlists_for_episode(episode, client=default): +def all_playlists_for_episode( + episode: str | dict, client: KitsuClient = default +) -> list[dict]: """ - Args: episode (str / dict): The episode dict or the episode ID. Returns: list: All playlists for the given episode. """ - project = normalize_model_parameter(episode["project_id"]) return sort_by_name( raw.fetch_all( @@ -75,7 +87,7 @@ def all_playlists_for_episode(episode, client=default): @cache -def get_playlist(playlist, client=default): +def get_playlist(playlist: str | dict, client: KitsuClient = default) -> dict: """ Args: playlist (str / dict): The playlist dict or the playlist ID. @@ -83,13 +95,14 @@ def get_playlist(playlist, client=default): Returns: dict: playlist object for given id. """ - playlist = normalize_model_parameter(playlist) return raw.fetch_one("playlists", playlist["id"], client=client) @cache -def get_playlist_by_name(project, name, client=default): +def get_playlist_by_name( + project: str | dict, name: str, client: KitsuClient = default +) -> dict | None: """ Args: project (str / dict): The project dict or the project ID. @@ -104,19 +117,22 @@ def get_playlist_by_name(project, name, client=default): def new_playlist( - project, - name, - episode=None, - for_entity="shot", - for_client=False, - client=default, -): + project: str | dict, + name: str, + episode: str | dict | None = None, + for_entity: Literal["shot", "asset", "sequence"] = "shot", + for_client: bool = False, + client: KitsuClient = default, +) -> dict: """ Create a new playlist in the database for given project. Args: project (str / dict): The project dict or the project ID. name (str): Playlist name. + for_entity (str): The type of entity to include in the playlist, can + be one of "asset", "sequence" or "shot". + for_client (bool): Whether the playlist should be shared with clients. Returns: dict: Created playlist. @@ -137,7 +153,7 @@ def new_playlist( return playlist -def update_playlist(playlist, client=default): +def update_playlist(playlist: dict, client: KitsuClient = default) -> dict: """ Save given playlist data into the API. Metadata are fully replaced by the ones set on given playlist. @@ -153,7 +169,9 @@ def update_playlist(playlist, client=default): ) -def get_entity_preview_files(entity, client=default): +def get_entity_preview_files( + entity: str | dict, client: KitsuClient = default +) -> dict[str, list[dict]]: """ Get all preview files grouped by task type for a given entity. @@ -171,8 +189,12 @@ def get_entity_preview_files(entity, client=default): def add_entity_to_playlist( - playlist, entity, preview_file=None, persist=True, client=default -): + playlist: dict, + entity: str | dict, + preview_file: str | dict | None = None, + persist: bool = True, + client: KitsuClient = default, +) -> dict: """ Add an entity to the playlist, use the last uploaded preview as revision to review. @@ -209,14 +231,18 @@ def add_entity_to_playlist( def remove_entity_from_playlist( - playlist, entity, persist=True, client=default -): + playlist: dict, + entity: str | dict, + persist: bool = True, + client: KitsuClient = default, +) -> dict: """ Remove all occurences of a given entity from a playlist. Args: playlist (dict): Playlist object to modify entity (str / dict): the entity to remove or its ID + persist (bool): Set it to True to save the result to the API. Returns: dict: Updated playlist. @@ -233,14 +259,20 @@ def remove_entity_from_playlist( def update_entity_preview( - playlist, entity, preview_file, persist=True, client=default -): + playlist: dict, + entity: str | dict, + preview_file: str | dict, + persist: bool = True, + client: KitsuClient = default, +) -> dict: """ - Remove all occurences of a given entity from a playlist. + Update the preview file linked to a given entity in a playlist. Args: - playlist (dict): Playlist object to modify - entity (str / dict): the entity to add or its ID + playlist (dict): Playlist object to modify. + entity (str / dict): The entity to update the preview file for. + preview_file (str / dict): The new preview file to set for the entity. + persist (bool): Set it to True to save the result to the API. Returns: dict: Updated playlist. @@ -256,12 +288,14 @@ def update_entity_preview( @cache -def delete_playlist(playlist, client=default): +def delete_playlist( + playlist: str | dict, client: KitsuClient = default +) -> str: """ Delete a playlist. Args: - playlist (dict / ID): The playlist dict or id. + playlist (str / dict): The playlist dict or id. Returns: Response: Request response object. @@ -271,12 +305,14 @@ def delete_playlist(playlist, client=default): @cache -def get_entity_previews(playlist, client=default): +def get_entity_previews( + playlist: str | dict, client: KitsuClient = default +) -> list[dict]: """ Get entity previews for a playlist. Args: - playlist (dict / ID): The playlist dict or id. + playlist (str / dict): The playlist dict or id. Returns: list: Entity previews for the playlist. @@ -288,29 +324,32 @@ def get_entity_previews(playlist, client=default): @cache -def get_build_job(build_job, client=default): +def get_build_job( + build_job: str | dict, client: KitsuClient = default +) -> dict: """ Get a build job. Args: - build_job (dict / ID): The build job dict or id. + build_job (str / dict): The build job dict or id. Returns: dict: Build job information. """ build_job = normalize_model_parameter(build_job) - return raw.fetch_one("playlists/build-jobs", build_job["id"], client=client) + return raw.fetch_one( + "playlists/build-jobs", build_job["id"], client=client + ) -def remove_build_job(build_job, client=default): +def remove_build_job( + build_job: str | dict, client: KitsuClient = default +) -> str: """ Delete a build job. Args: - build_job (dict / ID): The build job dict or id. - - Returns: - Response: Request response object. + build_job (str / dict): The build job dict or id. """ build_job = normalize_model_parameter(build_job) return raw.delete( @@ -319,12 +358,14 @@ def remove_build_job(build_job, client=default): @cache -def all_build_jobs_for_project(project, client=default): +def all_build_jobs_for_project( + project: str | dict, client: KitsuClient = default +) -> list[dict]: """ Get all build jobs for a project. Args: - project (dict / ID): The project dict or id. + project (str / dict): The project dict or id. Returns: list: All build jobs for the project. @@ -335,12 +376,14 @@ def all_build_jobs_for_project(project, client=default): ) -def build_playlist_movie(playlist, client=default): +def build_playlist_movie( + playlist: str | dict, client: KitsuClient = default +) -> dict: """ Build a movie for a playlist. Args: - playlist (dict / ID): The playlist dict or id. + playlist (str / dict): The playlist dict or id. Returns: dict: Build job information. @@ -351,13 +394,18 @@ def build_playlist_movie(playlist, client=default): ) -def download_playlist_build(playlist, build_job, file_path, client=default): +def download_playlist_build( + playlist: str | dict, + build_job: str | dict, + file_path: str, + client: KitsuClient = default, +) -> requests.Response: """ Download a playlist build. Args: - playlist (dict / ID): The playlist dict or id. - build_job (dict / ID): The build job dict or id. + playlist (str / dict): The playlist dict or id. + build_job (str / dict): The build job dict or id. file_path (str): The location to store the file on the hard drive. Returns: @@ -372,12 +420,14 @@ def download_playlist_build(playlist, build_job, file_path, client=default): return raw.download(path, file_path, client=client) -def download_playlist_zip(playlist, file_path, client=default): +def download_playlist_zip( + playlist: str | dict, file_path: str, client: KitsuClient = default +) -> requests.Response: """ Download a playlist as a zip file. Args: - playlist (dict / ID): The playlist dict or id. + playlist (str / dict): The playlist dict or id. file_path (str): The location to store the file on the hard drive. Returns: @@ -388,12 +438,14 @@ def download_playlist_zip(playlist, file_path, client=default): return raw.download(path, file_path, client=client) -def generate_temp_playlist(project, data, client=default): +def generate_temp_playlist( + project: str | dict, data: dict, client: KitsuClient = default +) -> dict: """ Generate a temporary playlist. Args: - project (dict / ID): The project dict or id. + project (str / dict): The project dict or id. data (dict): Playlist generation data. Returns: @@ -405,12 +457,14 @@ def generate_temp_playlist(project, data, client=default): ) -def notify_clients_playlist_ready(playlist, client=default): +def notify_clients_playlist_ready( + playlist: str | dict, client: KitsuClient = default +) -> dict: """ Notify clients that a playlist is ready. Args: - playlist (dict / ID): The playlist dict or id. + playlist (str / dict): The playlist dict or id. Returns: dict: Notification response. diff --git a/gazu/project.py b/gazu/project.py index 71e17f8..c5d5444 100644 --- a/gazu/project.py +++ b/gazu/project.py @@ -1,7 +1,12 @@ +from __future__ import annotations + +from typing_extensions import Literal # Python 3.7 compatibility. + from . import client as raw from .sorting import sort_by_name from .cache import cache +from .client import KitsuClient from .helpers import ( normalize_model_parameter, normalize_list_of_models_for_links, @@ -11,7 +16,7 @@ @cache -def all_project_status(client=default): +def all_project_status(client: KitsuClient = default) -> list[dict]: """ Returns: list: Project status listed in database. @@ -20,7 +25,9 @@ def all_project_status(client=default): @cache -def get_project_status_by_name(project_status_name, client=default): +def get_project_status_by_name( + project_status_name: str, client: KitsuClient = default +) -> dict | None: """ Args: project_status_name (str): Name of claimed project status. @@ -34,7 +41,7 @@ def get_project_status_by_name(project_status_name, client=default): @cache -def all_projects(client=default): +def all_projects(client: KitsuClient = default) -> list[dict]: """ Returns: list: Projects stored in the database. @@ -43,7 +50,7 @@ def all_projects(client=default): @cache -def all_open_projects(client=default): +def all_open_projects(client: KitsuClient = default) -> list[dict]: """ Returns: Open projects stored in the database. @@ -52,7 +59,7 @@ def all_open_projects(client=default): @cache -def get_project(project_id, client=default): +def get_project(project_id: str, client: KitsuClient = default) -> dict: """ Args: project_id (str): ID of claimed project. @@ -64,7 +71,9 @@ def get_project(project_id, client=default): @cache -def get_project_url(project, section="assets", client=default): +def get_project_url( + project: str | dict, section: str = "assets", client: KitsuClient = default +) -> str: """ Args: project (str / dict): The project dict or the project ID. @@ -83,7 +92,9 @@ def get_project_url(project, section="assets", client=default): @cache -def get_project_by_name(project_name, client=default): +def get_project_by_name( + project_name: str, client: KitsuClient = default +) -> dict | None: """ Args: project_name (str): Name of claimed project. @@ -95,15 +106,15 @@ def get_project_by_name(project_name, client=default): def new_project( - name, - production_type="short", - team=[], - asset_types=[], - task_statuses=[], - task_types=[], - production_style="2d3d", - client=default, -): + name: str, + production_type: str = "short", + team: list = [], + asset_types: list = [], + task_statuses: list = [], + task_types: list = [], + production_style: str = "2d3d", + client: KitsuClient = default, +) -> dict: """ Creates a new project. @@ -139,7 +150,9 @@ def new_project( return project -def remove_project(project, force=False, client=default): +def remove_project( + project: str | dict, force: bool = False, client: KitsuClient = default +) -> str: """ Remove given project from database. (Prior to do that, make sure, there is no asset or shot left). @@ -154,7 +167,7 @@ def remove_project(project, force=False, client=default): return raw.delete(path, client=client) -def update_project(project, client=default): +def update_project(project: dict, client: KitsuClient = default) -> dict: """ Save given project data into the API. Metadata are fully replaced by the ones set on given project. @@ -182,7 +195,9 @@ def update_project(project, client=default): return raw.put("data/projects/%s" % project["id"], project, client=client) -def update_project_data(project, data={}, client=default): +def update_project_data( + project: str | dict, data: dict = {}, client: KitsuClient = default +) -> dict: """ Update the metadata for the provided project. Keys that are not provided are not changed. @@ -202,7 +217,7 @@ def update_project_data(project, data={}, client=default): return update_project(project, client=client) -def close_project(project, client=default): +def close_project(project: str | dict, client: KitsuClient = default) -> dict: """ Closes the provided project. @@ -223,7 +238,9 @@ def close_project(project, client=default): return project -def add_asset_type(project, asset_type, client=default): +def add_asset_type( + project: str | dict, asset_type: str | dict, client: KitsuClient = default +) -> dict: project = normalize_model_parameter(project) asset_type = normalize_model_parameter(asset_type) data = {"asset_type_id": asset_type["id"]} @@ -234,7 +251,12 @@ def add_asset_type(project, asset_type, client=default): ) -def add_task_type(project, task_type, priority, client=default): +def add_task_type( + project: str | dict, + task_type: str | dict, + priority: int, + client: KitsuClient = default, +) -> dict: project = normalize_model_parameter(project) task_type = normalize_model_parameter(task_type) data = {"task_type_id": task_type["id"], "priority": priority} @@ -245,7 +267,9 @@ def add_task_type(project, task_type, priority, client=default): ) -def add_task_status(project, task_status, client=default): +def add_task_status( + project: str | dict, task_status: str | dict, client: KitsuClient = default +) -> dict: project = normalize_model_parameter(project) task_status = normalize_model_parameter(task_status) data = {"task_status_id": task_status["id"]} @@ -257,15 +281,15 @@ def add_task_status(project, task_status, client=default): def add_metadata_descriptor( - project, - name, - entity_type, - data_type="string", - choices=[], - for_client=False, - departments=[], - client=default, -): + project: str | dict, + name: str, + entity_type: str, + data_type: str = "string", + choices: list[str] = [], + for_client: bool = False, + departments: list[str | dict] = [], + client: KitsuClient = default, +) -> dict: """ Create a new metadata descriptor for a project. @@ -296,7 +320,11 @@ def add_metadata_descriptor( ) -def get_metadata_descriptor(project, metadata_descriptor_id, client=default): +def get_metadata_descriptor( + project: str | dict, + metadata_descriptor_id: str, + client: KitsuClient = default, +) -> dict: """ Retrieve a the metadata descriptor matching given ID. @@ -316,13 +344,15 @@ def get_metadata_descriptor(project, metadata_descriptor_id, client=default): ) -def get_metadata_descriptor_by_field_name(project, field_name, client=default): +def get_metadata_descriptor_by_field_name( + project: str | dict, field_name: str, client: KitsuClient = default +) -> dict | None: """ - Get a metadata descriptor matchind given project and name. + Get a metadata descriptor matching the given project and name. Args: project (dict / ID): The project dict or id. - metadata_descriptor_id (dict / ID): The metadata descriptor dict or id. + field_name (str): The name of the metadata field. Returns: dict: The metadata descriptor matchind the ID. @@ -338,7 +368,9 @@ def get_metadata_descriptor_by_field_name(project, field_name, client=default): ) -def all_metadata_descriptors(project, client=default): +def all_metadata_descriptors( + project: str | dict, client: KitsuClient = default +) -> list[dict]: """ Get all the metadata descriptors. @@ -355,7 +387,11 @@ def all_metadata_descriptors(project, client=default): ) -def update_metadata_descriptor(project, metadata_descriptor, client=default): +def update_metadata_descriptor( + project: str | dict, + metadata_descriptor: dict, + client: KitsuClient = default, +) -> dict: """ Update a metadata descriptor. @@ -383,8 +419,11 @@ def update_metadata_descriptor(project, metadata_descriptor, client=default): def remove_metadata_descriptor( - project, metadata_descriptor_id, force=False, client=default -): + project: str | dict, + metadata_descriptor_id: str | dict, + force: bool = False, + client: KitsuClient = default, +) -> str: """ Remove a metadata descriptor. @@ -405,24 +444,32 @@ def remove_metadata_descriptor( ) -def get_team(project, client=default): +def get_team(project: str | dict, client: KitsuClient = default) -> list[dict]: """ Get team for project. Args: project (dict / ID): The project dict or id. + + Returns: + list[dict]: The list of user dicts that are part of the project team. """ project = normalize_model_parameter(project) return raw.fetch_all("projects/%s/team" % project["id"], client=client) -def add_person_to_team(project, person, client=default): +def add_person_to_team( + project: str | dict, person: str | dict, client: KitsuClient = default +) -> dict: """ Add a person to the team project. Args: project (dict / ID): The project dict or id. person (dict / ID): The person dict or id. + + Returns: + dict: The project dictionary. """ project = normalize_model_parameter(project) person = normalize_model_parameter(person) @@ -432,7 +479,9 @@ def add_person_to_team(project, person, client=default): ) -def remove_person_from_team(project, person, client=default): +def remove_person_from_team( + project: str | dict, person: str | dict, client: KitsuClient = default +) -> str: """ Remove a person from the team project. @@ -449,7 +498,9 @@ def remove_person_from_team(project, person, client=default): @cache -def get_project_task_types(project, client=default): +def get_project_task_types( + project: str | dict, client: KitsuClient = default +) -> list[dict]: """ Get task types configured for a project. @@ -466,7 +517,9 @@ def get_project_task_types(project, client=default): @cache -def get_project_task_statuses(project, client=default): +def get_project_task_statuses( + project: str | dict, client: KitsuClient = default +) -> list[dict]: """ Get task statuses configured for a project. @@ -483,7 +536,9 @@ def get_project_task_statuses(project, client=default): @cache -def all_status_automations(project, client=default): +def all_status_automations( + project: str | dict, client: KitsuClient = default +) -> list[dict]: """ Get status automations configured for a project. @@ -500,13 +555,21 @@ def all_status_automations(project, client=default): ) -def add_status_automation(project, automation, client=default): +def add_status_automation( + project: str | dict, + automation: dict[Literal["status_automation_id"], str], + client: KitsuClient = default, +) -> dict: """ Add a status automation to the project. Args: project (dict / ID): The project dict or id. - automation (dict): The automation payload (e.g. from/to status, task_type, rules). + automation (dict): A dictionary with a key of "status_automation_id" and + value of the automation ID. + + Returns: + dict: The project dictionary. """ project = normalize_model_parameter(project) return raw.post( @@ -516,7 +579,9 @@ def add_status_automation(project, automation, client=default): ) -def remove_status_automation(project, automation, client=default): +def remove_status_automation( + project: str | dict, automation: str | dict, client: KitsuClient = default +) -> str: """ Remove a status automation from the project. @@ -534,7 +599,9 @@ def remove_status_automation(project, automation, client=default): @cache -def get_preview_background_files(project, client=default): +def get_preview_background_files( + project: str | dict, client: KitsuClient = default +) -> list[dict]: """ Get preview background files configured for a project. @@ -543,11 +610,16 @@ def get_preview_background_files(project, client=default): """ project = normalize_model_parameter(project) return raw.fetch_all( - "projects/%s/settings/preview-background-files" % project["id"], client=client + "projects/%s/settings/preview-background-files" % project["id"], + client=client, ) -def add_preview_background_file(project, background_file, client=default): +def add_preview_background_file( + project: str | dict, + background_file: dict[Literal["preview_background_file_id"], str], + client: KitsuClient = default, +) -> dict: """ Add a preview background file to a project. @@ -558,7 +630,7 @@ def add_preview_background_file(project, background_file, client=default): project (dict / ID): The project dict or id. background_file (dict): A dict with a key of "preview_background_file_id" and value of the ID of the preview background to add. - + Returns: (dict): The project dictionary. """ @@ -570,7 +642,11 @@ def add_preview_background_file(project, background_file, client=default): ) -def remove_preview_background_file(project, background_file, client=default): +def remove_preview_background_file( + project: str | dict, + background_file: str | dict, + client: KitsuClient = default, +) -> str: """ Remove a preview background file from a project. @@ -588,7 +664,9 @@ def remove_preview_background_file(project, background_file, client=default): @cache -def get_milestones(project, client=default): +def get_milestones( + project: str | dict, client: KitsuClient = default +) -> list[dict]: """ Get production milestones for a project. @@ -602,7 +680,9 @@ def get_milestones(project, client=default): @cache -def get_project_quotas(project, client=default): +def get_project_quotas( + project: str | dict, client: KitsuClient = default +) -> list[dict]: """ Get quotas for a project. @@ -610,13 +690,13 @@ def get_project_quotas(project, client=default): project (dict / ID): The project dict or id. """ project = normalize_model_parameter(project) - return raw.fetch_all( - "projects/%s/quotas" % project["id"], client=client - ) + return raw.fetch_all("projects/%s/quotas" % project["id"], client=client) @cache -def get_project_person_quotas(project, person, client=default): +def get_project_person_quotas( + project: str | dict, person: str | dict, client: KitsuClient = default +) -> list[dict]: """ Get quotas for a person within a project. @@ -634,7 +714,9 @@ def get_project_person_quotas(project, person, client=default): @cache -def get_budgets(project, client=default): +def get_budgets( + project: str | dict, client: KitsuClient = default +) -> list[dict]: """ Get budgets for a project. @@ -646,15 +728,15 @@ def get_budgets(project, client=default): def create_budget( - project, - name, - description=None, - currency=None, - start_date=None, - end_date=None, - amount=None, - client=default, -): + project: str | dict, + name: str, + description: str | None = None, + currency: str | None = None, + start_date: str | None = None, + end_date: str | None = None, + amount: int | float | None = None, + client: KitsuClient = default, +) -> dict: """ Create a budget for a project. @@ -685,7 +767,9 @@ def create_budget( @cache -def get_budget(project, budget, client=default): +def get_budget( + project: str | dict, budget: str | dict, client: KitsuClient = default +) -> dict: """ Get a specific budget. @@ -700,7 +784,12 @@ def get_budget(project, budget, client=default): ) -def update_budget(project, budget, data, client=default): +def update_budget( + project: str | dict, + budget: str | dict, + data: dict, + client: KitsuClient = default, +) -> dict: """ Update a specific budget. @@ -718,7 +807,9 @@ def update_budget(project, budget, data, client=default): ) -def remove_budget(project, budget, client=default): +def remove_budget( + project: str | dict, budget: str | dict, client: KitsuClient = default +) -> str: """ Delete a specific budget. @@ -735,7 +826,9 @@ def remove_budget(project, budget, client=default): @cache -def get_budget_entries(project, budget, client=default): +def get_budget_entries( + project: str | dict, budget: str | dict, client: KitsuClient = default +) -> list[dict]: """ Get entries for a specific budget. @@ -752,17 +845,17 @@ def get_budget_entries(project, budget, client=default): def create_budget_entry( - project, - budget, - name, - date=None, - amount=None, - quantity=None, - unit_price=None, - description=None, - category=None, - client=default, -): + project: str | dict, + budget: str | dict, + name: str, + date: str | None = None, + amount: int | float | None = None, + quantity: int | float | None = None, + unit_price: int | float | None = None, + description: str | None = None, + category: str | None = None, + client: KitsuClient = default, +) -> dict: """ Create a budget entry for a specific budget. @@ -793,15 +886,19 @@ def create_budget_entry( if category is not None: data["category"] = category return raw.post( - "data/projects/%s/budgets/%s/entries" - % (project["id"], budget["id"]), + "data/projects/%s/budgets/%s/entries" % (project["id"], budget["id"]), data, client=client, ) @cache -def get_budget_entry(project, budget, entry, client=default): +def get_budget_entry( + project: str | dict, + budget: str | dict, + entry: str | dict, + client: KitsuClient = default, +) -> dict: """ Get a specific budget entry. @@ -820,7 +917,13 @@ def get_budget_entry(project, budget, entry, client=default): ) -def update_budget_entry(project, budget, entry, data, client=default): +def update_budget_entry( + project: str | dict, + budget: str | dict, + entry: str | dict, + data: dict, + client: KitsuClient = default, +) -> dict: """ Update a specific budget entry. @@ -841,7 +944,12 @@ def update_budget_entry(project, budget, entry, data, client=default): ) -def remove_budget_entry(project, budget, entry, client=default): +def remove_budget_entry( + project: str | dict, + budget: str | dict, + entry: str | dict, + client: KitsuClient = default, +) -> str: """ Delete a specific budget entry.