Skip to content

Commit 71585c9

Browse files
committed
Clean up indentation per #754
1 parent 5276775 commit 71585c9

File tree

2 files changed

+171
-168
lines changed

2 files changed

+171
-168
lines changed

kaggle/api/kaggle_api_extended.py

Lines changed: 83 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,12 +1083,12 @@ def competition_download_file(self,
10831083
request.file_name = file_name
10841084
response = kaggle.competitions.competition_api_client.download_data_file(
10851085
request)
1086-
url = response.history[0].url
1087-
outfile = os.path.join(effective_path, url.split('?')[0].split('/')[-1])
1088-
1089-
if force or self.download_needed(response, outfile, quiet):
1090-
self.download_file(response, outfile, kaggle.http_client(), quiet,
1091-
not force)
1086+
url = response.history[0].url
1087+
outfile = os.path.join(effective_path, url.split('?')[0].split('/')[-1])
1088+
1089+
if force or self.download_needed(response, outfile, quiet):
1090+
self.download_file(response, outfile, kaggle.http_client(), quiet,
1091+
not force)
10921092

10931093
def competition_download_files(self,
10941094
competition,
@@ -1115,12 +1115,12 @@ def competition_download_files(self,
11151115
request.competition_name = competition
11161116
response = kaggle.competitions.competition_api_client.download_data_files(
11171117
request)
1118-
url = response.url.split('?')[0]
1119-
outfile = os.path.join(effective_path,
1120-
competition + '.' + url.split('.')[-1])
1121-
1122-
if force or self.download_needed(response, outfile, quiet):
1123-
self.download_file(response, outfile, kaggle.http_client(), quiet, not force)
1118+
url = response.url.split('?')[0]
1119+
outfile = os.path.join(effective_path,
1120+
competition + '.' + url.split('.')[-1])
1121+
1122+
if force or self.download_needed(response, outfile, quiet):
1123+
self.download_file(response, outfile, kaggle.http_client(), quiet, not force)
11241124

11251125
def competition_download_cli(self,
11261126
competition,
@@ -1171,15 +1171,15 @@ def competition_leaderboard_download(self, competition, path, quiet=True):
11711171
request.competition_name = competition
11721172
response = kaggle.competitions.competition_api_client.download_leaderboard(
11731173
request)
1174-
if path is None:
1175-
effective_path = self.get_default_download_dir('competitions',
1176-
competition)
1177-
else:
1178-
effective_path = path
1179-
1180-
file_name = competition + '.zip'
1181-
outfile = os.path.join(effective_path, file_name)
1182-
self.download_file(response, outfile, kaggle.http_client(), quiet)
1174+
if path is None:
1175+
effective_path = self.get_default_download_dir('competitions',
1176+
competition)
1177+
else:
1178+
effective_path = path
1179+
1180+
file_name = competition + '.zip'
1181+
outfile = os.path.join(effective_path, file_name)
1182+
self.download_file(response, outfile, kaggle.http_client(), quiet)
11831183

11841184
def competition_leaderboard_view(self, competition):
11851185
"""View a leaderboard based on a competition name.
@@ -1615,14 +1615,14 @@ def dataset_download_file(self,
16151615
request.dataset_version_number = dataset_version_number
16161616
request.file_name = file_name
16171617
response = kaggle.datasets.dataset_api_client.download_dataset(request)
1618-
url = response.history[0].url
1619-
outfile = os.path.join(effective_path, url.split('?')[0].split('/')[-1])
1620-
1621-
if force or self.download_needed(response, outfile, quiet):
1622-
self.download_file(response, outfile, kaggle.http_client(), quiet, not force)
1623-
return True
1624-
else:
1625-
return False
1618+
url = response.history[0].url
1619+
outfile = os.path.join(effective_path, url.split('?')[0].split('/')[-1])
1620+
1621+
if force or self.download_needed(response, outfile, quiet):
1622+
self.download_file(response, outfile, kaggle.http_client(), quiet, not force)
1623+
return True
1624+
else:
1625+
return False
16261626

16271627
def dataset_download_files(self,
16281628
dataset,
@@ -1663,39 +1663,39 @@ def dataset_download_files(self,
16631663
request.dataset_version_number = dataset_version_number
16641664
response = kaggle.datasets.dataset_api_client.download_dataset(request)
16651665

1666-
outfile = os.path.join(effective_path, dataset_slug + '.zip')
1667-
if force or self.download_needed(response, outfile, quiet):
1668-
self.download_file(response, outfile, kaggle.http_client(), quiet, not force)
1669-
downloaded = True
1670-
else:
1671-
downloaded = False
1672-
1673-
if downloaded:
16741666
outfile = os.path.join(effective_path, dataset_slug + '.zip')
1675-
if unzip:
1676-
try:
1677-
with zipfile.ZipFile(outfile) as z:
1678-
z.extractall(effective_path)
1679-
except zipfile.BadZipFile as e:
1680-
raise ValueError(
1681-
f"The file {outfile} is corrupted or not a valid zip file. "
1682-
"Please report this issue at https://www.github.com/kaggle/kaggle-api"
1683-
)
1684-
except FileNotFoundError:
1685-
raise FileNotFoundError(
1686-
f"The file {outfile} was not found. "
1687-
"Please report this issue at https://www.github.com/kaggle/kaggle-api"
1688-
)
1689-
except Exception as e:
1690-
raise RuntimeError(
1691-
f"An unexpected error occurred: {e}. "
1692-
"Please report this issue at https://www.github.com/kaggle/kaggle-api"
1693-
)
1694-
1695-
try:
1696-
os.remove(outfile)
1697-
except OSError as e:
1698-
print('Could not delete zip file, got %s' % e)
1667+
if force or self.download_needed(response, outfile, quiet):
1668+
self.download_file(response, outfile, kaggle.http_client(), quiet, not force)
1669+
downloaded = True
1670+
else:
1671+
downloaded = False
1672+
1673+
if downloaded:
1674+
outfile = os.path.join(effective_path, dataset_slug + '.zip')
1675+
if unzip:
1676+
try:
1677+
with zipfile.ZipFile(outfile) as z:
1678+
z.extractall(effective_path)
1679+
except zipfile.BadZipFile as e:
1680+
raise ValueError(
1681+
f"The file {outfile} is corrupted or not a valid zip file. "
1682+
"Please report this issue at https://www.github.com/kaggle/kaggle-api"
1683+
)
1684+
except FileNotFoundError:
1685+
raise FileNotFoundError(
1686+
f"The file {outfile} was not found. "
1687+
"Please report this issue at https://www.github.com/kaggle/kaggle-api"
1688+
)
1689+
except Exception as e:
1690+
raise RuntimeError(
1691+
f"An unexpected error occurred: {e}. "
1692+
"Please report this issue at https://www.github.com/kaggle/kaggle-api"
1693+
)
1694+
1695+
try:
1696+
os.remove(outfile)
1697+
except OSError as e:
1698+
print('Could not delete zip file, got %s' % e)
16991699

17001700
def _print_dataset_url_and_license(self, owner_slug, dataset_slug,
17011701
dataset_version_number, licenses):
@@ -3780,28 +3780,28 @@ def model_instance_version_download(self,
37803780
response = kaggle.models.model_api_client.download_model_instance_version(
37813781
request)
37823782

3783-
outfile = os.path.join(effective_path, model_slug + '.tar.gz')
3784-
if force or self.download_needed(response, outfile, quiet):
3785-
self.download_file(response, outfile, kaggle.http_client(), quiet, not force)
3786-
downloaded = True
3787-
else:
3788-
downloaded = False
3789-
3790-
if downloaded:
3791-
if untar:
3792-
try:
3793-
with tarfile.open(outfile, mode='r:gz') as t:
3794-
t.extractall(effective_path)
3795-
except Exception as e:
3796-
raise ValueError(
3797-
'Error extracting the tar.gz file, please report on '
3798-
'www.github.com/kaggle/kaggle-api', e)
3799-
3800-
try:
3801-
os.remove(outfile)
3802-
except OSError as e:
3803-
print('Could not delete tar file, got %s' % e)
3804-
return outfile
3783+
outfile = os.path.join(effective_path, model_slug + '.tar.gz')
3784+
if force or self.download_needed(response, outfile, quiet):
3785+
self.download_file(response, outfile, kaggle.http_client(), quiet, not force)
3786+
downloaded = True
3787+
else:
3788+
downloaded = False
3789+
3790+
if downloaded:
3791+
if untar:
3792+
try:
3793+
with tarfile.open(outfile, mode='r:gz') as t:
3794+
t.extractall(effective_path)
3795+
except Exception as e:
3796+
raise ValueError(
3797+
'Error extracting the tar.gz file, please report on '
3798+
'www.github.com/kaggle/kaggle-api', e)
3799+
3800+
try:
3801+
os.remove(outfile)
3802+
except OSError as e:
3803+
print('Could not delete tar file, got %s' % e)
3804+
return outfile
38053805

38063806
def model_instance_version_download_cli(self,
38073807
model_instance_version,

0 commit comments

Comments
 (0)