Skip to content

Commit 76f5b7e

Browse files
authored
Update to latest protos (#25)
1 parent c7a3fe7 commit 76f5b7e

8 files changed

Lines changed: 70 additions & 30 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
dist/
2+
.idea

kagglesdk/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "0.1.13"
1+
__version__ = "0.1.14"
22

33
from kagglesdk.kaggle_client import KaggleClient
44
from kagglesdk.kaggle_creds import KaggleCredentials

kagglesdk/community/types/content_enums.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,37 @@ class ContentState(enum.Enum):
1515
"""
1616
TEMPORARILY_QUARANTINED = 3
1717
r"""
18-
Quarantined by an admin or by the system. This means that the content is
19-
only visible to the user and admins, however users are able to toggle their
20-
content out of this state.
18+
DEPRECATED, use SYSTEM_DELETED: Quarantined by an admin or by the system.
19+
This means that the content is only visible to the user and admins, however
20+
users are able to toggle their content out of this state.
2121
"""
2222
PERMANENTLY_QUARANTINED = 4
2323
r"""
24-
Quarantined by an admin or by the system, the user cannot toggle their
25-
content's state back to public.
24+
DEPRECATED, use SYSTEM_DELETED: Quarantined by an admin or by the system,
25+
the user cannot toggle their content's state back to public.
2626
"""
2727
USER_DELETED = 5
28-
"""Deleted by the user."""
28+
r"""
29+
Deleted by the user. This data needs to be wiped out according to the
30+
table's data retention policy.
31+
"""
2932
SYSTEM_DELETED = 6
30-
"""Deleted by an admin or by a system account."""
33+
r"""
34+
Deleted by an admin or by a system account for moderation purposes. This
35+
data may need to be restored in the event of a successfull user appeal, and
36+
should not be wiped out.
37+
"""
3138
PENDING_PERMANENT_DELETE = 7
32-
"""Awaiting hard deletion."""
39+
"""Awaiting permanent deletion."""
40+
PERMANENTLY_DELETED = 10
41+
r"""
42+
All the data has been deleted, and thus satisfies wipeout. The data is in a
43+
state where it should not be restored. This state immediately follows
44+
PENDING_PERMANENT_DELETE, if the row is kept in the DB. This row could also
45+
be removed from the DB ('hard deleted'), as no data is associated with it.
46+
Whether a row is kept as PERMANENTLY_DELETED or removed from the DB is up
47+
to each team. For more details, see: http://shortn/_Z23aOje4MH
48+
"""
3349
DRAFT = 8
3450
r"""
3551
Initial state of entity that has never been previously published.

kagglesdk/kaggle_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ def __init__(self, http_client: KaggleHttpClient):
6969
self.account_client = AccountClient(http_client)
7070
self.group_api_client = GroupApiClient(http_client)
7171

72-
def __init__(self, env: KaggleEnv = None, verbose: bool = False, username: str = None, password: str = None, api_token: str = None, user_agent: str = None):
73-
self._http_client = http_client = KaggleHttpClient(env, verbose, username=username, password=password, api_token=api_token, user_agent=user_agent)
72+
def __init__(self, env: KaggleEnv = None, verbose: bool = False, username: str = None, password: str = None, api_token: str = None, user_agent: str = '', response_processor=None):
73+
self._http_client = http_client = KaggleHttpClient(env, verbose, username=username, password=password, api_token=api_token, user_agent=user_agent, response_processor=response_processor)
7474
self.admin = KaggleClient.Admin(http_client)
7575
self.benchmarks = KaggleClient.Benchmarks(http_client)
7676
self.blobs = KaggleClient.Blobs(http_client)

kagglesdk/kaggle_http_client.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
KaggleEnv,
1717
)
1818
from kagglesdk.kaggle_object import KaggleObject
19+
from kagglesdk.common.types.file_download import FileDownload
20+
from kagglesdk.common.types.http_redirect import HttpRedirect
1921
from typing import Type
2022

2123
# TODO (http://b/354237483) Generate the client from the existing one.
@@ -59,7 +61,8 @@ def __init__(
5961
username: str = None,
6062
password: str = None,
6163
api_token: str = None,
62-
user_agent: str = "kaggle-api/v1.7.0", # Was: V2
64+
user_agent: str = "kaggle-api/v1.7.0", # Was: V2
65+
response_processor=None,
6366
):
6467
self._env = env or get_env()
6568
self._signed_in = None
@@ -70,6 +73,7 @@ def __init__(
7073
self._password = password
7174
self._api_token = api_token
7275
self._user_agent = user_agent
76+
self._response_processor = response_processor
7377

7478
def call(
7579
self,
@@ -83,6 +87,12 @@ def call(
8387

8488
# Merge environment settings into session
8589
settings = self._session.merge_environment_settings(http_request.url, {}, None, None, None)
90+
91+
# Use stream=True for file downloads to avoid loading entire file into memory
92+
# See: https://github.com/Kaggle/kaggle-api/issues/754
93+
if response_type is not None and (response_type == FileDownload or response_type == HttpRedirect):
94+
settings["stream"] = True
95+
8696
http_response = self._session.send(http_request, **settings)
8797

8898
response = self._prepare_response(response_type, http_response)
@@ -112,6 +122,9 @@ def _prepare_response(self, response_type, http_response):
112122
except KeyError:
113123
pass
114124
http_response.raise_for_status()
125+
# Allow client to check header content.
126+
if self._response_processor:
127+
self._response_processor(http_response)
115128
if response_type is None: # Method doesn't have a return type
116129
return None
117130
return response_type.prepare_from(http_response)

kagglesdk/search/types/search_service.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ class WriteUpItemInfo(KaggleObject):
167167
Name of the team that owns the WriteUp
168168
id (int)
169169
Id of the WriteUp
170+
hackathon_track_ids (int)
171+
The track ids of the Hackathon
170172
"""
171173

172174
def __init__(self):
@@ -177,6 +179,7 @@ def __init__(self):
177179
self._content_state = ContentState.CONTENT_STATE_UNSPECIFIED
178180
self._team_name = None
179181
self._id = 0
182+
self._hackathon_track_ids = []
180183
self._freeze()
181184

182185
@property
@@ -279,6 +282,22 @@ def id(self, id: int):
279282
raise TypeError('id must be of type int')
280283
self._id = id
281284

285+
@property
286+
def hackathon_track_ids(self) -> Optional[List[int]]:
287+
"""The track ids of the Hackathon"""
288+
return self._hackathon_track_ids
289+
290+
@hackathon_track_ids.setter
291+
def hackathon_track_ids(self, hackathon_track_ids: Optional[List[int]]):
292+
if hackathon_track_ids is None:
293+
del self.hackathon_track_ids
294+
return
295+
if not isinstance(hackathon_track_ids, list):
296+
raise TypeError('hackathon_track_ids must be of type list')
297+
if not all([isinstance(t, int) for t in hackathon_track_ids]):
298+
raise TypeError('hackathon_track_ids must contain only items of type int')
299+
self._hackathon_track_ids = hackathon_track_ids
300+
282301

283302
WriteUpCompetitionInfo._fields = [
284303
FieldMetadata("competitionTitle", "competition_title", "_competition_title", str, "", PredefinedSerializer()),
@@ -299,5 +318,6 @@ def id(self, id: int):
299318
FieldMetadata("contentState", "content_state", "_content_state", ContentState, ContentState.CONTENT_STATE_UNSPECIFIED, EnumSerializer()),
300319
FieldMetadata("teamName", "team_name", "_team_name", str, None, PredefinedSerializer(), optional=True),
301320
FieldMetadata("id", "id", "_id", int, 0, PredefinedSerializer()),
321+
FieldMetadata("hackathonTrackIds", "hackathon_track_ids", "_hackathon_track_ids", int, [], ListSerializer(PredefinedSerializer())),
302322
]
303323

kagglesdk/security/types/security_types.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ class KaggleResourceType(enum.Enum):
8888
KAGGLE_RESOURCE_TYPE_MODEL_VERSIONS = 612
8989
KAGGLE_RESOURCE_TYPE_GATING_AGREEMENTS = 614
9090
KAGGLE_RESOURCE_TYPE_GATING_AGREEMENTS_USER_CONSENTS = 616
91+
KAGGLE_RESOURCE_TYPE_MODEL_PROXY = 620
9192
KAGGLE_RESOURCE_TYPE_BENCHMARKS = 700
9293
"""---------- Benchmarks ----------"""
9394
KAGGLE_RESOURCE_TYPE_BENCHMARK_VERSIONS = 704
@@ -96,6 +97,10 @@ class KaggleResourceType(enum.Enum):
9697
KAGGLE_RESOURCE_TYPE_BENCHMARK_TASKS = 710
9798
KAGGLE_RESOURCE_TYPE_BENCHMARK_TASK_VERSIONS = 712
9899
KAGGLE_RESOURCE_TYPE_BENCHMARK_TASK_RUNS = 714
100+
KAGGLE_RESOURCE_TYPE_COURSE_TRACKS = 800
101+
"""---------- Courses ----------"""
102+
KAGGLE_RESOURCE_TYPE_COURSE_LESSONS = 802
103+
KAGGLE_RESOURCE_TYPE_COURSE_TUTORIALS = 804
99104

100105
class KaggleResourceId(KaggleObject):
101106
r"""

kagglesdk/users/types/user_avatar.py

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
class UserAvatar(KaggleObject):
66
r"""
7+
A more lightweight version of the User object, with just what's required to
8+
render a user's avatar.
9+
710
Attributes:
811
display_name (str)
912
Display name for the given user
@@ -28,8 +31,6 @@ class UserAvatar(KaggleObject):
2831
TODO(http://b/402224065) remove once clients have migrated from this.
2932
progression_opt_out (bool)
3033
True if the user is opted out of the progression system.
31-
is_phone_verified (bool)
32-
True if the user is phone verified
3334
"""
3435

3536
def __init__(self):
@@ -43,7 +44,6 @@ def __init__(self):
4344
self._performance_tier = None
4445
self._user_id = None
4546
self._progression_opt_out = None
46-
self._is_phone_verified = None
4747
self._freeze()
4848

4949
@property
@@ -195,20 +195,6 @@ def progression_opt_out(self, progression_opt_out: Optional[bool]):
195195
raise TypeError('progression_opt_out must be of type bool')
196196
self._progression_opt_out = progression_opt_out
197197

198-
@property
199-
def is_phone_verified(self) -> bool:
200-
"""True if the user is phone verified"""
201-
return self._is_phone_verified or False
202-
203-
@is_phone_verified.setter
204-
def is_phone_verified(self, is_phone_verified: Optional[bool]):
205-
if is_phone_verified is None:
206-
del self.is_phone_verified
207-
return
208-
if not isinstance(is_phone_verified, bool):
209-
raise TypeError('is_phone_verified must be of type bool')
210-
self._is_phone_verified = is_phone_verified
211-
212198

213199
UserAvatar._fields = [
214200
FieldMetadata("displayName", "display_name", "_display_name", str, None, PredefinedSerializer(), optional=True),
@@ -221,6 +207,5 @@ def is_phone_verified(self, is_phone_verified: Optional[bool]):
221207
FieldMetadata("performanceTier", "performance_tier", "_performance_tier", UserAchievementTier, None, EnumSerializer(), optional=True),
222208
FieldMetadata("userId", "user_id", "_user_id", int, None, PredefinedSerializer(), optional=True),
223209
FieldMetadata("progressionOptOut", "progression_opt_out", "_progression_opt_out", bool, None, PredefinedSerializer(), optional=True),
224-
FieldMetadata("isPhoneVerified", "is_phone_verified", "_is_phone_verified", bool, None, PredefinedSerializer(), optional=True),
225210
]
226211

0 commit comments

Comments
 (0)