kaggle-notebook-deploy 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- kaggle_notebook_deploy-0.1.0/.github/workflows/publish.yml +27 -0
- kaggle_notebook_deploy-0.1.0/.github/workflows/test.yml +27 -0
- kaggle_notebook_deploy-0.1.0/.gitignore +22 -0
- kaggle_notebook_deploy-0.1.0/GUIDE.md +311 -0
- kaggle_notebook_deploy-0.1.0/LICENSE +21 -0
- kaggle_notebook_deploy-0.1.0/PKG-INFO +159 -0
- kaggle_notebook_deploy-0.1.0/README.md +130 -0
- kaggle_notebook_deploy-0.1.0/pyproject.toml +48 -0
- kaggle_notebook_deploy-0.1.0/src/kaggle_notebook_deploy/__init__.py +3 -0
- kaggle_notebook_deploy-0.1.0/src/kaggle_notebook_deploy/cli.py +26 -0
- kaggle_notebook_deploy-0.1.0/src/kaggle_notebook_deploy/commands/__init__.py +0 -0
- kaggle_notebook_deploy-0.1.0/src/kaggle_notebook_deploy/commands/init.py +149 -0
- kaggle_notebook_deploy-0.1.0/src/kaggle_notebook_deploy/commands/init_repo.py +171 -0
- kaggle_notebook_deploy-0.1.0/src/kaggle_notebook_deploy/commands/push.py +85 -0
- kaggle_notebook_deploy-0.1.0/src/kaggle_notebook_deploy/commands/validate.py +131 -0
- kaggle_notebook_deploy-0.1.0/tests/__init__.py +0 -0
- kaggle_notebook_deploy-0.1.0/tests/test_cli.py +241 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [published]
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
publish:
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
permissions:
|
|
11
|
+
id-token: write
|
|
12
|
+
|
|
13
|
+
steps:
|
|
14
|
+
- uses: actions/checkout@v4
|
|
15
|
+
|
|
16
|
+
- uses: actions/setup-python@v5
|
|
17
|
+
with:
|
|
18
|
+
python-version: "3.12"
|
|
19
|
+
|
|
20
|
+
- name: Install build tools
|
|
21
|
+
run: pip install build
|
|
22
|
+
|
|
23
|
+
- name: Build package
|
|
24
|
+
run: python -m build
|
|
25
|
+
|
|
26
|
+
- name: Publish to PyPI
|
|
27
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
name: Test
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
test:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
strategy:
|
|
13
|
+
matrix:
|
|
14
|
+
python-version: ["3.9", "3.10", "3.11", "3.12"]
|
|
15
|
+
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v4
|
|
18
|
+
|
|
19
|
+
- uses: actions/setup-python@v5
|
|
20
|
+
with:
|
|
21
|
+
python-version: ${{ matrix.python-version }}
|
|
22
|
+
|
|
23
|
+
- name: Install dependencies
|
|
24
|
+
run: pip install -e ".[dev]"
|
|
25
|
+
|
|
26
|
+
- name: Run tests
|
|
27
|
+
run: pytest tests/ -v
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
# kaggle-notebook-deploy: git pushするだけでKaggle Notebookをデプロイ
|
|
2
|
+
|
|
3
|
+
## はじめに
|
|
4
|
+
|
|
5
|
+
KaggleのNotebookをブラウザ上のエディタで直接編集していませんか?
|
|
6
|
+
|
|
7
|
+
ブラウザエディタでは、Gitによるバージョン管理ができない、差分の確認がしづらい、使い慣れたエディタ(VSCode等)が使えない、といった不便があります。
|
|
8
|
+
|
|
9
|
+
**kaggle-notebook-deploy** は、このワークフローをコマンド一発でセットアップするCLIツールです。
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
pip install kaggle-notebook-deploy
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
GitHub Actionsを使い、**`git push`するだけでKaggleにNotebookを自動デプロイ**できます。
|
|
16
|
+
|
|
17
|
+
## 完成するワークフロー
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
ノートブック編集 → git push → GitHub Actions → Kaggleにアップロード → ブラウザでSubmit
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
1. ローカルまたは任意のデバイスで `.ipynb` を編集
|
|
24
|
+
2. `git add && git commit && git push`
|
|
25
|
+
3. `gh workflow run kaggle-push.yml -f notebook_dir=<コンペ名>`
|
|
26
|
+
4. GitHub ActionsがKaggle APIでノートブックをアップロード
|
|
27
|
+
5. ブラウザでKaggleのNotebook画面を開き「Submit to Competition」をクリック
|
|
28
|
+
|
|
29
|
+
## セットアップ(5分で完了)
|
|
30
|
+
|
|
31
|
+
### Step 1: kaggle-notebook-deploy をインストール
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
pip install kaggle-notebook-deploy
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Step 2: Kaggle APIの認証情報を準備
|
|
38
|
+
|
|
39
|
+
[Kaggle Account Settings](https://www.kaggle.com/settings) から API Token を取得し、`~/.kaggle/kaggle.json` に配置します。
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
# すでに kaggle CLI を使っている場合はスキップ
|
|
43
|
+
mkdir -p ~/.kaggle
|
|
44
|
+
echo '{"username":"your-username","key":"your-api-key"}' > ~/.kaggle/kaggle.json
|
|
45
|
+
chmod 600 ~/.kaggle/kaggle.json
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Step 3: リポジトリの初期化
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
# 新しいリポジトリを作成(既存リポでもOK)
|
|
52
|
+
mkdir my-kaggle && cd my-kaggle && git init
|
|
53
|
+
|
|
54
|
+
# GitHub Actions ワークフローをセットアップ
|
|
55
|
+
kaggle-notebook-deploy init-repo
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
以下のファイルが自動生成されます:
|
|
59
|
+
|
|
60
|
+
```
|
|
61
|
+
my-kaggle/
|
|
62
|
+
├── .github/workflows/
|
|
63
|
+
│ └── kaggle-push.yml # Kaggleプッシュ用ワークフロー
|
|
64
|
+
├── scripts/
|
|
65
|
+
│ └── setup-credentials.sh # CI/新デバイス用の認証セットアップ
|
|
66
|
+
└── .gitignore # データファイル等を除外
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Step 4: GitHub Secretsの設定
|
|
70
|
+
|
|
71
|
+
GitHubにpushした後、リポジトリのSecretsにKaggle認証情報を登録します。
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
# GitHub CLI を使う場合
|
|
75
|
+
gh secret set KAGGLE_USERNAME
|
|
76
|
+
gh secret set KAGGLE_KEY
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
またはGitHubのWeb UI: **Settings > Secrets and variables > Actions** から設定。
|
|
80
|
+
|
|
81
|
+
## 使い方
|
|
82
|
+
|
|
83
|
+
### コンペに参加する
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
# コンペ用ディレクトリを作成(slugはKaggle URLの末尾部分)
|
|
87
|
+
kaggle-notebook-deploy init titanic
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
```
|
|
91
|
+
titanic/
|
|
92
|
+
├── kernel-metadata.json # Kaggleに必要なメタデータ
|
|
93
|
+
└── titanic-baseline.ipynb # ベースラインNotebook
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
`kernel-metadata.json` は以下の内容で自動生成されます:
|
|
97
|
+
|
|
98
|
+
```json
|
|
99
|
+
{
|
|
100
|
+
"id": "your-username/titanic-baseline",
|
|
101
|
+
"title": "Titanic Baseline",
|
|
102
|
+
"code_file": "titanic-baseline.ipynb",
|
|
103
|
+
"language": "python",
|
|
104
|
+
"kernel_type": "notebook",
|
|
105
|
+
"is_private": "true",
|
|
106
|
+
"enable_gpu": "false",
|
|
107
|
+
"enable_internet": "false",
|
|
108
|
+
"competition_sources": ["titanic"]
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### よく使うオプション
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
# GPU有効(XGBoost, LightGBM等のGPU学習に)
|
|
116
|
+
kaggle-notebook-deploy init my-competition --gpu
|
|
117
|
+
|
|
118
|
+
# 公開Notebook(メダル狙いのポートフォリオ用)
|
|
119
|
+
kaggle-notebook-deploy init my-competition --public
|
|
120
|
+
|
|
121
|
+
# タイトル指定
|
|
122
|
+
kaggle-notebook-deploy init my-competition --title "My Awesome Approach"
|
|
123
|
+
|
|
124
|
+
# ユーザー名を明示指定
|
|
125
|
+
kaggle-notebook-deploy init my-competition --username yasunorim
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### デプロイ前のバリデーション
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
kaggle-notebook-deploy validate titanic
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
チェック内容:
|
|
135
|
+
- 必須フィールド(id, title, code_file 等)の存在
|
|
136
|
+
- `id` が `username/slug` 形式か
|
|
137
|
+
- `code_file` で指定したファイルが実際に存在するか
|
|
138
|
+
- `language`, `kernel_type` の値が有効か
|
|
139
|
+
- コードコンペで `enable_internet: true` になっていないか(警告)
|
|
140
|
+
|
|
141
|
+
### Kaggleにデプロイ
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
# ローカルから直接プッシュ(バリデーション付き)
|
|
145
|
+
kaggle-notebook-deploy push titanic
|
|
146
|
+
|
|
147
|
+
# バリデーションのみスキップ
|
|
148
|
+
kaggle-notebook-deploy push titanic --skip-validate
|
|
149
|
+
|
|
150
|
+
# 実行せずにコマンドを確認
|
|
151
|
+
kaggle-notebook-deploy push titanic --dry-run
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### GitHub Actions経由でデプロイ
|
|
155
|
+
|
|
156
|
+
```bash
|
|
157
|
+
git add titanic/ && git commit -m "Update titanic baseline" && git push
|
|
158
|
+
gh workflow run kaggle-push.yml -f notebook_dir=titanic
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
GitHub Actionsのログで実行状況を確認できます:
|
|
162
|
+
|
|
163
|
+
```bash
|
|
164
|
+
gh run list --workflow=kaggle-push.yml
|
|
165
|
+
gh run view <run-id> --log
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### Notebookの実行状況を確認
|
|
169
|
+
|
|
170
|
+
```bash
|
|
171
|
+
kaggle kernels status your-username/titanic-baseline
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
ステータス: `QUEUED` → `RUNNING` → `COMPLETE` or `ERROR`
|
|
175
|
+
|
|
176
|
+
## 実践例:Deep Past Challenge
|
|
177
|
+
|
|
178
|
+
実際に [Deep Past Challenge](https://www.kaggle.com/competitions/deep-past-initiative-machine-translation)(Akkadian→English翻訳コンペ)で運用した例です。
|
|
179
|
+
|
|
180
|
+
```bash
|
|
181
|
+
# コンペ用ディレクトリを作成
|
|
182
|
+
kaggle-notebook-deploy init deep-past-initiative-machine-translation \
|
|
183
|
+
--title "Deep Past Akkadian Baseline"
|
|
184
|
+
|
|
185
|
+
# Notebookを編集(TF-IDFベースライン等)
|
|
186
|
+
vim deep-past-initiative-machine-translation/deep-past-initiative-machine-translation-baseline.ipynb
|
|
187
|
+
|
|
188
|
+
# バリデーション → デプロイ
|
|
189
|
+
kaggle-notebook-deploy validate deep-past-initiative-machine-translation
|
|
190
|
+
kaggle-notebook-deploy push deep-past-initiative-machine-translation
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
## ハマりポイントと対策
|
|
194
|
+
|
|
195
|
+
### 1. コードコンペでは `enable_internet: false` が必須
|
|
196
|
+
|
|
197
|
+
コードコンペ(Code Competition)では、提出するNotebookのインターネット接続が禁止されています。`enable_internet: true` だと提出ボタンが押せません。
|
|
198
|
+
|
|
199
|
+
`kaggle-notebook-deploy init` はデフォルトで `false` に設定するので、`--internet` フラグを付けなければ安全です。
|
|
200
|
+
|
|
201
|
+
### 2. データパスの罠
|
|
202
|
+
|
|
203
|
+
| ソース種別 | kernel-metadata.json のキー | マウントパス |
|
|
204
|
+
|---|---|---|
|
|
205
|
+
| コンペデータ | `competition_sources` | `/kaggle/input/competitions/<slug>/` |
|
|
206
|
+
| データセット | `dataset_sources` | `/kaggle/input/<slug>/` |
|
|
207
|
+
|
|
208
|
+
**`competition_sources` には `competitions/` サブディレクトリが入ります。** これは頻出のハマりポイントです。
|
|
209
|
+
|
|
210
|
+
Notebook内でデバッグするには:
|
|
211
|
+
|
|
212
|
+
```python
|
|
213
|
+
from pathlib import Path
|
|
214
|
+
for item in sorted(Path('/kaggle/input').iterdir()):
|
|
215
|
+
print(f' {item.name}/')
|
|
216
|
+
for sub in sorted(item.iterdir()):
|
|
217
|
+
print(f' {sub.name} ({sub.stat().st_size:,} bytes)')
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
### 3. API経由のSubmitはできない
|
|
221
|
+
|
|
222
|
+
Kaggle APIの `CreateCodeSubmission` は公開トークンでは `kernelSessions.get` 権限がなく403になります(2026-02時点)。
|
|
223
|
+
|
|
224
|
+
そのため、**最後のSubmitだけはブラウザ操作が必要**です。これはKaggle側の制限であり、kaggle-notebook-deployのスコープ外です。
|
|
225
|
+
|
|
226
|
+
### 4. `kaggle kernels push` はSecretsをリセットする
|
|
227
|
+
|
|
228
|
+
Kaggle Notebookの「Secrets」(W&B APIキー等)は、`kaggle kernels push` のたびに紐付けが外れます。
|
|
229
|
+
|
|
230
|
+
**対策**: CLIでpush → ブラウザのWeb UIでSecretsを再度有効化 → Run
|
|
231
|
+
|
|
232
|
+
### 5. コンペルール同意を忘れずに
|
|
233
|
+
|
|
234
|
+
`competition_sources` でコンペデータをマウントするには、ブラウザでコンペルールに同意(Accept)する必要があります。同意前だとデータがマウントされず、FileNotFoundErrorになります。
|
|
235
|
+
|
|
236
|
+
## ディレクトリ構成の推奨パターン
|
|
237
|
+
|
|
238
|
+
```
|
|
239
|
+
my-kaggle/
|
|
240
|
+
├── .github/workflows/
|
|
241
|
+
│ └── kaggle-push.yml # kaggle-notebook-deploy init-repo で生成
|
|
242
|
+
├── scripts/
|
|
243
|
+
│ └── setup-credentials.sh # kaggle-notebook-deploy init-repo で生成
|
|
244
|
+
├── titanic/ # kaggle-notebook-deploy init titanic で生成
|
|
245
|
+
│ ├── kernel-metadata.json
|
|
246
|
+
│ └── titanic-baseline.ipynb
|
|
247
|
+
├── house-prices/ # kaggle-notebook-deploy init house-prices で生成
|
|
248
|
+
│ ├── kernel-metadata.json
|
|
249
|
+
│ └── house-prices-baseline.ipynb
|
|
250
|
+
├── .gitignore
|
|
251
|
+
└── README.md
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
コンペごとにディレクトリを分け、それぞれに `kernel-metadata.json` と Notebook を配置します。GitHub Actions のワークフローは1つで全コンペに対応(`notebook_dir` パラメータで切り替え)。
|
|
255
|
+
|
|
256
|
+
## コマンドリファレンス
|
|
257
|
+
|
|
258
|
+
### `kaggle-notebook-deploy init <competition-slug>`
|
|
259
|
+
|
|
260
|
+
コンペ用ディレクトリを雛形から生成。
|
|
261
|
+
|
|
262
|
+
| オプション | 説明 | デフォルト |
|
|
263
|
+
|---|---|---|
|
|
264
|
+
| `-u, --username` | Kaggleユーザー名 | `~/.kaggle/kaggle.json` から取得 |
|
|
265
|
+
| `-t, --title` | Notebookタイトル | slugから自動生成 |
|
|
266
|
+
| `--gpu` | GPU有効化 | off |
|
|
267
|
+
| `--internet` | インターネット有効化 | off(コードコンペ向け) |
|
|
268
|
+
| `--public` | 公開Notebook | off(非公開) |
|
|
269
|
+
|
|
270
|
+
### `kaggle-notebook-deploy init-repo`
|
|
271
|
+
|
|
272
|
+
リポジトリにGitHub Actionsワークフローをセットアップ。
|
|
273
|
+
|
|
274
|
+
| オプション | 説明 |
|
|
275
|
+
|---|---|
|
|
276
|
+
| `-f, --force` | 既存ファイルを上書き |
|
|
277
|
+
|
|
278
|
+
### `kaggle-notebook-deploy validate [directory]`
|
|
279
|
+
|
|
280
|
+
`kernel-metadata.json` のバリデーション。エラーがあれば終了コード1で終了。
|
|
281
|
+
|
|
282
|
+
### `kaggle-notebook-deploy push [directory]`
|
|
283
|
+
|
|
284
|
+
Kaggle にNotebookをプッシュ(内部で `kaggle kernels push` を実行)。
|
|
285
|
+
|
|
286
|
+
| オプション | 説明 |
|
|
287
|
+
|---|---|
|
|
288
|
+
| `--skip-validate` | バリデーションをスキップ |
|
|
289
|
+
| `--dry-run` | 実行せずにコマンドを表示 |
|
|
290
|
+
|
|
291
|
+
## なぜ完全自動化できないのか
|
|
292
|
+
|
|
293
|
+
理想は `git push` だけで提出まで完了することですが、以下のKaggle側の制限により、最後のSubmitは手動です:
|
|
294
|
+
|
|
295
|
+
1. **API制限**: `CreateCodeSubmission` APIは公開トークンでは権限不足(403)
|
|
296
|
+
2. **Secrets問題**: `kaggle kernels push` でSecretsの紐付けがリセットされる
|
|
297
|
+
3. **ルール同意**: コンペ参加にはブラウザでの同意が必要
|
|
298
|
+
|
|
299
|
+
それでも、**コード管理・差分確認・デプロイの大部分を自動化**できるだけで、開発体験は大きく向上します。
|
|
300
|
+
|
|
301
|
+
## まとめ
|
|
302
|
+
|
|
303
|
+
```bash
|
|
304
|
+
pip install kaggle-notebook-deploy # インストール
|
|
305
|
+
kaggle-notebook-deploy init-repo # リポジトリセットアップ
|
|
306
|
+
kaggle-notebook-deploy init titanic # コンペ参加
|
|
307
|
+
# ... Notebookを編集 ...
|
|
308
|
+
kaggle-notebook-deploy push titanic # デプロイ
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
GitHub のエコシステム(バージョン管理、Actions、Secrets、Pull Request)をそのままKaggleコンペに活用できます。ブラウザエディタからの脱却、ぜひ試してみてください。
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 yasunorim
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: kaggle-notebook-deploy
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: git pushするだけでKaggle NotebookをデプロイするCLIツール
|
|
5
|
+
Project-URL: Homepage, https://github.com/yasumorishima/kaggle-notebook-deploy
|
|
6
|
+
Project-URL: Repository, https://github.com/yasumorishima/kaggle-notebook-deploy
|
|
7
|
+
Author: yasunorim
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: ci-cd,deploy,github-actions,kaggle,notebook
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
21
|
+
Requires-Python: >=3.9
|
|
22
|
+
Requires-Dist: click>=8.0
|
|
23
|
+
Requires-Dist: kaggle>=1.6.0
|
|
24
|
+
Requires-Dist: pyyaml>=6.0
|
|
25
|
+
Provides-Extra: dev
|
|
26
|
+
Requires-Dist: pytest-cov>=4.0; extra == 'dev'
|
|
27
|
+
Requires-Dist: pytest>=7.0; extra == 'dev'
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
|
|
30
|
+
# kaggle-notebook-deploy
|
|
31
|
+
|
|
32
|
+
`git push` するだけで Kaggle Notebook をデプロイする CLI ツール。
|
|
33
|
+
|
|
34
|
+
Kaggle Notebook のコード管理を GitHub に集約し、GitHub Actions 経由で自動デプロイするワークフローをセットアップします。
|
|
35
|
+
|
|
36
|
+
## ワークフロー
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
ノートブック編集 → git push → GitHub Actions → Kaggle にアップロード → ブラウザで Submit
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## インストール
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
pip install kaggle-notebook-deploy
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## クイックスタート
|
|
49
|
+
|
|
50
|
+
### 1. リポジトリのセットアップ
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
# GitHub Actions ワークフローと .gitignore を生成
|
|
54
|
+
kaggle-notebook-deploy init-repo
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
生成されるファイル:
|
|
58
|
+
- `.github/workflows/kaggle-push.yml` - Kaggle プッシュ用ワークフロー
|
|
59
|
+
- `scripts/setup-credentials.sh` - 認証情報セットアップスクリプト
|
|
60
|
+
- `.gitignore` への Kaggle 関連パターン追記
|
|
61
|
+
|
|
62
|
+
### 2. GitHub Secrets の設定
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
gh secret set KAGGLE_USERNAME
|
|
66
|
+
gh secret set KAGGLE_KEY
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### 3. コンペ用ディレクトリの作成
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
# 基本
|
|
73
|
+
kaggle-notebook-deploy init titanic
|
|
74
|
+
|
|
75
|
+
# GPU有効・公開Notebook
|
|
76
|
+
kaggle-notebook-deploy init deep-past-initiative-machine-translation --gpu --public
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
生成されるファイル:
|
|
80
|
+
- `<slug>/kernel-metadata.json` - Kaggle カーネルメタデータ
|
|
81
|
+
- `<slug>/<slug>-baseline.ipynb` - ベースライン Notebook
|
|
82
|
+
|
|
83
|
+
### 4. 開発・デプロイ
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
# Notebook を編集
|
|
87
|
+
vim titanic/titanic-baseline.ipynb
|
|
88
|
+
|
|
89
|
+
# バリデーション
|
|
90
|
+
kaggle-notebook-deploy validate titanic
|
|
91
|
+
|
|
92
|
+
# ローカルからプッシュ
|
|
93
|
+
kaggle-notebook-deploy push titanic
|
|
94
|
+
|
|
95
|
+
# または GitHub Actions 経由
|
|
96
|
+
git add titanic/ && git commit -m "Add titanic baseline" && git push
|
|
97
|
+
gh workflow run kaggle-push.yml -f notebook_dir=titanic
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## コマンド一覧
|
|
101
|
+
|
|
102
|
+
### `kaggle-notebook-deploy init <competition-slug>`
|
|
103
|
+
|
|
104
|
+
コンペ用ディレクトリを雛形から生成します。
|
|
105
|
+
|
|
106
|
+
| オプション | 説明 |
|
|
107
|
+
|---|---|
|
|
108
|
+
| `-u, --username` | Kaggle ユーザー名(省略時は ~/.kaggle/kaggle.json から取得) |
|
|
109
|
+
| `-t, --title` | Notebook タイトル(省略時はスラッグから自動生成) |
|
|
110
|
+
| `--gpu` | GPU 有効化 |
|
|
111
|
+
| `--internet` | インターネット有効化(コードコンペでは非推奨) |
|
|
112
|
+
| `--public` | 公開 Notebook として作成 |
|
|
113
|
+
|
|
114
|
+
### `kaggle-notebook-deploy init-repo`
|
|
115
|
+
|
|
116
|
+
GitHub Actions ワークフローと関連ファイルをセットアップします。
|
|
117
|
+
|
|
118
|
+
| オプション | 説明 |
|
|
119
|
+
|---|---|
|
|
120
|
+
| `-f, --force` | 既存ファイルを上書き |
|
|
121
|
+
|
|
122
|
+
### `kaggle-notebook-deploy validate [directory]`
|
|
123
|
+
|
|
124
|
+
`kernel-metadata.json` のバリデーションを行います。
|
|
125
|
+
|
|
126
|
+
チェック項目:
|
|
127
|
+
- 必須フィールドの存在
|
|
128
|
+
- `id` のフォーマット(`username/slug`)
|
|
129
|
+
- `code_file` の存在
|
|
130
|
+
- `language`, `kernel_type` の有効値
|
|
131
|
+
- `enable_internet` と `competition_sources` の整合性
|
|
132
|
+
|
|
133
|
+
### `kaggle-notebook-deploy push [directory]`
|
|
134
|
+
|
|
135
|
+
Kaggle に Notebook をプッシュします(内部で `kaggle kernels push` を実行)。
|
|
136
|
+
|
|
137
|
+
| オプション | 説明 |
|
|
138
|
+
|---|---|
|
|
139
|
+
| `--skip-validate` | バリデーションをスキップ |
|
|
140
|
+
| `--dry-run` | 実行せずにコマンドを表示 |
|
|
141
|
+
|
|
142
|
+
## 注意事項
|
|
143
|
+
|
|
144
|
+
### コードコンペでの制約
|
|
145
|
+
|
|
146
|
+
- `enable_internet: false` が必須(true だと提出不可)
|
|
147
|
+
- API での Submit は制限あり(手動ブラウザ Submit が必要)
|
|
148
|
+
- `kaggle kernels push` は Kaggle Secrets の紐付けをリセットするため、W&B 等を使う場合は Web UI で再設定が必要
|
|
149
|
+
|
|
150
|
+
### データパスの違い
|
|
151
|
+
|
|
152
|
+
| ソース | マウントパス |
|
|
153
|
+
|---|---|
|
|
154
|
+
| `competition_sources` | `/kaggle/input/competitions/<slug>/` |
|
|
155
|
+
| `dataset_sources` | `/kaggle/input/<slug>/` |
|
|
156
|
+
|
|
157
|
+
## ライセンス
|
|
158
|
+
|
|
159
|
+
MIT
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
# kaggle-notebook-deploy
|
|
2
|
+
|
|
3
|
+
`git push` するだけで Kaggle Notebook をデプロイする CLI ツール。
|
|
4
|
+
|
|
5
|
+
Kaggle Notebook のコード管理を GitHub に集約し、GitHub Actions 経由で自動デプロイするワークフローをセットアップします。
|
|
6
|
+
|
|
7
|
+
## ワークフロー
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
ノートブック編集 → git push → GitHub Actions → Kaggle にアップロード → ブラウザで Submit
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## インストール
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pip install kaggle-notebook-deploy
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## クイックスタート
|
|
20
|
+
|
|
21
|
+
### 1. リポジトリのセットアップ
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
# GitHub Actions ワークフローと .gitignore を生成
|
|
25
|
+
kaggle-notebook-deploy init-repo
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
生成されるファイル:
|
|
29
|
+
- `.github/workflows/kaggle-push.yml` - Kaggle プッシュ用ワークフロー
|
|
30
|
+
- `scripts/setup-credentials.sh` - 認証情報セットアップスクリプト
|
|
31
|
+
- `.gitignore` への Kaggle 関連パターン追記
|
|
32
|
+
|
|
33
|
+
### 2. GitHub Secrets の設定
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
gh secret set KAGGLE_USERNAME
|
|
37
|
+
gh secret set KAGGLE_KEY
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### 3. コンペ用ディレクトリの作成
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
# 基本
|
|
44
|
+
kaggle-notebook-deploy init titanic
|
|
45
|
+
|
|
46
|
+
# GPU有効・公開Notebook
|
|
47
|
+
kaggle-notebook-deploy init deep-past-initiative-machine-translation --gpu --public
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
生成されるファイル:
|
|
51
|
+
- `<slug>/kernel-metadata.json` - Kaggle カーネルメタデータ
|
|
52
|
+
- `<slug>/<slug>-baseline.ipynb` - ベースライン Notebook
|
|
53
|
+
|
|
54
|
+
### 4. 開発・デプロイ
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
# Notebook を編集
|
|
58
|
+
vim titanic/titanic-baseline.ipynb
|
|
59
|
+
|
|
60
|
+
# バリデーション
|
|
61
|
+
kaggle-notebook-deploy validate titanic
|
|
62
|
+
|
|
63
|
+
# ローカルからプッシュ
|
|
64
|
+
kaggle-notebook-deploy push titanic
|
|
65
|
+
|
|
66
|
+
# または GitHub Actions 経由
|
|
67
|
+
git add titanic/ && git commit -m "Add titanic baseline" && git push
|
|
68
|
+
gh workflow run kaggle-push.yml -f notebook_dir=titanic
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## コマンド一覧
|
|
72
|
+
|
|
73
|
+
### `kaggle-notebook-deploy init <competition-slug>`
|
|
74
|
+
|
|
75
|
+
コンペ用ディレクトリを雛形から生成します。
|
|
76
|
+
|
|
77
|
+
| オプション | 説明 |
|
|
78
|
+
|---|---|
|
|
79
|
+
| `-u, --username` | Kaggle ユーザー名(省略時は ~/.kaggle/kaggle.json から取得) |
|
|
80
|
+
| `-t, --title` | Notebook タイトル(省略時はスラッグから自動生成) |
|
|
81
|
+
| `--gpu` | GPU 有効化 |
|
|
82
|
+
| `--internet` | インターネット有効化(コードコンペでは非推奨) |
|
|
83
|
+
| `--public` | 公開 Notebook として作成 |
|
|
84
|
+
|
|
85
|
+
### `kaggle-notebook-deploy init-repo`
|
|
86
|
+
|
|
87
|
+
GitHub Actions ワークフローと関連ファイルをセットアップします。
|
|
88
|
+
|
|
89
|
+
| オプション | 説明 |
|
|
90
|
+
|---|---|
|
|
91
|
+
| `-f, --force` | 既存ファイルを上書き |
|
|
92
|
+
|
|
93
|
+
### `kaggle-notebook-deploy validate [directory]`
|
|
94
|
+
|
|
95
|
+
`kernel-metadata.json` のバリデーションを行います。
|
|
96
|
+
|
|
97
|
+
チェック項目:
|
|
98
|
+
- 必須フィールドの存在
|
|
99
|
+
- `id` のフォーマット(`username/slug`)
|
|
100
|
+
- `code_file` の存在
|
|
101
|
+
- `language`, `kernel_type` の有効値
|
|
102
|
+
- `enable_internet` と `competition_sources` の整合性
|
|
103
|
+
|
|
104
|
+
### `kaggle-notebook-deploy push [directory]`
|
|
105
|
+
|
|
106
|
+
Kaggle に Notebook をプッシュします(内部で `kaggle kernels push` を実行)。
|
|
107
|
+
|
|
108
|
+
| オプション | 説明 |
|
|
109
|
+
|---|---|
|
|
110
|
+
| `--skip-validate` | バリデーションをスキップ |
|
|
111
|
+
| `--dry-run` | 実行せずにコマンドを表示 |
|
|
112
|
+
|
|
113
|
+
## 注意事項
|
|
114
|
+
|
|
115
|
+
### コードコンペでの制約
|
|
116
|
+
|
|
117
|
+
- `enable_internet: false` が必須(true だと提出不可)
|
|
118
|
+
- API での Submit は制限あり(手動ブラウザ Submit が必要)
|
|
119
|
+
- `kaggle kernels push` は Kaggle Secrets の紐付けをリセットするため、W&B 等を使う場合は Web UI で再設定が必要
|
|
120
|
+
|
|
121
|
+
### データパスの違い
|
|
122
|
+
|
|
123
|
+
| ソース | マウントパス |
|
|
124
|
+
|---|---|
|
|
125
|
+
| `competition_sources` | `/kaggle/input/competitions/<slug>/` |
|
|
126
|
+
| `dataset_sources` | `/kaggle/input/<slug>/` |
|
|
127
|
+
|
|
128
|
+
## ライセンス
|
|
129
|
+
|
|
130
|
+
MIT
|