Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

run nbdev_readme in nbdev_new #919

Merged
merged 3 commits into from
Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions nbdev/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from .doclinks import *
from .test import *
from .clean import *
from .quarto import refresh_quarto_yml
from .quarto import nbdev_readme, refresh_quarto_yml
from .frontmatter import FrontmatterProc

from execnb.nbio import *
Expand Down Expand Up @@ -85,7 +85,7 @@ def _render_nb(fn, cfg):
@call_parse
@delegates(nbdev_create_config)
def nbdev_new(**kwargs):
"Create a new project."
"Create an nbdev project."
from fastcore.net import urljson

nbdev_create_config.__wrapped__(**kwargs)
Expand All @@ -107,8 +107,9 @@ def nbdev_new(**kwargs):
refresh_quarto_yml()

nbdev_export.__wrapped__()
nbdev_readme.__wrapped__()

# %% ../nbs/12_cli.ipynb 28
# %% ../nbs/12_cli.ipynb 15
@call_parse
def chelp():
"Show help for all console scripts"
Expand Down
21 changes: 10 additions & 11 deletions nbdev/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,44 +169,43 @@ def nbdev_create_config(
cfg_fn = Path(path)/cfg_name
print(f'{cfg_fn} created.')

# %% ../nbs/01_config.ipynb 36
# %% ../nbs/01_config.ipynb 26
def _nbdev_config_file(cfg_name=_nbdev_cfg_name, path=None):
cfg_path = path = Path.cwd() if path is None else Path(path)
while cfg_path != cfg_path.parent and not (cfg_path/cfg_name).exists(): cfg_path = cfg_path.parent
if not (cfg_path/cfg_name).exists(): cfg_path = path
return cfg_path/cfg_name

# %% ../nbs/01_config.ipynb 38
# %% ../nbs/01_config.ipynb 28
def _xdg_config_paths(cfg_name=_nbdev_cfg_name):
xdg_config_paths = reversed([xdg_config_home()]+xdg_config_dirs())
return [o/_nbdev_home_dir/cfg_name for o in xdg_config_paths]

# %% ../nbs/01_config.ipynb 39
# %% ../nbs/01_config.ipynb 29
@functools.lru_cache(maxsize=None)
def get_config(cfg_name=_nbdev_cfg_name, path=None):
"""Return nbdev config.\n\nSearches up from `path` until `cfg_name` is found. User settings are loaded from
`~/.config/nbdev/{cfg_name}`. Unspecified optional settings return defaults."""
"Return nbdev config."
cfg_file = _nbdev_config_file(cfg_name, path)
extra_files = _xdg_config_paths(cfg_name)
cfg = Config(cfg_file.parent, cfg_file.name, extra_files=extra_files)
return _apply_defaults(cfg)

# %% ../nbs/01_config.ipynb 65
# %% ../nbs/01_config.ipynb 45
def config_key(c, default=None, path=True, missing_ok=None):
"Deprecated: use `get_config().get` or `get_config().path` instead."
warn("`config_key` is deprecated. Use `get_config().get` or `get_config().path` instead.", DeprecationWarning)
return get_config().path(c, default) if path else get_config().get(c, default)

# %% ../nbs/01_config.ipynb 67
# %% ../nbs/01_config.ipynb 47
def create_output(txt, mime):
"Add a cell output containing `txt` of the `mime` text MIME sub-type"
return [{"data": { f"text/{mime}": str(txt).splitlines(True) },
"execution_count": 1, "metadata": {}, "output_type": "execute_result"}]

# %% ../nbs/01_config.ipynb 68
# %% ../nbs/01_config.ipynb 48
def show_src(src, lang='python'): return Markdown(f'```{lang}\n{src}\n```')

# %% ../nbs/01_config.ipynb 71
# %% ../nbs/01_config.ipynb 51
_re_version = re.compile('^__version__\s*=.*$', re.MULTILINE)
_init = '__init__.py'

Expand Down Expand Up @@ -235,13 +234,13 @@ def add_init(path=None):
if _has_py(fs) or any(filter(_has_py, subds)) and not (r/_init).exists(): (r/_init).touch()
update_version(path)

# %% ../nbs/01_config.ipynb 74
# %% ../nbs/01_config.ipynb 54
def write_cells(cells, hdr, file, offset=0):
"Write `cells` to `file` along with header `hdr` starting at index `offset` (mainly for nbdev internal use)."
for cell in cells:
if cell.source.strip(): file.write(f'\n\n{hdr} {cell.idx_+offset}\n{cell.source}')

# %% ../nbs/01_config.ipynb 75
# %% ../nbs/01_config.ipynb 55
def _basic_export_nb(fname, name, dest=None):
"Basic exporter to bootstrap nbdev."
if dest is None: dest = get_config().path('lib_path')
Expand Down
Loading