Skip to content

Commit 0985010

Browse files
Merge branch 'release/25.2' into merge/lts-to-main
2 parents 9d1fdc2 + 9bdd404 commit 0985010

File tree

4 files changed

+114
-1
lines changed

4 files changed

+114
-1
lines changed

src/kili/domain_api/assets.py

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ def _prepare_video_processing_parameters(
239239
return transformed
240240

241241

242-
class AssetsNamespace(DomainNamespace):
242+
class AssetsNamespace(DomainNamespace): # pylint: disable=too-many-public-methods
243243
"""Assets domain namespace providing asset-related operations.
244244
245245
This namespace provides access to all asset-related functionality
@@ -264,6 +264,8 @@ class AssetsNamespace(DomainNamespace):
264264
- move_to_next_step(): Move assets to the next workflow step
265265
- assign(): Assign assets to labelers
266266
- update_priority(): Update asset priorities
267+
- skip(): Skip an asset
268+
- unskip(): Unskip an asset
267269
268270
Examples:
269271
>>> kili = Kili()
@@ -1808,6 +1810,64 @@ def set_metadata(
18081810
external_ids=external_ids,
18091811
)
18101812

1813+
@typechecked
1814+
def skip(
1815+
self,
1816+
*,
1817+
asset_id: str,
1818+
project_id: str,
1819+
reason: str,
1820+
) -> str:
1821+
"""Skip an asset.
1822+
1823+
Args:
1824+
asset_id: ID of the asset you want to skip.
1825+
project_id: The project ID.
1826+
reason: The reason why you skip an asset.
1827+
1828+
Returns:
1829+
The asset ID of the asset skipped. An error message if mutation failed.
1830+
1831+
Examples:
1832+
>>> kili.assets.skip(
1833+
project_id="ckg22d81r0jrg0885unmuswj8",
1834+
asset_id="ckg22d81s0jrh0885pdxfd03n",
1835+
reason="Test"
1836+
)
1837+
"""
1838+
return self._client.skip_or_unskip(
1839+
action="skip",
1840+
asset_id=asset_id,
1841+
project_id=project_id,
1842+
reason=reason,
1843+
)
1844+
1845+
@typechecked
1846+
def unskip(
1847+
self,
1848+
*,
1849+
asset_id: str,
1850+
project_id: str,
1851+
) -> str:
1852+
"""Unskip an asset.
1853+
1854+
Args:
1855+
asset_id: ID of the asset you want to unskip.
1856+
project_id: The project ID.
1857+
1858+
Returns:
1859+
The asset ID of the asset unskipped. An error message if mutation failed.
1860+
1861+
Examples:
1862+
>>> kili.assets.unskip(
1863+
asset_id="ckg22d81s0jrh0885pdxfd03n"
1864+
project_id="ckg22d81r0jrg0885unmuswj8"
1865+
)
1866+
"""
1867+
return self._client.skip_or_unskip(
1868+
action="unskip", asset_id=asset_id, project_id=project_id
1869+
)
1870+
18111871
@overload
18121872
def invalidate(
18131873
self,

src/kili/entrypoints/mutations/asset/__init__.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
GQL_ASSIGN_ASSETS,
2222
GQL_DELETE_MANY_FROM_DATASET,
2323
GQL_SEND_BACK_ASSETS_TO_QUEUE,
24+
GQL_SKIP_ASSET,
25+
GQL_UNSKIP_ASSET,
2426
GQL_UPDATE_PROPERTIES_IN_ASSETS,
2527
)
2628
from kili.entrypoints.mutations.exceptions import MutationError
@@ -860,3 +862,39 @@ def verify_last_batch(last_batch: dict, results: list) -> None:
860862
)
861863
result["asset_ids"] = [asset["id"] for asset in assets_in_queue]
862864
return result
865+
866+
def skip_or_unskip(
867+
self,
868+
action: Literal["skip", "unskip"],
869+
asset_id: str,
870+
project_id: str,
871+
reason: Optional[str] = None,
872+
) -> str:
873+
"""Skip or unskip an asset.
874+
875+
Args:
876+
action: The action you want to do. Either skip or unskip.
877+
asset_id: ID of the asset you want to skip or unskip.
878+
project_id: The project ID.
879+
reason: The reason why you skip an asset. Only required if the action is `skip`.
880+
881+
Returns:
882+
The asset ID of the asset modified. An error message if mutation failed.
883+
884+
Examples:
885+
>>> kili.skip_or_unskip(
886+
action="skip",
887+
asset_id="ckg22d81s0jrh0885pdxfd03n",
888+
project_id="ckg22d81r0jrg0885unmuswj8",
889+
reason="Test"
890+
)
891+
"""
892+
if action == "skip":
893+
if reason is None:
894+
raise MissingArgumentError("You must provide a reason to skip an asset")
895+
payload = {"reason": reason, "where": {"id": asset_id, "project": {"id": project_id}}}
896+
self.graphql_client.execute(GQL_SKIP_ASSET, payload)
897+
else:
898+
payload = {"projectId": project_id, "assetId": asset_id}
899+
self.graphql_client.execute(GQL_UNSKIP_ASSET, payload)
900+
return asset_id

src/kili/entrypoints/mutations/asset/queries.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,17 @@
5353
}}
5454
}}
5555
"""
56+
57+
GQL_SKIP_ASSET = """
58+
mutation SkipAsset($reason: String!, $where: AssetWhere!) {
59+
skipAsset(reason: $reason, where: $where) {
60+
id
61+
}
62+
}
63+
"""
64+
65+
GQL_UNSKIP_ASSET = """
66+
mutation UnskipAsset($projectId: ID!, $assetId: ID!) {
67+
unskipAsset(projectId: $projectId, assetId: $assetId)
68+
}
69+
"""

tests/unit/domain_api/test_assets.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def mock_client(self):
2828
client.change_asset_external_ids = MagicMock()
2929
client.add_metadata = MagicMock()
3030
client.set_metadata = MagicMock()
31+
client.skip_or_unskip = MagicMock()
3132
return client
3233

3334
@pytest.fixture()

0 commit comments

Comments
 (0)