Skip to content

Commit 940db05

Browse files
committed
add repo and tag options to nbdev_new`
1 parent 4af4d47 commit 940db05

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

nbdev/cli.py

Lines changed: 21 additions & 5 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 *
@@ -85,12 +86,27 @@ def nbdev_new(**kwargs):
8586
_update_repo_meta(cfg)
8687

8788
path = Path()
88-
with warnings.catch_warnings():
89-
warnings.simplefilter('ignore', UserWarning)
90-
tag = GhApi(gh_host='https://api.github.com', authenticate=False).repos.get_latest_release('fastai', 'nbdev-template').tag_name
91-
url = f"https://github.com/fastai/nbdev-template/archive/{tag}.tar.gz"
89+
90+
_ORG_OR_USR = 'fastai'
91+
_REPOSITORY = 'nbdev-template'
92+
_TEMPLATE = f'{_ORG_OR_USR}/{_TEMPLATE}'
93+
template = kwargs.get('template', _TEMPLATE)
94+
try:
95+
org_or_usr, repo = template.split('/')
96+
except ValueError:
97+
org_or_usr, repo = _ORG_OR_USR, _REPOSITORY
98+
99+
100+
tag = kwargs.get('tag', None)
101+
if tag is None:
102+
with warnings.catch_warnings():
103+
warnings.simplefilter('ignore', UserWarning)
104+
105+
tag = GhApi(gh_host='https://api.github.com', authenticate=False).repos.get_latest_release(org_or_usr, repo).tag_name
106+
107+
url = f"https://github.com/{org_or_usr}/{repo}/archive/{tag}.tar.gz"
92108
extract_tgz(url)
93-
tmpl_path = path/f'nbdev-template-{tag}'
109+
tmpl_path = path/f'{repo}-{tag}'
94110

95111
cfg.nbs_path.mkdir(exist_ok=True)
96112
nbexists = bool(first(cfg.nbs_path.glob('*.ipynb')))

0 commit comments

Comments
 (0)