Skip to content

Commit 05c512c

Browse files
authored
Merge pull request #1350 from dsm-72/add-repo-option
2 parents 01b84f7 + 20a421d commit 05c512c

File tree

2 files changed

+98
-20
lines changed

2 files changed

+98
-20
lines changed

nbdev/cli.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
# %% ../nbs/api/13_cli.ipynb 2
44
from __future__ import annotations
5+
from multiprocessing import Value
56
import warnings
67

78
from .config import *

nbs/api/13_cli.ipynb

Lines changed: 97 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"cells": [
33
{
4+
"attachments": {},
45
"cell_type": "markdown",
56
"id": "ff4908a6",
67
"metadata": {},
@@ -14,7 +15,11 @@
1415
"cell_type": "code",
1516
"execution_count": null,
1617
"id": "c6d13dc1",
17-
"metadata": {},
18+
"metadata": {
19+
"vscode": {
20+
"languageId": "python"
21+
}
22+
},
1823
"outputs": [],
1924
"source": [
2025
"#|default_exp cli"
@@ -24,7 +29,11 @@
2429
"cell_type": "code",
2530
"execution_count": null,
2631
"id": "6a35c7c4-748f-4c82-a9bf-c780a8d83e90",
27-
"metadata": {},
32+
"metadata": {
33+
"vscode": {
34+
"languageId": "python"
35+
}
36+
},
2837
"outputs": [],
2938
"source": [
3039
"#|export\n",
@@ -56,7 +65,11 @@
5665
"cell_type": "code",
5766
"execution_count": null,
5867
"id": "1e623a3d-3e77-44c6-adf3-4768b78328c5",
59-
"metadata": {},
68+
"metadata": {
69+
"vscode": {
70+
"languageId": "python"
71+
}
72+
},
6073
"outputs": [],
6174
"source": [
6275
"#|hide\n",
@@ -66,6 +79,7 @@
6679
]
6780
},
6881
{
82+
"attachments": {},
6983
"cell_type": "markdown",
7084
"id": "e9fc60a8",
7185
"metadata": {},
@@ -77,7 +91,11 @@
7791
"cell_type": "code",
7892
"execution_count": null,
7993
"id": "86c29369",
80-
"metadata": {},
94+
"metadata": {
95+
"vscode": {
96+
"languageId": "python"
97+
}
98+
},
8199
"outputs": [],
82100
"source": [
83101
"#|export\n",
@@ -108,7 +126,11 @@
108126
"cell_type": "code",
109127
"execution_count": null,
110128
"id": "fe4dc8bf",
111-
"metadata": {},
129+
"metadata": {
130+
"vscode": {
131+
"languageId": "python"
132+
}
133+
},
112134
"outputs": [],
113135
"source": [
114136
"#|hide\n",
@@ -117,6 +139,7 @@
117139
]
118140
},
119141
{
142+
"attachments": {},
120143
"cell_type": "markdown",
121144
"id": "3e7e76f7-7b19-4347-a52b-c33ad15d2178",
122145
"metadata": {},
@@ -128,7 +151,11 @@
128151
"cell_type": "code",
129152
"execution_count": null,
130153
"id": "a1c001af-2c7c-4e0b-8c7d-a7d40c08f5e9",
131-
"metadata": {},
154+
"metadata": {
155+
"vscode": {
156+
"languageId": "python"
157+
}
158+
},
132159
"outputs": [],
133160
"source": [
134161
"#|export\n",
@@ -141,7 +168,11 @@
141168
"cell_type": "code",
142169
"execution_count": null,
143170
"id": "60df4b28",
144-
"metadata": {},
171+
"metadata": {
172+
"vscode": {
173+
"languageId": "python"
174+
}
175+
},
145176
"outputs": [],
146177
"source": [
147178
"#|export\n",
@@ -157,7 +188,11 @@
157188
"cell_type": "code",
158189
"execution_count": null,
159190
"id": "dd385911-aa8f-44e7-8d46-7b8a20f3b010",
160-
"metadata": {},
191+
"metadata": {
192+
"vscode": {
193+
"languageId": "python"
194+
}
195+
},
161196
"outputs": [],
162197
"source": [
163198
"#|export\n",
@@ -176,7 +211,11 @@
176211
"cell_type": "code",
177212
"execution_count": null,
178213
"id": "c4a663d9",
179-
"metadata": {},
214+
"metadata": {
215+
"vscode": {
216+
"languageId": "python"
217+
}
218+
},
180219
"outputs": [],
181220
"source": [
182221
"#|export\n",
@@ -190,13 +229,28 @@
190229
" _update_repo_meta(cfg)\n",
191230
"\n",
192231
" path = Path()\n",
193-
" with warnings.catch_warnings():\n",
194-
" warnings.simplefilter('ignore', UserWarning)\n",
195-
" tag = GhApi(gh_host='https://api.github.com', authenticate=False).repos.get_latest_release('fastai', 'nbdev-template').tag_name\n",
196-
" url = f\"https://github.com/fastai/nbdev-template/archive/{tag}.tar.gz\"\n",
197-
" extract_tgz(url)\n",
198-
" tmpl_path = path/f'nbdev-template-{tag}'\n",
199232
"\n",
233+
" _ORG_OR_USR = 'fastai'\n",
234+
" _REPOSITORY = 'nbdev-template'\n",
235+
" _TEMPLATE = f'{_ORG_OR_USR}/{_TEMPLATE}'\n",
236+
" template = kwargs.get('template', _TEMPLATE)\n",
237+
" try:\n",
238+
" org_or_usr, repo = template.split('/')\n",
239+
" except ValueError:\n",
240+
" org_or_usr, repo = _ORG_OR_USR, _REPOSITORY\n",
241+
"\n",
242+
"\n",
243+
" tag = kwargs.get('tag', None)\n",
244+
" if tag is None:\n",
245+
" with warnings.catch_warnings():\n",
246+
" warnings.simplefilter('ignore', UserWarning)\n",
247+
"\n",
248+
" tag = GhApi(gh_host='https://api.github.com', authenticate=False).repos.get_latest_release(org_or_usr, repo).tag_name\n",
249+
"\n",
250+
" url = f\"https://github.com/{org_or_usr}/{repo}/archive/{tag}.tar.gz\"\n",
251+
" extract_tgz(url)\n",
252+
" tmpl_path = path/f'{repo}-{tag}'\n",
253+
" \n",
200254
" cfg.nbs_path.mkdir(exist_ok=True)\n",
201255
" nbexists = bool(first(cfg.nbs_path.glob('*.ipynb')))\n",
202256
" _nbs_path_sufs = ('.ipynb','.css')\n",
@@ -215,6 +269,7 @@
215269
]
216270
},
217271
{
272+
"attachments": {},
218273
"cell_type": "markdown",
219274
"id": "2239c092",
220275
"metadata": {},
@@ -282,7 +337,11 @@
282337
"cell_type": "code",
283338
"execution_count": null,
284339
"id": "edc5f6e9",
285-
"metadata": {},
340+
"metadata": {
341+
"vscode": {
342+
"languageId": "python"
343+
}
344+
},
286345
"outputs": [],
287346
"source": [
288347
"#|hide\n",
@@ -292,6 +351,7 @@
292351
]
293352
},
294353
{
354+
"attachments": {},
295355
"cell_type": "markdown",
296356
"id": "280e0d6d-6559-4fc3-9478-320ce5eff0dc",
297357
"metadata": {},
@@ -303,7 +363,11 @@
303363
"cell_type": "code",
304364
"execution_count": null,
305365
"id": "e34f6ff4-f85b-4805-b406-121279cc9246",
306-
"metadata": {},
366+
"metadata": {
367+
"vscode": {
368+
"languageId": "python"
369+
}
370+
},
307371
"outputs": [],
308372
"source": [
309373
"#|export\n",
@@ -318,7 +382,11 @@
318382
"cell_type": "code",
319383
"execution_count": null,
320384
"id": "b50d27fb-c343-47e2-a008-7ebdd02e1356",
321-
"metadata": {},
385+
"metadata": {
386+
"vscode": {
387+
"languageId": "python"
388+
}
389+
},
322390
"outputs": [
323391
{
324392
"name": "stdout",
@@ -361,6 +429,7 @@
361429
]
362430
},
363431
{
432+
"attachments": {},
364433
"cell_type": "markdown",
365434
"id": "aa35b010",
366435
"metadata": {},
@@ -372,7 +441,11 @@
372441
"cell_type": "code",
373442
"execution_count": null,
374443
"id": "3d8031ce",
375-
"metadata": {},
444+
"metadata": {
445+
"vscode": {
446+
"languageId": "python"
447+
}
448+
},
376449
"outputs": [],
377450
"source": [
378451
"#|hide\n",
@@ -383,7 +456,11 @@
383456
"cell_type": "code",
384457
"execution_count": null,
385458
"id": "12588a26-43a6-42c4-bacd-896293c871ab",
386-
"metadata": {},
459+
"metadata": {
460+
"vscode": {
461+
"languageId": "python"
462+
}
463+
},
387464
"outputs": [],
388465
"source": []
389466
}

0 commit comments

Comments
 (0)