Skip to content

Commit da26449

Browse files
authored
Reformat (#638)
This really is just reformatting. The `TODO`s will be eliminated before the conversion is completed. They are just bookmarks for changes I can't make until Swagger is removed.
1 parent 8e32390 commit da26449

File tree

4 files changed

+136
-130
lines changed

4 files changed

+136
-130
lines changed

kaggle/api/kaggle_api_extended.py

Lines changed: 69 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,8 @@ def _load_previous_if_any(self):
210210

211211
def _is_previous_valid(self, previous):
212212
return previous.path == self.path and \
213-
previous.start_blob_upload_request == self.start_blob_upload_request and \
214-
previous.timestamp > time.time() - ResumableFileUpload.RESUMABLE_UPLOAD_EXPIRY_SECONDS
213+
previous.start_blob_upload_request == self.start_blob_upload_request and \
214+
previous.timestamp > time.time() - ResumableFileUpload.RESUMABLE_UPLOAD_EXPIRY_SECONDS
215215

216216
def upload_initiated(self, start_blob_upload_response):
217217
if self.context.no_resume:
@@ -382,11 +382,11 @@ class KaggleApi(KaggleApi):
382382

383383
def _is_retriable(self, e):
384384
return issubclass(type(e), ConnectionError) or \
385-
issubclass(type(e), urllib3_exceptions.ConnectionError) or \
386-
issubclass(type(e), urllib3_exceptions.ConnectTimeoutError) or \
387-
issubclass(type(e), urllib3_exceptions.ProtocolError) or \
388-
issubclass(type(e), requests.exceptions.ConnectionError) or \
389-
issubclass(type(e), requests.exceptions.ConnectTimeout)
385+
issubclass(type(e), urllib3_exceptions.ConnectionError) or \
386+
issubclass(type(e), urllib3_exceptions.ConnectTimeoutError) or \
387+
issubclass(type(e), urllib3_exceptions.ProtocolError) or \
388+
issubclass(type(e), requests.exceptions.ConnectionError) or \
389+
issubclass(type(e), requests.exceptions.ConnectTimeout)
390390

391391
def _calculate_backoff_delay(self, attempt, initial_delay_millis,
392392
retry_multiplier, randomness_factor):
@@ -437,7 +437,7 @@ def authenticate(self):
437437

438438
# Step 2: if credentials were not in env read in configuration file
439439
if self.CONFIG_NAME_USER not in config_data \
440-
or self.CONFIG_NAME_KEY not in config_data:
440+
or self.CONFIG_NAME_KEY not in config_data:
441441
if os.path.exists(self.config):
442442
config_data = self.read_config_file(config_data)
443443
elif self._is_help_or_version_command(api_command) or (len(
@@ -709,9 +709,9 @@ def print_config_values(self, prefix='- '):
709709

710710
def build_kaggle_client(self):
711711
env = KaggleEnv.STAGING if '--staging' in self.args \
712-
else KaggleEnv.ADMIN if '--admin' in self.args \
713-
else KaggleEnv.LOCAL if '--local' in self.args \
714-
else KaggleEnv.PROD
712+
else KaggleEnv.ADMIN if '--admin' in self.args \
713+
else KaggleEnv.LOCAL if '--local' in self.args \
714+
else KaggleEnv.PROD
715715
verbose = '--verbose' in self.args or '-v' in self.args
716716
config = self.api_client.configuration
717717
return KaggleClient(
@@ -935,9 +935,9 @@ def competition_submissions_cli(self,
935935
competition, page_token=page_token, page_size=page_size)
936936
if submissions:
937937
if csv_display:
938-
self.print_csv(submissions, submission_fields)
938+
self.print_csv(submissions, self.submission_fields)
939939
else:
940-
self.print_table(submissions, submission_fields)
940+
self.print_table(submissions, self.submission_fields)
941941
else:
942942
print('No submissions found')
943943

@@ -1397,7 +1397,7 @@ def dataset_list_files(self, dataset, page_token=None, page_size=20):
13971397
if dataset is None:
13981398
raise ValueError('A dataset must be specified')
13991399
owner_slug, dataset_slug, dataset_version_number = self.split_dataset_string(
1400-
dataset)
1400+
dataset)
14011401

14021402
with self.build_kaggle_client() as kaggle:
14031403
request = ApiListDatasetFilesRequest()
@@ -1501,15 +1501,15 @@ def dataset_download_file(self,
15011501
if '/' in dataset:
15021502
self.validate_dataset_string(dataset)
15031503
owner_slug, dataset_slug, dataset_version_number = self.split_dataset_string(
1504-
dataset)
1504+
dataset)
15051505
else:
15061506
owner_slug = self.get_config_value(self.CONFIG_NAME_USER)
15071507
dataset_slug = dataset
15081508
dataset_version_number = None
15091509

15101510
if path is None:
1511-
effective_path = self.get_default_download_dir(
1512-
'datasets', owner_slug, dataset_slug)
1511+
effective_path = self.get_default_download_dir('datasets', owner_slug,
1512+
dataset_slug)
15131513
else:
15141514
effective_path = path
15151515

@@ -1554,10 +1554,10 @@ def dataset_download_files(self,
15541554
if dataset is None:
15551555
raise ValueError('A dataset must be specified')
15561556
owner_slug, dataset_slug, dataset_version_number = self.split_dataset_string(
1557-
dataset)
1557+
dataset)
15581558
if path is None:
1559-
effective_path = self.get_default_download_dir(
1560-
'datasets', owner_slug, dataset_slug)
1559+
effective_path = self.get_default_download_dir('datasets', owner_slug,
1560+
dataset_slug)
15611561
else:
15621562
effective_path = path
15631563

@@ -1586,18 +1586,18 @@ def dataset_download_files(self,
15861586
z.extractall(effective_path)
15871587
except zipfile.BadZipFile as e:
15881588
raise ValueError(
1589-
f"The file {outfile} is corrupted or not a valid zip file. "
1590-
"Please report this issue at https://www.github.com/kaggle/kaggle-api"
1589+
f"The file {outfile} is corrupted or not a valid zip file. "
1590+
"Please report this issue at https://www.github.com/kaggle/kaggle-api"
15911591
)
15921592
except FileNotFoundError:
15931593
raise FileNotFoundError(
1594-
f"The file {outfile} was not found. "
1595-
"Please report this issue at https://www.github.com/kaggle/kaggle-api"
1594+
f"The file {outfile} was not found. "
1595+
"Please report this issue at https://www.github.com/kaggle/kaggle-api"
15961596
)
15971597
except Exception as e:
15981598
raise RuntimeError(
1599-
f"An unexpected error occurred: {e}. "
1600-
"Please report this issue at https://www.github.com/kaggle/kaggle-api"
1599+
f"An unexpected error occurred: {e}. "
1600+
"Please report this issue at https://www.github.com/kaggle/kaggle-api"
16011601
)
16021602

16031603
try:
@@ -1754,8 +1754,10 @@ def dataset_create_version(self,
17541754
id_no = self.get_or_default(meta_data, 'id_no', None)
17551755
if not ref and not id_no:
17561756
raise ValueError('ID or slug must be specified in the metadata')
1757-
elif ref and ref == self.config_values[self.CONFIG_NAME_USER] + '/INSERT_SLUG_HERE':
1758-
raise ValueError('Default slug detected, please change values before uploading')
1757+
elif ref and ref == self.config_values[
1758+
self.CONFIG_NAME_USER] + '/INSERT_SLUG_HERE':
1759+
raise ValueError(
1760+
'Default slug detected, please change values before uploading')
17591761

17601762
subtitle = meta_data.get('subtitle')
17611763
if subtitle and (len(subtitle) < 20 or len(subtitle) > 80):
@@ -1793,7 +1795,9 @@ def dataset_create_version(self,
17931795
with ResumableUploadContext() as upload_context:
17941796
self.upload_files(body, resources, folder, ApiBlobType.DATASET,
17951797
upload_context, quiet, dir_mode)
1796-
request.body.files = [self._api_dataset_new_file(file) for file in request.body.files]
1798+
request.body.files = [
1799+
self._api_dataset_new_file(file) for file in request.body.files
1800+
]
17971801
response = self.with_retry(message)(request)
17981802
return response
17991803

@@ -1808,8 +1812,10 @@ def dataset_create_version(self,
18081812
self.datasets_create_version_by_id_with_http_info)(
18091813
id_no, request)))
18101814
else:
1811-
if ref == self.config_values[self.CONFIG_NAME_USER] + '/INSERT_SLUG_HERE':
1812-
raise ValueError('Default slug detected, please change values before uploading')
1815+
if ref == self.config_values[
1816+
self.CONFIG_NAME_USER] + '/INSERT_SLUG_HERE':
1817+
raise ValueError(
1818+
'Default slug detected, please change values before uploading')
18131819
self.validate_dataset_string(ref)
18141820
ref_list = ref.split('/')
18151821
owner_slug = ref_list[0]
@@ -1924,22 +1930,18 @@ def dataset_create_new(self,
19241930
dataset_slug = ref_list[1]
19251931

19261932
# validations
1927-
if ref == self.config_values[
1928-
self.CONFIG_NAME_USER] + '/INSERT_SLUG_HERE':
1933+
if ref == self.config_values[self.CONFIG_NAME_USER] + '/INSERT_SLUG_HERE':
19291934
raise ValueError(
1930-
'Default slug detected, please change values before uploading')
1935+
'Default slug detected, please change values before uploading')
19311936
if title == 'INSERT_TITLE_HERE':
19321937
raise ValueError(
1933-
'Default title detected, please change values before uploading'
1934-
)
1938+
'Default title detected, please change values before uploading')
19351939
if len(licenses) != 1:
19361940
raise ValueError('Please specify exactly one license')
19371941
if len(dataset_slug) < 6 or len(dataset_slug) > 50:
1938-
raise ValueError(
1939-
'The dataset slug must be between 6 and 50 characters')
1942+
raise ValueError('The dataset slug must be between 6 and 50 characters')
19401943
if len(title) < 6 or len(title) > 50:
1941-
raise ValueError(
1942-
'The dataset title must be between 6 and 50 characters')
1944+
raise ValueError('The dataset title must be between 6 and 50 characters')
19431945
resources = meta_data.get('resources')
19441946
if resources:
19451947
self.validate_resources(folder, resources)
@@ -1950,19 +1952,19 @@ def dataset_create_new(self,
19501952

19511953
subtitle = meta_data.get('subtitle')
19521954
if subtitle and (len(subtitle) < 20 or len(subtitle) > 80):
1953-
raise ValueError(
1954-
'Subtitle length must be between 20 and 80 characters')
1955-
1956-
request = DatasetNewRequest(title=title,
1957-
slug=dataset_slug,
1958-
owner_slug=owner_slug,
1959-
license_name=license_name,
1960-
subtitle=subtitle,
1961-
description=description,
1962-
files=[],
1963-
is_private=not public,
1964-
convert_to_csv=convert_to_csv,
1965-
category_ids=keywords)
1955+
raise ValueError('Subtitle length must be between 20 and 80 characters')
1956+
1957+
request = DatasetNewRequest(
1958+
title=title,
1959+
slug=dataset_slug,
1960+
owner_slug=owner_slug,
1961+
license_name=license_name,
1962+
subtitle=subtitle,
1963+
description=description,
1964+
files=[],
1965+
is_private=not public,
1966+
convert_to_csv=convert_to_csv,
1967+
category_ids=keywords)
19661968

19671969
with ResumableUploadContext() as upload_context:
19681970
# TODO Change upload_files() to use ApiCreateDatasetRequest
@@ -1971,23 +1973,24 @@ def dataset_create_new(self,
19711973

19721974
with self.build_kaggle_client() as kaggle:
19731975
retry_request = ApiCreateDatasetRequest()
1974-
retry_request.title=title
1975-
retry_request.slug=dataset_slug
1976-
retry_request.owner_slug=owner_slug
1977-
retry_request.license_name=license_name
1978-
retry_request.subtitle=subtitle
1979-
retry_request.description=description
1980-
retry_request.files=[]
1981-
retry_request.is_private=not public
1982-
retry_request.category_ids=keywords
1976+
retry_request.title = title
1977+
retry_request.slug = dataset_slug
1978+
retry_request.owner_slug = owner_slug
1979+
retry_request.license_name = license_name
1980+
retry_request.subtitle = subtitle
1981+
retry_request.description = description
1982+
retry_request.files = []
1983+
retry_request.is_private = not public
1984+
retry_request.category_ids = keywords
19831985
response = self.with_retry(
1984-
kaggle.datasets.dataset_api_client.create_dataset)(retry_request)
1986+
kaggle.datasets.dataset_api_client.create_dataset)(
1987+
retry_request)
19851988
return response
19861989

19871990
result = DatasetNewResponse(
1988-
self.process_response(
1989-
self.with_retry(
1990-
self.datasets_create_new_with_http_info)(request)))
1991+
self.process_response(
1992+
self.with_retry(
1993+
self.datasets_create_new_with_http_info)(request)))
19911994

19921995
return result
19931996

kaggle/models/kaggle_models_extended.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
#!/usr/bin/python
2-
#
3-
# Copyright 2024 Kaggle Inc
4-
#
5-
# Licensed under the Apache License, Version 2.0 (the "License");
6-
# you may not use this file except in compliance with the License.
7-
# You may obtain a copy of the License at
8-
#
9-
# http://www.apache.org/licenses/LICENSE-2.0
10-
#
11-
# Unless required by applicable law or agreed to in writing, software
12-
# distributed under the License is distributed on an "AS IS" BASIS,
13-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14-
# See the License for the specific language governing permissions and
15-
# limitations under the License.
16-
1+
#!/usr/bin/python
2+
#
3+
# Copyright 2024 Kaggle Inc
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
1717
#!/usr/bin/python
1818
#
1919
# Copyright 2019 Kaggle Inc
@@ -131,7 +131,7 @@ def __repr__(self):
131131
class File(object):
132132

133133
def __init__(self, init_dict):
134-
try: # TODO Remove try-block
134+
try: # TODO Remove try-block
135135
parsed_dict = {k: parse(v) for k, v in init_dict.items()}
136136
self.__dict__.update(parsed_dict)
137137
self.size = File.get_size(self.totalBytes)
@@ -186,7 +186,7 @@ def __repr__(self):
186186
class ListFilesResult(object):
187187

188188
def __init__(self, init_dict):
189-
try: # TODO Remove try-block
189+
try: # TODO Remove try-block
190190
self.error_message = init_dict['errorMessage']
191191
files = init_dict['datasetFiles']
192192
token = init_dict['nextPageToken']

0 commit comments

Comments
 (0)