Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Changelog
====

#### 1.5.13
Release date: 2/27/22
* Add ability to add a model to a kernel

### 1.5.12
Release date: 03/12/21
* No changes
Expand Down
5 changes: 5 additions & 0 deletions KaggleSwagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1150,6 +1150,11 @@ definitions:
description: A list of kernel data sources that the kernel should use. Each dataset is specified as `USERNAME/KERNEL-SLUG`
items:
type: string
modelDataSources:
type: array
description: A list of model data sources that the kernel should use. Each model is specified as `USERNAME/MODEL-SLUG/FRAMEWORK/VARIATION-SLUG/VERSION-NUMBER`
items:
type: string
categoryIds:
type: array
description: A list of tag IDs to associated with the kernel
Expand Down
45 changes: 28 additions & 17 deletions kaggle/api/kaggle_api_extended.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
#!/usr/bin/python
#
# Copyright 2020 Kaggle Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

#!/usr/bin/python
#
# Copyright 2019 Kaggle Inc
Expand Down Expand Up @@ -82,7 +66,7 @@


class KaggleApi(KaggleApi):
__version__ = '1.5.12'
__version__ = '1.5.13'

CONFIG_NAME_PROXY = 'proxy'
CONFIG_NAME_COMPETITION = 'competition'
Expand Down Expand Up @@ -1763,6 +1747,7 @@ def kernels_initialize(self, folder):
'dataset_sources': [],
'competition_sources': [],
'kernel_sources': [],
'model_sources': [],
}
meta_file = os.path.join(folder, self.KERNEL_METADATA_FILE)
with open(meta_file, 'w') as f:
Expand Down Expand Up @@ -1856,6 +1841,10 @@ def kernels_push(self, folder):
for source in kernel_sources:
self.validate_kernel_string(source)

model_sources = self.get_or_default(meta_data, 'model_sources', [])
for source in model_sources:
self.validate_model_string(source)

docker_pinning_type = self.get_or_default(meta_data,
'docker_image_pinning_type',
None)
Expand Down Expand Up @@ -1891,6 +1880,7 @@ def kernels_push(self, folder):
competition_data_sources=self.get_or_default(
meta_data, 'competition_sources', []),
kernel_data_sources=kernel_sources,
model_data_sources=model_sources,
category_ids=self.get_or_default(meta_data, 'keywords', []),
docker_image_pinning_type=docker_pinning_type)

Expand Down Expand Up @@ -2068,6 +2058,8 @@ def kernels_pull(self, kernel, path, metadata=False, quiet=True):
'kernel_sources')
self.set_if_present(server_metadata, 'competitionDataSources',
data, 'competition_sources')
self.set_if_present(server_metadata, 'modelDataSources', data,
'model_sources')
with open(metadata_path, 'w') as f:
json.dump(data, f, indent=2)

Expand Down Expand Up @@ -2537,6 +2529,24 @@ def validate_kernel_string(self, kernel):
raise ValueError(
'Kernel slug must be at least five characters')

def validate_model_string(self, model):
""" determine if a model string is valid, meaning it is in the format
of {username}/{model-slug}.
Parameters
==========
model: the model name to validate
"""
if model:
if '/' not in model:
raise ValueError(
'Model must be specified in the form of '
'\'{username}/{model-slug}/{framework}/{variation-slug}/{version-number}\''
)

split = model.split('/')
if not split[0] or not split[1]:
raise ValueError('Invalid model specification ' + model)

def validate_resources(self, folder, resources):
""" validate resources is a wrapper to validate the existence of files
and that there are no duplicates for a folder and set of resources.
Expand Down Expand Up @@ -2609,6 +2619,7 @@ def convert_to_dataset_file_metadata(self, file_data, path):


class TqdmBufferedReader(io.BufferedReader):

def __init__(self, raw, progress_bar):
""" helper class to implement an io.BufferedReader
Parameters
Expand Down
31 changes: 15 additions & 16 deletions kaggle/models/kaggle_models_extended.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
#!/usr/bin/python
#
# Copyright 2020 Kaggle Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

#!/usr/bin/python
#
# Copyright 2019 Kaggle Inc
Expand All @@ -36,6 +20,7 @@


class Competition(object):

def __init__(self, init_dict):
parsed_dict = {k: parse(v) for k, v in init_dict.items()}
self.__dict__.update(parsed_dict)
Expand All @@ -46,6 +31,7 @@ def __repr__(self):


class SubmitResult(object):

def __init__(self, init_dict):
parsed_dict = {k: parse(v) for k, v in init_dict.items()}
self.__dict__.update(parsed_dict)
Expand All @@ -55,6 +41,7 @@ def __repr__(self):


class Submission(object):

def __init__(self, init_dict):
parsed_dict = {k: parse(v) for k, v in init_dict.items()}
self.__dict__.update(parsed_dict)
Expand All @@ -68,6 +55,7 @@ def __repr__(self):


class LeaderboardEntry(object):

def __init__(self, init_dict):
parsed_dict = {k: parse(v) for k, v in init_dict.items()}
self.__dict__.update(parsed_dict)
Expand All @@ -77,6 +65,7 @@ def __repr__(self):


class Dataset(object):

def __init__(self, init_dict):
parsed_dict = {k: parse(v) for k, v in init_dict.items()}
self.__dict__.update(parsed_dict)
Expand All @@ -90,6 +79,7 @@ def __repr__(self):


class Metadata(object):

def __init__(self, init_info):
parsed_info = {k: parse(v) for k, v in init_info.items()}
# backwards compatibility
Expand All @@ -102,6 +92,7 @@ def __repr__(self):


class DatasetVersion(object):

def __init__(self, init_dict):
parsed_dict = {k: parse(v) for k, v in init_dict.items()}
self.__dict__.update(parsed_dict)
Expand All @@ -111,6 +102,7 @@ def __repr__(self):


class File(object):

def __init__(self, init_dict):
parsed_dict = {k: parse(v) for k, v in init_dict.items()}
self.__dict__.update(parsed_dict)
Expand All @@ -130,6 +122,7 @@ def get_size(size, precision=0):


class Tag(object):

def __init__(self, init_dict):
parsed_dict = {k: parse(v) for k, v in init_dict.items()}
self.__dict__.update(parsed_dict)
Expand All @@ -139,6 +132,7 @@ def __repr__(self):


class FileUploadInfo(object):

def __init__(self, init_dict):
parsed_dict = {k: parse(v) for k, v in init_dict.items()}
self.__dict__.update(parsed_dict)
Expand All @@ -148,6 +142,7 @@ def __repr__(self):


class DatasetNewVersionResponse(object):

def __init__(self, init_dict):
parsed_dict = {k: parse(v) for k, v in init_dict.items()}
self.__dict__.update(parsed_dict)
Expand All @@ -157,6 +152,7 @@ def __repr__(self):


class DatasetNewResponse(object):

def __init__(self, init_dict):
parsed_dict = {k: parse(v) for k, v in init_dict.items()}
self.__dict__.update(parsed_dict)
Expand All @@ -166,6 +162,7 @@ def __repr__(self):


class ListFilesResult(object):

def __init__(self, init_dict):
self.error_message = init_dict['errorMessage']
files = init_dict['datasetFiles']
Expand All @@ -179,6 +176,7 @@ def __repr__(self):


class Kernel:

def __init__(self, init_dict):
parsed_dict = {k: parse(v) for k, v in init_dict.items()}
self.__dict__.update(parsed_dict)
Expand All @@ -188,6 +186,7 @@ def __repr__(self):


class KernelPushResponse(object):

def __init__(self, init_dict):
parsed_dict = {k: parse(v) for k, v in init_dict.items()}
self.__dict__.update(parsed_dict)
Expand Down
33 changes: 17 additions & 16 deletions kaggle/tests/test_authenticate.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
#!/usr/bin/python
#
# Copyright 2020 Kaggle Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

#!/usr/bin/python
#
# Copyright 2020 Kaggle Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from kaggle.api.kaggle_api_extended import KaggleApi

# python -m unittest tests.test_authenticate
Expand All @@ -23,6 +23,7 @@


class TestAuthenticate(unittest.TestCase):

def setUp(self):
print("setup class:%s" % self)

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

setup(
name='kaggle',
version='1.5.12',
version='1.5.13',
description='Kaggle API',
long_description=
('Official API for https://www.kaggle.com, accessible using a command line '
Expand Down