nbdevAuto 0.3.63__tar.gz → 0.3.64__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nbdevAuto
3
- Version: 0.3.63
3
+ Version: 0.3.64
4
4
  Summary: automating nbdev
5
5
  Author-email: Benedict Thekkel <bthekkel1@gmail.com>
6
6
  License-Expression: Apache-2.0
@@ -23,6 +23,7 @@ Description-Content-Type: text/markdown
23
23
  License-File: LICENSE
24
24
  Requires-Dist: graphviz
25
25
  Requires-Dist: fastcore
26
+ Requires-Dist: rich
26
27
  Provides-Extra: gh
27
28
  Requires-Dist: githubkit>=0.12; extra == "gh"
28
29
  Dynamic: license-file
@@ -0,0 +1 @@
1
+ __version__ = "0.3.64"
@@ -5,7 +5,12 @@ d = { 'settings': { 'branch': 'main',
5
5
  'doc_host': 'https://bthek1.github.io',
6
6
  'git_url': 'https://github.com/bthek1/nbdevAuto',
7
7
  'lib_path': 'nbdevAuto'},
8
- 'syms': { 'nbdevAuto.automate': { 'nbdevAuto.automate.gacp': ('automate.html#gacp', 'nbdevAuto/automate.py'),
8
+ 'syms': { 'nbdevAuto.automate': { 'nbdevAuto.automate._banner': ('automate.html#_banner', 'nbdevAuto/automate.py'),
9
+ 'nbdevAuto.automate._done': ('automate.html#_done', 'nbdevAuto/automate.py'),
10
+ 'nbdevAuto.automate._dur': ('automate.html#_dur', 'nbdevAuto/automate.py'),
11
+ 'nbdevAuto.automate._status_table': ('automate.html#_status_table', 'nbdevAuto/automate.py'),
12
+ 'nbdevAuto.automate._step': ('automate.html#_step', 'nbdevAuto/automate.py'),
13
+ 'nbdevAuto.automate.gacp': ('automate.html#gacp', 'nbdevAuto/automate.py'),
9
14
  'nbdevAuto.automate.help_output': ('automate.html#help_output', 'nbdevAuto/automate.py'),
10
15
  'nbdevAuto.automate.prep': ('automate.html#prep', 'nbdevAuto/automate.py'),
11
16
  'nbdevAuto.automate.release': ('automate.html#release', 'nbdevAuto/automate.py'),
@@ -0,0 +1,209 @@
1
+ """Automate
2
+
3
+ Docs: https://bthek1.github.io/nbdevAuto/automate.html.md"""
4
+
5
+ # AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/01_Automate.ipynb.
6
+
7
+ # %% auto #0
8
+ __all__ = ['prep', 'gacp', 'status', 'upload', 'release_git', 'release_pypi', 'release', 'help_output']
9
+
10
+ # %% ../nbs/01_Automate.ipynb #6d1499d1-aa55-47d8-92fd-fa056b1fb135
11
+ from fastcore.script import *
12
+ from rich import box
13
+ from rich.console import Console
14
+ from rich.markup import escape
15
+ from rich.table import Table
16
+
17
+ # %% ../nbs/01_Automate.ipynb #7c1e5a90-3f52-4d21-9b6a-2c0f4e8d1a37
18
+ from contextlib import contextmanager
19
+ from time import perf_counter
20
+
21
+ from nbdevAuto import __version__
22
+
23
+ console = Console()
24
+
25
+ # `git status -s` codes: colour, and the word for the third column.
26
+ _CODE_STYLE = {"M":"yellow", "A":"green", "D":"red", "R":"cyan", "C":"cyan", "U":"magenta", "?":"dim"}
27
+ _CODE_LABEL = {"M":"modified", "A":"added", "D":"deleted", "R":"renamed", "C":"copied",
28
+ "U":"conflict", "?":"untracked"}
29
+
30
+ def _dur(t0):
31
+ "Elapsed time since `t0`, at a readable scale"
32
+ s = perf_counter() - t0
33
+ if s < 1: return f"{s*1000:.0f}ms"
34
+ if s < 60: return f"{s:.1f}s"
35
+ return f"{int(s)//60}m{int(s)%60:02d}s"
36
+
37
+ def _banner(cmd):
38
+ "Command header, with the package version alongside"
39
+ console.rule(f"[bold cyan]{cmd}[/bold cyan] [dim]nbdevAuto {__version__}[/dim]", style="cyan")
40
+
41
+ def _done(cmd, t0):
42
+ "Closing summary for a multi-stage command"
43
+ console.rule(f"[green]{cmd} finished[/green] [dim]in {_dur(t0)}[/dim]", style="green")
44
+
45
+ @contextmanager
46
+ def _step(n, total, label):
47
+ "Run one stage, reporting its outcome and duration. Re-raises so nothing is swallowed"
48
+ console.print(f"[dim]{n}/{total}[/dim] [bold]{label}[/bold]")
49
+ t0 = perf_counter()
50
+ try:
51
+ yield
52
+ except BaseException:
53
+ console.print(f" [bold red]FAIL[/bold red] [dim]{_dur(t0)}[/dim]\n")
54
+ raise
55
+ console.print(f" [green]OK[/green] [dim]{_dur(t0)}[/dim]\n")
56
+
57
+ def _status_table(porcelain):
58
+ "Render `git status -s` output as a table, one row per path"
59
+ t = Table(box=box.SIMPLE, show_header=False, pad_edge=False, expand=False)
60
+ t.add_column("code", no_wrap=True, justify="right")
61
+ t.add_column("path", overflow="fold")
62
+ t.add_column("what", style="dim", no_wrap=True)
63
+ n = 0
64
+ for line in porcelain.splitlines():
65
+ if not line.strip(): continue
66
+ code, path = line[:2].strip(), line[3:]
67
+ style = _CODE_STYLE.get(code[:1], "white")
68
+ t.add_row(f"[{style}]{code}[/{style}]", escape(path), _CODE_LABEL.get(code[:1], ""))
69
+ n += 1
70
+ return t, n
71
+
72
+ # %% ../nbs/01_Automate.ipynb #3a6f81d2-5c47-4e19-8b03-9d2a7f6c0e15
73
+ @call_parse
74
+ def prep(
75
+ p:int = 2, # Increment Part
76
+ ):
77
+ "Bump version part `p`, then export, test and clean the notebooks, refreshing _quarto.yml and README"
78
+
79
+ import nbdev.test, nbdev.clean, nbdev.quarto, nbdev.release
80
+ _banner("prep")
81
+ t0 = perf_counter()
82
+ with _step(1, 6, f"bump version (part {p})"):
83
+ nbdev.release.nbdev_bump_version(p)
84
+ with _step(2, 6, "nbdev_export"):
85
+ nbdev.quarto.nbdev_export.__wrapped__()
86
+ with _step(3, 6, "nbdev_test"):
87
+ nbdev.test.nbdev_test.__wrapped__(
88
+ n_workers = 8, # Number of workers
89
+ timing = True, # Time each notebook to see which are slow
90
+ )
91
+ with _step(4, 6, "nbdev_clean"):
92
+ nbdev.clean.nbdev_clean.__wrapped__()
93
+ with _step(5, 6, "refresh_quarto_yml"):
94
+ nbdev.quarto.refresh_quarto_yml()
95
+ with _step(6, 6, "nbdev_readme"):
96
+ nbdev.quarto.nbdev_readme.__wrapped__(chk_time=True)
97
+ _done("prep", t0)
98
+
99
+ # %% ../nbs/01_Automate.ipynb #f66ef35f-b7fa-4039-aa07-e9b782d204bb
100
+ @call_parse
101
+ def gacp(
102
+ m:str = '', # Commit message
103
+ ):
104
+ "git add, commit and push. Without `-m` the commit message is the status output"
105
+
106
+ import subprocess
107
+ _banner("gacp")
108
+ t0 = perf_counter()
109
+ with _step(1, 3, "git add"):
110
+ subprocess.run(["git", "add", "."])
111
+ status = subprocess.check_output(["git", "status", "-s"]).decode('utf-8')
112
+ if status.strip():
113
+ table, n = _status_table(status)
114
+ console.print(table)
115
+ console.print(f"[dim]{n} path{'' if n == 1 else 's'} staged[/dim]\n")
116
+ else:
117
+ console.print("[dim]nothing staged, the tree is clean[/dim]\n")
118
+
119
+ msg = m if m != '' else status
120
+ with _step(2, 3, "git commit"):
121
+ subprocess.run(["git", "commit", "-m", msg])
122
+ with _step(3, 3, "git push"):
123
+ subprocess.run(["git", "push"])
124
+ _done("gacp", t0)
125
+
126
+ # %% ../nbs/01_Automate.ipynb #88017a1b-55c1-4833-aeb6-277a7e5b6314
127
+ def status():
128
+ "Show the working tree state"
129
+ import subprocess
130
+
131
+ def _git(*a, **kw): return subprocess.check_output(["git", *a], **kw).decode('utf-8').strip()
132
+
133
+ _banner("status")
134
+ branch = _git("branch", "--show-current") or "DETACHED"
135
+ line = f"on [bold]{branch}[/bold]"
136
+ try:
137
+ behind, ahead = _git("rev-list", "--left-right", "--count", "@{upstream}...HEAD",
138
+ stderr=subprocess.DEVNULL).split()
139
+ if behind != "0": line += f" [yellow]behind {behind}[/yellow]"
140
+ if ahead != "0": line += f" [cyan]ahead {ahead}[/cyan]"
141
+ if behind == ahead == "0": line += " [dim]in step with upstream[/dim]"
142
+ except subprocess.CalledProcessError:
143
+ line += " [dim]no upstream[/dim]"
144
+ console.print(line)
145
+
146
+ # NOT via _git: `git status -s` pads the code to two columns, so stripping the
147
+ # output would eat the leading space of the first line and shift its path by one.
148
+ porcelain = subprocess.check_output(["git", "status", "-s"]).decode('utf-8')
149
+ if not porcelain:
150
+ console.print("[green]clean[/green]")
151
+ return
152
+ table, n = _status_table(porcelain)
153
+ console.print(table)
154
+ console.print(f"[dim]{n} path{'' if n == 1 else 's'} changed[/dim]")
155
+
156
+ # %% ../nbs/01_Automate.ipynb #8d777a41-0160-47f8-b51c-b14360b62da4
157
+ @call_parse
158
+ def upload(
159
+ m:str = '', # Commit message
160
+ p:int = 2, # Increment part
161
+ ):
162
+ "prep then gacp: the everyday command for shipping a notebook change"
163
+ prep(p)
164
+ gacp(m)
165
+
166
+ # %% ../nbs/01_Automate.ipynb #dee37b06-c946-4b40-be0f-056e133751ea
167
+ def release_git():
168
+ "Bump the MINOR version, then tag and create a GitHub release"
169
+ import nbdev.release
170
+ console.rule("[bold]gitrelease")
171
+ with _step("bump minor version"):
172
+ nbdev.release.nbdev_bump_version(1)
173
+ with _step("tag and create the GitHub release"):
174
+ nbdev.release.release_git()
175
+
176
+ # %% ../nbs/01_Automate.ipynb #288708c6-194a-4059-9ff0-ae330079c199
177
+ def release_pypi():
178
+ "Build the sdist and wheel, then upload to PyPI with twine. CI publishes on push, so this is the manual path"
179
+ import nbdev.release
180
+ console.rule("[bold]piprelease")
181
+ with _step("build and upload to PyPI"):
182
+ nbdev.release.release_pypi()
183
+
184
+ # %% ../nbs/01_Automate.ipynb #dd798178-9d58-457e-969a-d86a5e8bf875
185
+ def release():
186
+ "release_git then release_pypi"
187
+ release_git()
188
+ release_pypi()
189
+
190
+ # %% ../nbs/01_Automate.ipynb #c4d2bd52-04c4-43fe-890b-b4cb5da8d206
191
+ def help_output():
192
+ "Print every console script this package installs, with its help"
193
+ from importlib.metadata import distribution
194
+ try:
195
+ eps = [e for e in distribution("nbdevAuto").entry_points if e.group == "console_scripts"]
196
+ except Exception:
197
+ # Running from a source tree with nothing installed: fall back to fastcore.
198
+ from fastcore.xtras import console_help
199
+ return console_help('nbdevAuto')
200
+ _banner("commands")
201
+ t = Table(box=box.SIMPLE, show_header=False, pad_edge=False, expand=False)
202
+ t.add_column("command", style="bold cyan", no_wrap=True)
203
+ t.add_column("does", overflow="fold")
204
+ for e in sorted(eps, key=lambda e: e.name):
205
+ try: doc = escape((e.load().__doc__ or "").strip().splitlines()[0])
206
+ except Exception: doc = "[red]could not load[/red]"
207
+ t.add_row(e.name, doc)
208
+ console.print(t)
209
+ console.print(escape("ghstatus needs the gh extra: pip install 'nbdevAuto[gh]'"), style="dim")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nbdevAuto
3
- Version: 0.3.63
3
+ Version: 0.3.64
4
4
  Summary: automating nbdev
5
5
  Author-email: Benedict Thekkel <bthekkel1@gmail.com>
6
6
  License-Expression: Apache-2.0
@@ -23,6 +23,7 @@ Description-Content-Type: text/markdown
23
23
  License-File: LICENSE
24
24
  Requires-Dist: graphviz
25
25
  Requires-Dist: fastcore
26
+ Requires-Dist: rich
26
27
  Provides-Extra: gh
27
28
  Requires-Dist: githubkit>=0.12; extra == "gh"
28
29
  Dynamic: license-file
@@ -1,5 +1,6 @@
1
1
  graphviz
2
2
  fastcore
3
+ rich
3
4
 
4
5
  [gh]
5
6
  githubkit>=0.12
@@ -24,7 +24,7 @@ classifiers = [
24
24
  "Programming Language :: Python :: 3.13",
25
25
  "Programming Language :: Python :: 3.14",
26
26
  ]
27
- dependencies = ['graphviz', 'fastcore']
27
+ dependencies = ['graphviz', 'fastcore', 'rich']
28
28
 
29
29
  [project.optional-dependencies]
30
30
  # An extra, not a dependency: githubkit pulls pydantic + httpx + hishel, which is
@@ -1 +0,0 @@
1
- __version__ = "0.3.63"
@@ -1,97 +0,0 @@
1
- """Automate
2
-
3
- Docs: https://bthek1.github.io/nbdevAuto/automate.html.md"""
4
-
5
- # AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/01_Automate.ipynb.
6
-
7
- # %% auto #0
8
- __all__ = ['prep', 'gacp', 'status', 'upload', 'release_git', 'release_pypi', 'release', 'help_output']
9
-
10
- # %% ../nbs/01_Automate.ipynb #6d1499d1-aa55-47d8-92fd-fa056b1fb135
11
- from fastcore.script import *
12
-
13
- @call_parse
14
- def prep(
15
- p:int = 2, # Increment Part
16
- ):
17
- "Bump version part `p`, then export, test and clean the notebooks, refreshing _quarto.yml and README"
18
-
19
- import nbdev.test, nbdev.clean, nbdev.quarto, nbdev.release
20
- nbdev.release.nbdev_bump_version(p)
21
-
22
- nbdev.quarto.nbdev_export.__wrapped__()
23
- print(f'### nbdev_export finished ###')
24
- nbdev.test.nbdev_test.__wrapped__(
25
- n_workers = 8, # Number of workers
26
- timing = True, # Time each notebook to see which are slow
27
- )
28
- print(f'### nbdev_test finished ###')
29
- nbdev.clean.nbdev_clean.__wrapped__()
30
- print(f'### nbdev_clean finished ###')
31
- nbdev.quarto.refresh_quarto_yml()
32
- print(f'### refresh_quarto_yml finished ###')
33
- nbdev.quarto.nbdev_readme.__wrapped__(chk_time=True)
34
- print(f'### nbdev_readme finished ###')
35
-
36
- # %% ../nbs/01_Automate.ipynb #f66ef35f-b7fa-4039-aa07-e9b782d204bb
37
- @call_parse
38
- def gacp(
39
- m:str = '', # Commit message
40
- ):
41
- "git add, commit and push. Without `-m` the commit message is the status output"
42
-
43
- import subprocess
44
- subprocess.run(["git", "add", "."])
45
- print(f'### git added ###')
46
- status = subprocess.check_output(["git", "status", "-s"]).decode('utf-8')
47
- print(f'### git status: "{status}" ###')
48
-
49
- if m != '':
50
- subprocess.run(["git", "commit", "-m", f'{m}'])
51
- print(f'### git commited "{m}"###')
52
- else:
53
- subprocess.run(["git", "commit", "-m", f'{status}'])
54
- print(f'### git commited status ###')
55
- subprocess.run(["git", "push"])
56
- print(f'### git pushed ###')
57
-
58
- # %% ../nbs/01_Automate.ipynb #88017a1b-55c1-4833-aeb6-277a7e5b6314
59
- def status():
60
- "Show the working tree state"
61
- import subprocess
62
- subprocess.run(["git", "status"])
63
-
64
- # %% ../nbs/01_Automate.ipynb #8d777a41-0160-47f8-b51c-b14360b62da4
65
- @call_parse
66
- def upload(
67
- m:str = '', # Commit message
68
- p:int = 2, #Increment part
69
- ):
70
- "prep then gacp: the everyday command for shipping a notebook change"
71
- prep(p)
72
- gacp(m)
73
-
74
- # %% ../nbs/01_Automate.ipynb #dee37b06-c946-4b40-be0f-056e133751ea
75
- def release_git():
76
- "Bump the MINOR version, then tag and create a GitHub release"
77
- import nbdev.release
78
- nbdev.release.nbdev_bump_version(1)
79
- nbdev.release.release_git()
80
-
81
- # %% ../nbs/01_Automate.ipynb #288708c6-194a-4059-9ff0-ae330079c199
82
- def release_pypi():
83
- "Build the sdist and wheel, then upload to PyPI with twine. CI publishes on push, so this is the manual path"
84
- import nbdev.release
85
- nbdev.release.release_pypi()
86
-
87
- # %% ../nbs/01_Automate.ipynb #dd798178-9d58-457e-969a-d86a5e8bf875
88
- def release():
89
- "release_git then release_pypi"
90
- release_git()
91
- release_pypi()
92
-
93
- # %% ../nbs/01_Automate.ipynb #c4d2bd52-04c4-43fe-890b-b4cb5da8d206
94
- def help_output():
95
- "Print every console script this package installs, with its help"
96
- from fastcore.xtras import console_help
97
- console_help('nbdevAuto')
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes