@@ -12,7 +12,7 @@ function usage {
12
12
echo " --editable (-e): Make the installed package always reference your latest"
13
13
echo " source code. Implies \" -i|--install\" . Be aware that changes to the \" src\" "
14
14
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"
16
16
echo " or https://www.kaggle.com."
17
17
echo " --watch (-w): Run the script in watch mode. It will watch the files under the \" template\" "
18
18
echo " directory and KaggleSwagger* files, and regenerate the package when there is a change."
@@ -63,8 +63,6 @@ SELF_DIR=$(dirname $(realpath $0))
63
63
SELF_DIR=${SELF_DIR%/* } # remove the last directory (tools) from the path
64
64
cd $SELF_DIR
65
65
66
- SWAGGER_YAML=$SELF_DIR /src/KaggleSwagger.yaml
67
- SWAGGER_CONFIG=$SELF_DIR /src/KaggleSwaggerConfig.json
68
66
KAGGLE_XDG_CONFIG_DIR=" ${XDG_CONFIG_HOME:- $HOME / .config} /kaggle"
69
67
mkdir -p " $KAGGLE_XDG_CONFIG_DIR "
70
68
KAGGLE_DEV_CONFIG_DIR=$( realpath " $KAGGLE_XDG_CONFIG_DIR /dev" )
@@ -109,31 +107,6 @@ function create-local-creds {
109
107
chmod 600 $kaggle_config_file
110
108
}
111
109
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
-
137
110
function copy-src {
138
111
cp ./src/setup.py .
139
112
cp ./src/setup.cfg .
@@ -151,16 +124,19 @@ function run-tests {
151
124
fi
152
125
153
126
if [[ " $TEST " == " $LOCAL_ENV " ]]; then
154
- source .. /use-localhost.sh
127
+ source tools /use-localhost.sh
155
128
elif [[ " $TEST " == " $PROD_ENV " ]]; then
156
- source .. /use-prod.sh
129
+ source tools /use-prod.sh
157
130
else
158
131
return 0 # Nothing to do
159
132
fi
160
133
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 ..
164
140
}
165
141
166
142
function install-package {
@@ -177,10 +153,8 @@ function cleanup {
177
153
rm -rf tox.ini \
178
154
test-requirements.txt \
179
155
test \
180
- .swagger-codegen \
181
156
.travis.yml \
182
157
git_push.sh \
183
- python_api_tests.py \
184
158
sample_submission.csv \
185
159
ds_salaries.csv \
186
160
test.csv \
@@ -194,7 +168,6 @@ function cleanup {
194
168
function run {
195
169
reset
196
170
197
- generate-package
198
171
copy-src
199
172
run-autogen
200
173
install-package
@@ -205,28 +178,11 @@ function run {
205
178
206
179
WATCHED_EVENTS=" -e create -e modify -e delete"
207
180
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
-
222
181
function watch-src {
223
182
local watched_paths=" $SELF_DIR /src"
224
183
225
184
echo " Watching for changes under \" src\" ..."
226
185
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).
230
186
echo " Copying changes..."
231
187
copy-src
232
188
echo " Done!"
@@ -244,9 +200,8 @@ function watch {
244
200
TEST=" no"
245
201
246
202
echo
247
- watch-swagger &
248
- local pid=$!
249
203
watch-src
204
+ local pid=$!
250
205
wait $pid
251
206
}
252
207
0 commit comments