-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy path__init__.py
More file actions
142 lines (121 loc) · 4.88 KB
/
__init__.py
File metadata and controls
142 lines (121 loc) · 4.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
"""Plugins queries."""
import json
from datetime import datetime
from typing import TYPE_CHECKING, Optional, cast
from typeguard import typechecked
from kili.adapters.kili_api_gateway.helpers.queries import QueryOptions
from kili.core.graphql.operations.plugin.queries import (
PluginBuildErrorsWhere,
PluginLogsWhere,
PluginQuery,
)
from kili.domain.types import ListOrTuple
from kili.entrypoints.base import BaseOperationEntrypointMixin
from kili.services.plugins import PluginUploader
from kili.utils.logcontext import for_all_methods, log_call
if TYPE_CHECKING:
from kili.client import Kili
@for_all_methods(log_call, exclude=["__init__"])
class QueriesPlugins(BaseOperationEntrypointMixin):
"""Set of Plugins queries."""
# pylint: disable=too-many-arguments
@typechecked
def get_plugin_build_errors(
self,
plugin_name: str,
start_date: Optional[datetime] = None,
limit: int = 100,
skip: int = 0,
) -> str:
# pylint: disable=line-too-long
"""Get paginated build errors of a plugin.
Args:
plugin_name: Name of the plugin
start_date: Datetime used to get the build errors from, if not provided, it will be the plugin's creation date
limit: Limit for pagination, if not provided, it will be 100
skip: Skip for pagination, if not provided, it will be 0
Returns:
A result array which contains the build errors of the plugin,
or an error message.
Examples:
>>> kili.get_plugin_build_errors(plugin_name="my_plugin_name", start_date="1970/01/01")
"""
where = PluginBuildErrorsWhere(plugin_name=plugin_name, start_date=start_date)
options = QueryOptions(
first=limit, skip=skip, disable_tqdm=False
) # disable tqm is not implemented for this query
pretty_result = PluginQuery(self.graphql_client, self.http_client).get_build_errors(
where, options
)
return json.dumps(pretty_result, sort_keys=True, indent=4)
@typechecked
def get_plugin_logs(
self,
project_id: str,
plugin_name: str,
start_date: Optional[datetime] = None,
limit: int = 100,
skip: int = 0,
) -> str:
"""Get paginated logs of a plugin on a project.
Args:
project_id: Identifier of the project
plugin_name: Name of the plugin
start_date: Datetime used to get the logs from, if not provided, it will be the plugin's creation date
limit: Limit for pagination, if not provided, it will be 100
skip: Skip for pagination, if not provided, it will be 0
Returns:
A result array which contains the logs of the plugin,
or an error message.
Examples:
>>> kili.get_plugin_logs(project_id="my_project_id", plugin_name="my_plugin_name", start_date="1970/01/01")
"""
where = PluginLogsWhere(
project_id=project_id, plugin_name=plugin_name, start_date=start_date
)
options = QueryOptions(
first=limit, skip=skip, disable_tqdm=False
) # disable tqm is not implemented for this query
pretty_result = PluginQuery(self.graphql_client, self.http_client).get_logs(where, options)
return json.dumps(pretty_result, sort_keys=True, indent=4)
@typechecked
def get_plugin_status(
self,
plugin_name: str,
verbose: bool = True,
) -> str:
"""Update a plugin with new code.
Args:
plugin_name: Name of the plugin
verbose: If false, minimal logs are displayed
Returns:
The status of the plugin if query was successful or an error message otherwise.
Examples:
>>> kili.get_plugin_status(plugin_name="my_plugin_name")
"""
return PluginUploader(
cast("Kili", self),
"",
plugin_name,
verbose,
self.http_client,
event_matcher=None,
).get_plugin_runner_status()
@typechecked
def list_plugins(
self,
fields: ListOrTuple[str] = ("name", "projectIds", "id", "createdAt", "updatedAt"),
) -> list[dict]:
# pylint: disable=line-too-long
"""List all plugins from your organization.
Args:
fields: All the fields to request among the possible fields for the plugins
See [the documentation](https://api-docs.kili-technology.com/types/objects/plugin) for all possible fields.
Returns:
A result array which contains all the plugins from your organization,
or an error message.
Examples:
>>> kili.list_plugins()
>>> kili.list_plugins(fields=['name'])
"""
return PluginQuery(self.graphql_client, self.http_client).list(fields=fields)