Skip to content

Commit 8268c88

Browse files
authored
Merge pull request #29 from ayasyrev/renames
Renames
2 parents a288a25 + b308257 commit 8268c88

File tree

14 files changed

+139
-21
lines changed

14 files changed

+139
-21
lines changed

docs/overrides/partials/copyright.html

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
{#-
2-
This file was automatically generated - do not edit
3-
-#}
41
<div class="md-copyright">
52
{% if config.copyright %}
63
<div class="md-copyright__highlight">

mkdocs.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ theme:
1919
markdown_extensions:
2020
- admonition
2121
- pymdownx.details
22-
- pymdownx.superfences
22+
- pymdownx.superfences
23+
copyright: Copyright &copy; 2022-2023 Andrei Yasyrev.

src/nbdocs/apps/app_nb2md.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from nbdocs.convert import convert2md, filter_changed
1010
from nbdocs.core import get_nb_names
11-
from nbdocs.settings import get_config
11+
from nbdocs.cfg_tools import get_config
1212

1313

1414
parser_cfg = ArgumentParserCfg(description="Nb2Md. Convert notebooks to Markdown.")
@@ -55,7 +55,9 @@ def convert(
5555
rprint(f"Found {nbs_number} notebooks.")
5656

5757
cfg = get_config(
58-
notebooks_path=app_cfg.nb_path, docs_path=app_cfg.dest_path, images_path=app_cfg.images_path
58+
notebooks_path=app_cfg.nb_path,
59+
docs_path=app_cfg.dest_path,
60+
images_path=app_cfg.images_path,
5961
)
6062

6163
# check logic -> do we need subdir and how to check modified Nbs

src/nbdocs/apps/app_nbclean.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from nbdocs.clean import clean_nb_file
99
from nbdocs.core import get_nb_names
10-
from nbdocs.settings import get_config
10+
from nbdocs.cfg_tools import get_config
1111

1212

1313
parser_cfg = ArgumentParserCfg(
@@ -23,7 +23,10 @@ class AppConfig:
2323
"nb_path", help="Path to NB or folder with Nbs to clean"
2424
)
2525
clear_execution_count: bool = field_argument(
26-
flag="--no-ec", default=True, action="store_false", help="Clean execution counts."
26+
flag="--no-ec",
27+
default=True,
28+
action="store_false",
29+
help="Clean execution counts.",
2730
)
2831

2932

src/nbdocs/apps/app_nbdocs.py

Lines changed: 67 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,30 @@
1+
from pathlib import Path
12
import sys
23
from dataclasses import dataclass
34
from typing import Optional, Sequence
45

5-
from argparsecfg import ArgumentParserCfg, field_argument, parse_args
6+
from argparsecfg import (
7+
ArgumentParserCfg,
8+
add_args_from_dc,
9+
create_dc_obj,
10+
create_parser,
11+
field_argument,
12+
)
613
from rich import print as rprint
714

815
from nbdocs.convert import convert2md, filter_changed
916
from nbdocs.core import get_nb_names
10-
from nbdocs.settings import get_config
17+
from nbdocs.cfg_tools import get_config
18+
from nbdocs.default_settings import (
19+
NBDOCS_SETTINGS,
20+
MKDOCS_BASE,
21+
MATERIAL_BASE,
22+
FOOTER_HTML,
23+
)
1124

12-
parser_cfg = ArgumentParserCfg(description="NbDocs. Convert notebooks to docs. Default to .md")
25+
parser_cfg = ArgumentParserCfg(
26+
description="NbDocs. Convert notebooks to docs. Default to .md"
27+
)
1328

1429

1530
@dataclass
@@ -21,7 +36,9 @@ class AppConfig:
2136
)
2237

2338

24-
def nbdocs(app_cfg: AppConfig,) -> None:
39+
def nbdocs(
40+
app_cfg: AppConfig,
41+
) -> None:
2542
"""NbDocs. Convert notebooks to docs. Default to .md"""
2643
cfg = get_config()
2744
nb_names = get_nb_names(cfg.notebooks_path)
@@ -45,9 +62,53 @@ def nbdocs(app_cfg: AppConfig,) -> None:
4562
convert2md(nb_names, cfg)
4663

4764

65+
@dataclass
66+
class SetupCfg:
67+
clean: bool = field_argument(
68+
"-c",
69+
default=False,
70+
action="store_true",
71+
help="Clean MkDocs setup.",
72+
)
73+
74+
75+
def setup(cfg: SetupCfg) -> None:
76+
"""Initialize config."""
77+
rprint("Settings up NbDocs.")
78+
# create nbdocs config - nbdocs.ini
79+
with open("nbdocs.ini", "w", encoding="utf-8") as f:
80+
f.write(NBDOCS_SETTINGS)
81+
# create mkdocs config - mkdocs.yaml
82+
mkdocs_setup = MKDOCS_BASE
83+
if not cfg.clean: # setting mkdocs material
84+
mkdocs_setup += MATERIAL_BASE
85+
# create footer with material
86+
filename = Path("docs/overrides/partials/copyright.html")
87+
filename.parent.mkdir(parents=True, exist_ok=True)
88+
with open(filename, "w", encoding="utf-8") as f:
89+
f.write(FOOTER_HTML)
90+
with open("mkdocs.yaml", "w", encoding="utf-8") as f:
91+
f.write(mkdocs_setup)
92+
rprint("Done.")
93+
94+
4895
def main(args: Optional[Sequence[str]] = None) -> None:
49-
app_cfg = parse_args(AppConfig, parser_cfg, args)
50-
nbdocs(app_cfg)
96+
parser = create_parser(parser_cfg)
97+
add_args_from_dc(parser, AppConfig)
98+
subparsers = parser.add_subparsers(title="Commands", help="Available commands.")
99+
parser_init = subparsers.add_parser(
100+
"init", help="Initialize config", description="Initialize NbDocs config"
101+
)
102+
parser_init.set_defaults(command="init")
103+
add_args_from_dc(parser_init, SetupCfg)
104+
parsed_args = parser.parse_args(args=args)
105+
if hasattr(parsed_args, "command"):
106+
if parsed_args.command == "init":
107+
setup_cfg = create_dc_obj(SetupCfg, parsed_args)
108+
setup(setup_cfg)
109+
else:
110+
app_cfg = create_dc_obj(AppConfig, parsed_args)
111+
nbdocs(app_cfg)
51112

52113

53114
if __name__ == "__main__":
File renamed without changes.

src/nbdocs/convert.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
md_find_image_names,
1717
md_process_output_flag,
1818
)
19-
from nbdocs.settings import NbDocsCfg
19+
from nbdocs.cfg_tools import NbDocsCfg
2020
from nbdocs.typing import Nb, TPreprocessor
2121

2222

src/nbdocs/default_settings.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# settings schema for nbdocs and mkdocs.yaml
2+
3+
NBDOCS_SETTINGS = """[nbdocs]
4+
docs_path = docs
5+
notebooks_path = nbs
6+
images_path = images
7+
"""
8+
9+
10+
MKDOCS_BASE = """site_name: Your site name
11+
# repo_url: Your repo url
12+
# repo_name: Your repo name
13+
# docs_dir: docs # The docs directory.
14+
15+
# copyright:
16+
"""
17+
18+
MATERIAL_BASE = """theme:
19+
name: material
20+
custom_dir: docs/overrides
21+
22+
palette:
23+
- scheme: default
24+
toggle:
25+
icon: material/toggle-switch-off-outline
26+
name: Switch to dark mode
27+
- scheme: slate
28+
toggle:
29+
icon: material/toggle-switch
30+
name: Switch to light mode
31+
markdown_extensions:
32+
- admonition
33+
- pymdownx.details
34+
- pymdownx.superfences
35+
"""
36+
37+
FOOTER_HTML = """<div class="md-copyright">
38+
{% if config.copyright %}
39+
<div class="md-copyright__highlight">
40+
{{ config.copyright }}
41+
</div>
42+
{% endif %}
43+
{% if not config.extra.generator == false %}
44+
Made with
45+
<a href="https://github.com/ayasyrev/nbdocs" target="_blank" rel="noopener">
46+
NbDocs
47+
</a>
48+
and
49+
<a href="https://squidfunk.github.io/mkdocs-material/" target="_blank" rel="noopener">
50+
Material for MkDocs
51+
</a>
52+
{% endif %}
53+
</div>
54+
"""

src/nbdocs/process.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from nbconvert.exporters.exporter import ResourcesDict
99
from nbconvert.preprocessors.base import Preprocessor
1010

11-
from nbdocs.settings import NbDocsCfg
11+
from nbdocs.cfg_tools import NbDocsCfg
1212
from nbdocs.typing import CellAndResources, CodeCell, MarkdownCell, Nb, Cell
1313

1414

src/nbdocs/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.2"
1+
__version__ = "0.2.1_dev"

tests/test_convert.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from pytest import CaptureFixture
44
from nbdocs.core import get_nb_names, read_nb, write_nb
55
from nbdocs.convert import MdConverter, convert2md, filter_changed
6-
from nbdocs.settings import NbDocsCfg
6+
from nbdocs.cfg_tools import NbDocsCfg
77

88
from nbdocs.tests.base import create_nb, create_test_nb, create_tmp_image_file
99

tests/test_core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import pytest
44

55
from nbdocs.core import get_nb_names, read_nb, write_nb
6-
from nbdocs.settings import get_config
6+
from nbdocs.cfg_tools import get_config
77
from nbdocs.typing import Nb
88

99
nb_path = Path("tests/test_nbs")

tests/test_process_links.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
get_image_link_re,
1010
md_find_image_names,
1111
)
12-
from nbdocs.settings import NbDocsCfg
12+
from nbdocs.cfg_tools import NbDocsCfg
1313
from nbdocs.tests.base import create_tmp_image_file
1414

1515

tests/test_settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import pytest
66

7-
from nbdocs.settings import (
7+
from nbdocs.cfg_tools import (
88
NAMES,
99
get_config,
1010
read_ini_config,

0 commit comments

Comments
 (0)