Skip to content

Commit 73ede3c

Browse files
authored
Update project management script (#663)
1 parent b3b46d6 commit 73ede3c

File tree

6 files changed

+32
-77
lines changed

6 files changed

+32
-77
lines changed

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ Obviously, this depends on Kaggle services. When you're extending the API and mo
2222
or adding to those services, you should be working in your Kaggle mid-tier development
2323
environment. You'll run Kaggle locally, in the container, and test the Python code by
2424
running it in the container so it can connect to your local testing environment.
25-
However, do not try to create a release from within the container. The code formatter
26-
(`yapf3`) changes much more than intended.
2725

2826
Also, run the following command to get `autogen.sh` installed:
2927
```bash

kaggle/api/kaggle_api_extended.py

Lines changed: 18 additions & 16 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 2024 Kaggle Inc
@@ -305,6 +305,8 @@ class KaggleApi:
305305
already_printed_version_warning = False
306306

307307
args = {} # DEBUG Add --local to use localhost
308+
if os.environ.get('KAGGLE_API_ENVIRONMENT') == 'LOCALHOST':
309+
args = {'--local'}
308310

309311
# Kernels valid types
310312
valid_push_kernel_types = ['script', 'notebook']

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ install-autogen = """curl -fsSL --output /tmp/autogen.zip "https://github.com/mb
6161
# TODO: install in Mac/Windows
6262
install-yapf = """pip3 install yapf==0.40.2 --break-system-packages || echo 'yapf could not be installed'"""
6363
install-toml = """sudo apt-get install -y python3-toml || echo 'toml could not be installed'"""
64-
install-java = """sudo apt-get install -y default-jre || echo 'java could not be installed'"""
65-
install-deps = "hatch run install-unzip && hatch run install-autogen && hatch run install-yapf && hatch run install-toml && hatch run install-java"
64+
install-deps = "hatch run install-unzip && hatch run install-autogen && hatch run install-yapf && hatch run install-toml"
6665

6766
integration-test = "pytest {args:integration_tests}"
6867

6968
compile = "./tools/GeneratePythonLibrary.sh"
7069
install = "./tools/GeneratePythonLibrary.sh --install"
7170
watch = "./tools/GeneratePythonLibrary.sh --watch"
71+
test = "./tools/GeneratePythonLibrary.sh --test local"

src/kaggle/api/kaggle_api_extended.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,8 @@ class KaggleApi:
289289
already_printed_version_warning = False
290290

291291
args = {} # DEBUG Add --local to use localhost
292+
if os.environ.get('KAGGLE_API_ENVIRONMENT') == 'LOCALHOST':
293+
args = {'--local'}
292294

293295
# Kernels valid types
294296
valid_push_kernel_types = ['script', 'notebook']

tests/unit_tests.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,6 @@ def test_kernels_c_push(self):
251251
self.fail(f"kernels_push failed: {e}")
252252

253253
def test_kernels_d_status(self):
254-
# AssertionError: kernels_status failed: 404 Client Error: Not Found for url: http://localhost/api/v1/kernels/status?username=stevemessick&kernelslug=testing
255254
if self.kernel_slug == '':
256255
self.test_kernels_c_push()
257256
try:
@@ -283,7 +282,6 @@ def test_kernels_e_list_files(self):
283282
self.fail(f"kernels_list_files failed: {e}")
284283

285284
def test_kernels_f_output(self):
286-
# AssertionError: kernels_output failed: 404 Client Error: Not Found for url: http://localhost/api/v1/kernels/output?username=stevemessick&kernelslug=testing
287285
fs = []
288286
if self.kernel_slug == '':
289287
self.test_kernels_c_push()

tools/GeneratePythonLibrary.sh

Lines changed: 10 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function usage {
1212
echo " --editable (-e): Make the installed package always reference your latest"
1313
echo " source code. Implies \"-i|--install\". Be aware that changes to the \"src\""
1414
echo " directory won't be reflected. See the README for details."
15-
echo " --test (-t) [$LOCAL_ENV|$PROD_ENV]: Run tests (python_api_tests.py) against http://localhost"
15+
echo " --test (-t) [$LOCAL_ENV|$PROD_ENV]: Run tests (unit_tests.py) against http://localhost"
1616
echo " or https://www.kaggle.com."
1717
echo " --watch (-w): Run the script in watch mode. It will watch the files under the \"template\""
1818
echo " directory and KaggleSwagger* files, and regenerate the package when there is a change."
@@ -63,8 +63,6 @@ SELF_DIR=$(dirname $(realpath $0))
6363
SELF_DIR=${SELF_DIR%/*} # remove the last directory (tools) from the path
6464
cd $SELF_DIR
6565

66-
SWAGGER_YAML=$SELF_DIR/src/KaggleSwagger.yaml
67-
SWAGGER_CONFIG=$SELF_DIR/src/KaggleSwaggerConfig.json
6866
KAGGLE_XDG_CONFIG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/kaggle"
6967
mkdir -p "$KAGGLE_XDG_CONFIG_DIR"
7068
KAGGLE_DEV_CONFIG_DIR=$(realpath "$KAGGLE_XDG_CONFIG_DIR/dev")
@@ -109,31 +107,6 @@ function create-local-creds {
109107
chmod 600 $kaggle_config_file
110108
}
111109

112-
function generate-package {
113-
# TODO Remove this.
114-
if [[ -f "kaggle/api/__init__.py" ]]; then
115-
sed -i -e 's/kaggle_api/kaggle_api_extended/g' kaggle/api/__init__.py
116-
fi
117-
118-
if [[ -f "kaggle/configuration.py" ]]; then
119-
# Replace the hard-coded endpoint URL with an environment variable in configuration.py
120-
# to allow talking to localhost, staging, prod etc.
121-
sed -i 's|self.host = "http|self.host = _get_endpoint_from_env() or "http|g' kaggle/configuration.py
122-
echo -e "\n" >> kaggle/configuration.py
123-
cat <<-END >> kaggle/configuration.py
124-
def _get_endpoint_from_env():
125-
import os
126-
endpoint = os.environ.get("KAGGLE_API_ENDPOINT")
127-
if endpoint is None:
128-
return None
129-
endpoint = endpoint.rstrip("/")
130-
if endpoint.endswith("/api/v1"):
131-
return endpoint
132-
return endpoint + "/api/v1"
133-
END
134-
fi
135-
}
136-
137110
function copy-src {
138111
cp ./src/setup.py .
139112
cp ./src/setup.cfg .
@@ -151,16 +124,19 @@ function run-tests {
151124
fi
152125

153126
if [[ "$TEST" == "$LOCAL_ENV" ]]; then
154-
source ../use-localhost.sh
127+
source tools/use-localhost.sh
155128
elif [[ "$TEST" == "$PROD_ENV" ]]; then
156-
source ../use-prod.sh
129+
source tools/use-prod.sh
157130
else
158131
return 0 # Nothing to do
159132
fi
160133

161-
cp ../python_api_tests.py ../sample_submission.csv ./
162-
python3 python_api_tests.py
163-
rm -f ./python_api_tests.py
134+
cd tests
135+
ln -s ../kagglesdk .
136+
ln -s ../kaggle .
137+
python3 unit_tests.py
138+
rm kaggle kagglesdk
139+
cd ..
164140
}
165141

166142
function install-package {
@@ -177,10 +153,8 @@ function cleanup {
177153
rm -rf tox.ini \
178154
test-requirements.txt \
179155
test \
180-
.swagger-codegen \
181156
.travis.yml \
182157
git_push.sh \
183-
python_api_tests.py \
184158
sample_submission.csv \
185159
ds_salaries.csv \
186160
test.csv \
@@ -194,7 +168,6 @@ function cleanup {
194168
function run {
195169
reset
196170

197-
generate-package
198171
copy-src
199172
run-autogen
200173
install-package
@@ -205,28 +178,11 @@ function run {
205178

206179
WATCHED_EVENTS="-e create -e modify -e delete"
207180

208-
function watch-swagger {
209-
local watched_paths="$SWAGGER_YAML $SWAGGER_CONFIG"
210-
211-
echo "Watching for changes to Swagger config..."
212-
while inotifywait -q -r $WATCHED_EVENTS --format "%e %w%f" $watched_paths; do
213-
echo "Deleting $SELF_DIR/kaggle/ $SELF_DIR/kaggle/"
214-
rm -rf $SELF_DIR/kaggle/*
215-
generate-package
216-
run-autogen
217-
copy-src
218-
echo -e "\nWatching for changes to Swagger config..."
219-
done
220-
}
221-
222181
function watch-src {
223182
local watched_paths="$SELF_DIR/src"
224183

225184
echo "Watching for changes under \"src\"..."
226185
while inotifywait -q -r $WATCHED_EVENTS --format "%e %w%f" $watched_paths; do
227-
# Do not delete the output directory when there is no Swagger change to avoid
228-
# having to run generate-package for each small code change as Swagger code
229-
# generation is a bit slow (can take 2-3 seconds).
230186
echo "Copying changes..."
231187
copy-src
232188
echo "Done!"
@@ -244,9 +200,8 @@ function watch {
244200
TEST="no"
245201

246202
echo
247-
watch-swagger &
248-
local pid=$!
249203
watch-src
204+
local pid=$!
250205
wait $pid
251206
}
252207

0 commit comments

Comments
 (0)