pnbp 0.9.0rc1__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.
- pnbp-0.9.0rc1/LICENSE +22 -0
- pnbp-0.9.0rc1/PKG-INFO +108 -0
- pnbp-0.9.0rc1/README.md +19 -0
- pnbp-0.9.0rc1/docs/pnbp.md +87 -0
- pnbp-0.9.0rc1/pyproject.toml +58 -0
- pnbp-0.9.0rc1/setup.cfg +4 -0
- pnbp-0.9.0rc1/src/pnbp/__init__.py +1 -0
- pnbp-0.9.0rc1/src/pnbp/cli.py +251 -0
- pnbp-0.9.0rc1/src/pnbp/commands/__init__.py +0 -0
- pnbp-0.9.0rc1/src/pnbp/commands/code.py +173 -0
- pnbp-0.9.0rc1/src/pnbp/commands/collect.py +249 -0
- pnbp-0.9.0rc1/src/pnbp/commands/commit.py +286 -0
- pnbp-0.9.0rc1/src/pnbp/commands/correct.py +234 -0
- pnbp-0.9.0rc1/src/pnbp/commands/graph.py +189 -0
- pnbp-0.9.0rc1/src/pnbp/commands/pprint.py +81 -0
- pnbp-0.9.0rc1/src/pnbp/commands/subl.py +75 -0
- pnbp-0.9.0rc1/src/pnbp/commands/tasks.py +323 -0
- pnbp-0.9.0rc1/src/pnbp/helpers/__init__.py +2 -0
- pnbp-0.9.0rc1/src/pnbp/helpers/_datetime.py +26 -0
- pnbp-0.9.0rc1/src/pnbp/helpers/wrappers.py +77 -0
- pnbp-0.9.0rc1/src/pnbp/models/__init__.py +4 -0
- pnbp-0.9.0rc1/src/pnbp/models/components/__init__.py +13 -0
- pnbp-0.9.0rc1/src/pnbp/models/components/codeblock.py +123 -0
- pnbp-0.9.0rc1/src/pnbp/models/components/component.py +79 -0
- pnbp-0.9.0rc1/src/pnbp/models/components/link.py +247 -0
- pnbp-0.9.0rc1/src/pnbp/models/components/tag.py +72 -0
- pnbp-0.9.0rc1/src/pnbp/models/components/url.py +104 -0
- pnbp-0.9.0rc1/src/pnbp/models/note.py +495 -0
- pnbp-0.9.0rc1/src/pnbp/models/notebook.py +1067 -0
- pnbp-0.9.0rc1/src/pnbp.egg-info/PKG-INFO +108 -0
- pnbp-0.9.0rc1/src/pnbp.egg-info/SOURCES.txt +50 -0
- pnbp-0.9.0rc1/src/pnbp.egg-info/dependency_links.txt +1 -0
- pnbp-0.9.0rc1/src/pnbp.egg-info/entry_points.txt +2 -0
- pnbp-0.9.0rc1/src/pnbp.egg-info/requires.txt +4 -0
- pnbp-0.9.0rc1/src/pnbp.egg-info/top_level.txt +1 -0
- pnbp-0.9.0rc1/tests/test_cleanup_contracts.py +108 -0
- pnbp-0.9.0rc1/tests/test_cli_collections.py +64 -0
- pnbp-0.9.0rc1/tests/test_code_extraction.py +173 -0
- pnbp-0.9.0rc1/tests/test_component_semantics.py +62 -0
- pnbp-0.9.0rc1/tests/test_config_contracts.py +97 -0
- pnbp-0.9.0rc1/tests/test_empty_sections.py +44 -0
- pnbp-0.9.0rc1/tests/test_git_automation.py +151 -0
- pnbp-0.9.0rc1/tests/test_lookup.py +63 -0
- pnbp-0.9.0rc1/tests/test_note_io.py +155 -0
- pnbp-0.9.0rc1/tests/test_note_state.py +95 -0
- pnbp-0.9.0rc1/tests/test_protected_text.py +118 -0
- pnbp-0.9.0rc1/tests/test_publication_eligibility.py +93 -0
- pnbp-0.9.0rc1/tests/test_publication_preflight.py +144 -0
- pnbp-0.9.0rc1/tests/test_publication_sync.py +325 -0
- pnbp-0.9.0rc1/tests/test_rendering.py +94 -0
- pnbp-0.9.0rc1/tests/test_smoke.py +28 -0
- pnbp-0.9.0rc1/tests/test_tasks.py +143 -0
pnbp-0.9.0rc1/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 prettynb
|
|
4
|
+
Copyright (c) 2026 Outside Labs
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
pnbp-0.9.0rc1/PKG-INFO
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pnbp
|
|
3
|
+
Version: 0.9.0rc1
|
|
4
|
+
Summary: Python tools for parsing and querying wiki-linked, tagged Markdown notebooks.
|
|
5
|
+
Author: prettynb
|
|
6
|
+
Maintainer: Outside Labs
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
Project-URL: Homepage, https://outside-labs.com
|
|
9
|
+
Project-URL: Repository, https://github.com/outside-labs/pretty-notebook
|
|
10
|
+
Project-URL: Documentation, https://github.com/outside-labs/pretty-notebook/tree/main/docs
|
|
11
|
+
Project-URL: Issues, https://github.com/outside-labs/pretty-notebook/issues
|
|
12
|
+
Keywords: markdown,notes,wikilinks,knowledge-management
|
|
13
|
+
Requires-Python: >=3.11
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
License-File: LICENSE
|
|
16
|
+
Requires-Dist: click>=8.0
|
|
17
|
+
Requires-Dist: markdown>=3.3.4
|
|
18
|
+
Requires-Dist: requests>=2.26
|
|
19
|
+
Requires-Dist: rich>=10.6
|
|
20
|
+
Dynamic: license-file
|
|
21
|
+
|
|
22
|
+
pnbp = **"pretty notebook parser"**
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
**pnbp** provides programmatic access to a **notebook** via :
|
|
27
|
+
- **[> pnbp/models](https://github.com/outside-labs/Pretty-Notebook/blob/main/docs/pnbp_models.md)** : **models and methods**.
|
|
28
|
+
- access notes and their individual (regex established) components in the python repl, scripts, and your own shell commands.
|
|
29
|
+
- **[> pnbp/commands](https://github.com/outside-labs/Pretty-Notebook/blob/main/docs/pnbp_commands.md)** : **shell commands**.
|
|
30
|
+
- run pre-defined function against a notebook in the terminal directly, or, scheduled.
|
|
31
|
+
|
|
32
|
+
\---
|
|
33
|
+
|
|
34
|
+
a pretty **notebook** is the collection of markdown files in a specific directory.
|
|
35
|
+
a pretty **note** is a single .md file within the notebook directory.
|
|
36
|
+
|
|
37
|
+
**links** ( \[\[link\]\] , !\[\[link.jpg\]\] ), **tags** ( \#tag ), **codeblocks** ( \`\`\`py print("Hello World")\`\`\` ), and **urls** ( \[goog\]\(https://google.com) ) are the main components outside of additional [render syntax](https://daringfireball.net/projects/markdown/syntax) of a .md note using an extended linking and tagging markdown.
|
|
38
|
+
|
|
39
|
+
https://obsidian.md/ is the best example of this in action.
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
#### quickstart guide :
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
##### (0) -> ```pip install pnbp```
|
|
48
|
+
|
|
49
|
+
##### (1) -> [access via the Notebook model](https://github.com/outside-labs/Pretty-Notebook/blob/main/docs/pnbp_models.md)
|
|
50
|
+
|
|
51
|
+
##### (2) -> [cli commands](https://github.com/outside-labs/Pretty-Notebook/blob/main/docs/pnbp_commands.md)
|
|
52
|
+
|
|
53
|
+
##### (3) -> [web application / api](https://github.com/outside-labs/Pretty-Notebook/blob/main/docs/web.md) *(experimental; not supported for public deployment in 0.9.0rc1)*
|
|
54
|
+
|
|
55
|
+
##### (4) -> [“pnano”](https://github.com/outside-labs/Pretty-Notebook/blob/main/docs/pnano.md) *(experimental/unsupported in 0.9.0rc1)*
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
##### (-1) -> **git clone** the repo.
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
pip uninstall pnbp
|
|
63
|
+
git clone https://github.com/outside-labs/Pretty-Notebook/ pnbp
|
|
64
|
+
cd pnbp/
|
|
65
|
+
pip install . # pyproject.toml defined requirements
|
|
66
|
+
pip install --editable . # pnbp/cli.py defined “pnbp command”s
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
---
|
|
70
|
+
|
|
71
|
+
##### (2) -> set **environment variables**.
|
|
72
|
+
|
|
73
|
+
| var | desc | e.g. |
|
|
74
|
+
| :--: | :--: | :--: |
|
|
75
|
+
| **NOTE_PATH** | the full directory path of your notebook | ```echo 'export NOTE_PATH="/users/alice/notebook"' >> ~/.zshrc``` |
|
|
76
|
+
| **IMG_PATH** | (optional entirely; set here or in pnbp_settings.json) | ```echo 'export IMG_PATH="$NOTE_PATH/imgs"' >> ~/.zshrc``` |
|
|
77
|
+
| **HTML_PATH** | (optional entirely; useful debug w/ Pretty-Notebook/apps/web api; set here, in pnbp_settings.json, or not at all.) | ```echo 'export HTML_PATH="$NOTE_PATH/html"' >> ~/.zshrc``` |
|
|
78
|
+
| **NOTE_NESTED** | (optional; default=*"flat"*) => *"single"*, *"recurs"*, *"all"*, | ... |
|
|
79
|
+
| **PNBP_SETTINGS** | (optional) => **"off"** to ignore using a NOTE_PATH/pnbp_settings.json | ```echo 'export PNBP_SETTINGS="off"' >> ~/.zshrc``` |
|
|
80
|
+
|
|
81
|
+
**NOTE_NESTED**
|
|
82
|
+
- *"flat"* - by default, **pnbp** assumes that every .md note exist within the base directory level of **NOTE\_PATH**/.
|
|
83
|
+
- *"single"* - if you want **pnbp** to search for .md notes within additional (non-hidden) directory level up.
|
|
84
|
+
- *"recurs"* - if you want .md notes to be found through all (non-hidden) directory levels up.
|
|
85
|
+
- *"all"* - if you want even hidden (non- .git, .obsidian) directories traversed recursively up.
|
|
86
|
+
|
|
87
|
+
**PNBP_SETTINGS**
|
|
88
|
+
- without ```PNBP_SETTINGS="off"```, "**NOTE\_PATH/pnbp_settings.json**" will be nagged for.
|
|
89
|
+
- **Notebook** can generate one at the python prompt that you can edit later ->
|
|
90
|
+
|
|
91
|
+
( ... on **Windows**? Environment Variable(s) can be set [here](https://docs.oracle.com/en/database/oracle/machine-learning/oml4r/1.5.1/oread/creating-and-modifying-environment-variables-on-windows.html#GUID-DD6F9982-60D5-48F6-8270-A27EC53807D0). Also, recall that in most places you'll also need to escape the "```\```" within any **path** strings (e.g. ```"IMG_PATH": "\\Users\\alice\\notebook\\imgs"```) used; the drive letter (e.g. ```"D:\\Media\imgs"```) is optional if it's your **\%HOMEDRIVE\%**. )
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
##### (3) -> **access your notes in python3.11+ !**
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
```py
|
|
99
|
+
>>> import pnbp
|
|
100
|
+
>>> nb = pnbp.Notebook()
|
|
101
|
+
...
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
<p align=center>
|
|
107
|
+
<img src=https://raw.githubusercontent.com/outside-labs/Pretty-Notebook/main/docs/IMG_pnbp.png alt=Pretty-Notebook width=200>
|
|
108
|
+
</p>
|
pnbp-0.9.0rc1/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Pretty-Notebook
|
|
2
|
+
|
|
3
|
+
A Python toolkit and FastAPI publisher for interconnected Markdown notebooks.
|
|
4
|
+
|
|
5
|
+
[Documentation](https://github.com/outside-labs/Pretty-Notebook/blob/main/docs/pnbp.md)
|
|
6
|
+
|
|
7
|
+
```mermaid
|
|
8
|
+
graph BT
|
|
9
|
+
id1[(Notebook)]
|
|
10
|
+
id2[(Note)] --> id1
|
|
11
|
+
Link --> id2
|
|
12
|
+
Url --> id2
|
|
13
|
+
CodeBlock --> id2
|
|
14
|
+
Tag --> id2
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
<p align=center>
|
|
18
|
+
<img src=https://raw.githubusercontent.com/outside-labs/Pretty-Notebook/main/docs/IMG_pnbp.png alt=Pretty-Notebook width=200>
|
|
19
|
+
</p>
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
pnbp = **"pretty notebook parser"**
|
|
2
|
+
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
**pnbp** provides programmatic access to a **notebook** via :
|
|
6
|
+
- **[> pnbp/models](https://github.com/outside-labs/Pretty-Notebook/blob/main/docs/pnbp_models.md)** : **models and methods**.
|
|
7
|
+
- access notes and their individual (regex established) components in the python repl, scripts, and your own shell commands.
|
|
8
|
+
- **[> pnbp/commands](https://github.com/outside-labs/Pretty-Notebook/blob/main/docs/pnbp_commands.md)** : **shell commands**.
|
|
9
|
+
- run pre-defined function against a notebook in the terminal directly, or, scheduled.
|
|
10
|
+
|
|
11
|
+
\---
|
|
12
|
+
|
|
13
|
+
a pretty **notebook** is the collection of markdown files in a specific directory.
|
|
14
|
+
a pretty **note** is a single .md file within the notebook directory.
|
|
15
|
+
|
|
16
|
+
**links** ( \[\[link\]\] , !\[\[link.jpg\]\] ), **tags** ( \#tag ), **codeblocks** ( \`\`\`py print("Hello World")\`\`\` ), and **urls** ( \[goog\]\(https://google.com) ) are the main components outside of additional [render syntax](https://daringfireball.net/projects/markdown/syntax) of a .md note using an extended linking and tagging markdown.
|
|
17
|
+
|
|
18
|
+
https://obsidian.md/ is the best example of this in action.
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
#### quickstart guide :
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
##### (0) -> ```pip install pnbp```
|
|
27
|
+
|
|
28
|
+
##### (1) -> [access via the Notebook model](https://github.com/outside-labs/Pretty-Notebook/blob/main/docs/pnbp_models.md)
|
|
29
|
+
|
|
30
|
+
##### (2) -> [cli commands](https://github.com/outside-labs/Pretty-Notebook/blob/main/docs/pnbp_commands.md)
|
|
31
|
+
|
|
32
|
+
##### (3) -> [web application / api](https://github.com/outside-labs/Pretty-Notebook/blob/main/docs/web.md) *(experimental; not supported for public deployment in 0.9.0rc1)*
|
|
33
|
+
|
|
34
|
+
##### (4) -> [“pnano”](https://github.com/outside-labs/Pretty-Notebook/blob/main/docs/pnano.md) *(experimental/unsupported in 0.9.0rc1)*
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
##### (-1) -> **git clone** the repo.
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
pip uninstall pnbp
|
|
42
|
+
git clone https://github.com/outside-labs/Pretty-Notebook/ pnbp
|
|
43
|
+
cd pnbp/
|
|
44
|
+
pip install . # pyproject.toml defined requirements
|
|
45
|
+
pip install --editable . # pnbp/cli.py defined “pnbp command”s
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
##### (2) -> set **environment variables**.
|
|
51
|
+
|
|
52
|
+
| var | desc | e.g. |
|
|
53
|
+
| :--: | :--: | :--: |
|
|
54
|
+
| **NOTE_PATH** | the full directory path of your notebook | ```echo 'export NOTE_PATH="/users/alice/notebook"' >> ~/.zshrc``` |
|
|
55
|
+
| **IMG_PATH** | (optional entirely; set here or in pnbp_settings.json) | ```echo 'export IMG_PATH="$NOTE_PATH/imgs"' >> ~/.zshrc``` |
|
|
56
|
+
| **HTML_PATH** | (optional entirely; useful debug w/ Pretty-Notebook/apps/web api; set here, in pnbp_settings.json, or not at all.) | ```echo 'export HTML_PATH="$NOTE_PATH/html"' >> ~/.zshrc``` |
|
|
57
|
+
| **NOTE_NESTED** | (optional; default=*"flat"*) => *"single"*, *"recurs"*, *"all"*, | ... |
|
|
58
|
+
| **PNBP_SETTINGS** | (optional) => **"off"** to ignore using a NOTE_PATH/pnbp_settings.json | ```echo 'export PNBP_SETTINGS="off"' >> ~/.zshrc``` |
|
|
59
|
+
|
|
60
|
+
**NOTE_NESTED**
|
|
61
|
+
- *"flat"* - by default, **pnbp** assumes that every .md note exist within the base directory level of **NOTE\_PATH**/.
|
|
62
|
+
- *"single"* - if you want **pnbp** to search for .md notes within additional (non-hidden) directory level up.
|
|
63
|
+
- *"recurs"* - if you want .md notes to be found through all (non-hidden) directory levels up.
|
|
64
|
+
- *"all"* - if you want even hidden (non- .git, .obsidian) directories traversed recursively up.
|
|
65
|
+
|
|
66
|
+
**PNBP_SETTINGS**
|
|
67
|
+
- without ```PNBP_SETTINGS="off"```, "**NOTE\_PATH/pnbp_settings.json**" will be nagged for.
|
|
68
|
+
- **Notebook** can generate one at the python prompt that you can edit later ->
|
|
69
|
+
|
|
70
|
+
( ... on **Windows**? Environment Variable(s) can be set [here](https://docs.oracle.com/en/database/oracle/machine-learning/oml4r/1.5.1/oread/creating-and-modifying-environment-variables-on-windows.html#GUID-DD6F9982-60D5-48F6-8270-A27EC53807D0). Also, recall that in most places you'll also need to escape the "```\```" within any **path** strings (e.g. ```"IMG_PATH": "\\Users\\alice\\notebook\\imgs"```) used; the drive letter (e.g. ```"D:\\Media\imgs"```) is optional if it's your **\%HOMEDRIVE\%**. )
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
##### (3) -> **access your notes in python3.11+ !**
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
```py
|
|
78
|
+
>>> import pnbp
|
|
79
|
+
>>> nb = pnbp.Notebook()
|
|
80
|
+
...
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
<p align=center>
|
|
86
|
+
<img src=https://raw.githubusercontent.com/outside-labs/Pretty-Notebook/main/docs/IMG_pnbp.png alt=Pretty-Notebook width=200>
|
|
87
|
+
</p>
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77.0.3"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "pnbp"
|
|
7
|
+
version = "0.9.0rc1"
|
|
8
|
+
description = "Python tools for parsing and querying wiki-linked, tagged Markdown notebooks."
|
|
9
|
+
readme = "docs/pnbp.md"
|
|
10
|
+
requires-python = ">=3.11"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
|
|
14
|
+
authors = [
|
|
15
|
+
{ name = "prettynb" },
|
|
16
|
+
]
|
|
17
|
+
maintainers = [
|
|
18
|
+
{ name = "Outside Labs" },
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
keywords = [
|
|
22
|
+
"markdown",
|
|
23
|
+
"notes",
|
|
24
|
+
"wikilinks",
|
|
25
|
+
"knowledge-management",
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
dependencies = [
|
|
29
|
+
"click>=8.0",
|
|
30
|
+
"markdown>=3.3.4",
|
|
31
|
+
"requests>=2.26",
|
|
32
|
+
"rich>=10.6",
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
[project.urls]
|
|
36
|
+
Homepage = "https://outside-labs.com"
|
|
37
|
+
Repository = "https://github.com/outside-labs/pretty-notebook"
|
|
38
|
+
Documentation = "https://github.com/outside-labs/pretty-notebook/tree/main/docs"
|
|
39
|
+
Issues = "https://github.com/outside-labs/pretty-notebook/issues"
|
|
40
|
+
|
|
41
|
+
[project.scripts]
|
|
42
|
+
pnbp = "pnbp.cli:cli"
|
|
43
|
+
|
|
44
|
+
[tool.setuptools]
|
|
45
|
+
package-dir = { "" = "src" }
|
|
46
|
+
|
|
47
|
+
[tool.setuptools.packages.find]
|
|
48
|
+
where = ["src"]
|
|
49
|
+
include = ["pnbp*"]
|
|
50
|
+
namespaces = false
|
|
51
|
+
|
|
52
|
+
[tool.pytest.ini_options]
|
|
53
|
+
addopts = ["-ra", "--strict-config", "--strict-markers"]
|
|
54
|
+
testpaths = ["tests"]
|
|
55
|
+
filterwarnings = [
|
|
56
|
+
"error",
|
|
57
|
+
"ignore:'crypt' is deprecated and slated for removal in Python 3.13:DeprecationWarning:passlib\\.utils",
|
|
58
|
+
]
|
pnbp-0.9.0rc1/setup.cfg
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .models import Notebook
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import subprocess
|
|
3
|
+
import sys
|
|
4
|
+
import inspect
|
|
5
|
+
|
|
6
|
+
import click
|
|
7
|
+
import requests
|
|
8
|
+
|
|
9
|
+
from .commands import collect
|
|
10
|
+
from .commands import commit
|
|
11
|
+
from .commands import correct
|
|
12
|
+
from .commands import code
|
|
13
|
+
from .commands import graph
|
|
14
|
+
from .commands import pprint
|
|
15
|
+
from .commands import subl
|
|
16
|
+
from .commands import tasks
|
|
17
|
+
|
|
18
|
+
from .models import Notebook
|
|
19
|
+
from .helpers import arrow_call
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@click.group()
|
|
24
|
+
def cli():
|
|
25
|
+
pass
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
""" Pretty-Notebook/apps/web api connection commands:
|
|
30
|
+
"""
|
|
31
|
+
def _publish_notebook(notebook, **kwargs):
|
|
32
|
+
"""Run publication with concise CLI reporting for transport failures."""
|
|
33
|
+
try:
|
|
34
|
+
return notebook.post_commits_to_web_api(**kwargs)
|
|
35
|
+
except requests.RequestException as error:
|
|
36
|
+
raise click.ClickException(f'Publication failed: {error}') from error
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
@cli.command()
|
|
40
|
+
def commit_html():
|
|
41
|
+
""" if note contains #public, -> HTML_PATH/.html
|
|
42
|
+
(for local debugging when running remote server
|
|
43
|
+
and not a concurrent localhost instance...)
|
|
44
|
+
"""
|
|
45
|
+
# ^^ docstring == help message
|
|
46
|
+
nb = Notebook()
|
|
47
|
+
nb.write_commits_to_local_html()
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
@cli.command()
|
|
51
|
+
@click.option(
|
|
52
|
+
'--prune',
|
|
53
|
+
is_flag=True,
|
|
54
|
+
help='Remove every remote page absent from this notebook after successful uploads.',
|
|
55
|
+
)
|
|
56
|
+
@click.option(
|
|
57
|
+
'--refresh-images',
|
|
58
|
+
is_flag=True,
|
|
59
|
+
help='Resend referenced images even when their names already exist remotely.',
|
|
60
|
+
)
|
|
61
|
+
def commit_remote(prune, refresh_images):
|
|
62
|
+
""" if note contains #public, ->
|
|
63
|
+
selective update POST to .../apps/web api
|
|
64
|
+
@ {API_BASE}/api/publishment
|
|
65
|
+
"""
|
|
66
|
+
nb = Notebook()
|
|
67
|
+
_publish_notebook(nb, prune=prune, refresh_images=refresh_images)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
@cli.command()
|
|
71
|
+
@click.option(
|
|
72
|
+
'--prune',
|
|
73
|
+
is_flag=True,
|
|
74
|
+
help='Remove every remote page absent from this notebook after successful uploads.',
|
|
75
|
+
)
|
|
76
|
+
@click.option(
|
|
77
|
+
'--refresh-images',
|
|
78
|
+
is_flag=True,
|
|
79
|
+
help='Resend referenced images even when their names already exist remotely.',
|
|
80
|
+
)
|
|
81
|
+
def commit_local(prune, refresh_images):
|
|
82
|
+
""" commit -> localhost .../apps/web instance
|
|
83
|
+
""" # a convenience command
|
|
84
|
+
nb = Notebook()
|
|
85
|
+
nb.API_BASE = 'http://127.0.0.1:8000'
|
|
86
|
+
_publish_notebook(nb, prune=prune, refresh_images=refresh_images)
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
@cli.command()
|
|
90
|
+
def commit_stage():
|
|
91
|
+
""" *only* print commit- changes against nb.API_BASE
|
|
92
|
+
to the terminal (staging view)
|
|
93
|
+
"""
|
|
94
|
+
nb = Notebook()
|
|
95
|
+
_publish_notebook(nb, stage_only=True)
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
@cli.command()
|
|
99
|
+
@click.option('--local', is_flag=True, default=False, help="post to localhost instead of the configured API_BASE")
|
|
100
|
+
def commit_settings(local):
|
|
101
|
+
""" commit nb.NOTE_PATH/pnbp_settings.json -> the Pretty-Notebook/apps/web api .../web_settings.json
|
|
102
|
+
"""
|
|
103
|
+
nb = Notebook()
|
|
104
|
+
|
|
105
|
+
if local:
|
|
106
|
+
nb.API_BASE = 'http://127.0.0.1:8000'
|
|
107
|
+
|
|
108
|
+
nb.web_settings_post()
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
@cli.command()
|
|
112
|
+
def git_clone_pnbp_web():
|
|
113
|
+
""" command to clone from github to ./pnbp_web/
|
|
114
|
+
"""
|
|
115
|
+
cmd = ["git", "clone", "--filter=blob:none",
|
|
116
|
+
"--sparse", "--depth", "1", "--single-branch",
|
|
117
|
+
"--branch", "main", "https://github.com/outside-labs/Pretty-Notebook.git",
|
|
118
|
+
"pnbp-web"]
|
|
119
|
+
|
|
120
|
+
cmd2 = ["git", "-C", "pnbp-web", "sparse-checkout", "set", "apps/web"]
|
|
121
|
+
|
|
122
|
+
op = subprocess.run(cmd,capture_output=True)
|
|
123
|
+
|
|
124
|
+
click.echo(op.stderr) # git outputs stdout to stderr
|
|
125
|
+
|
|
126
|
+
wp = subprocess.run(cmd2, capture_output=True)
|
|
127
|
+
|
|
128
|
+
click.echo(wp.stderr)
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
""" building click.commands out of
|
|
133
|
+
the (imported above) local /commands/ package
|
|
134
|
+
"""
|
|
135
|
+
def _create_command(func):
|
|
136
|
+
""" effectively writes a :
|
|
137
|
+
|
|
138
|
+
```@click.command()
|
|
139
|
+
def outer_act_cmd():
|
|
140
|
+
_outer_act_cmd()
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
where I had issues passing live parameters
|
|
144
|
+
and chaining command calls in click otherwise.
|
|
145
|
+
|
|
146
|
+
As actively wrapping here (vs calling _outer_act_cmd()),
|
|
147
|
+
has the nice feature of passing the _cmd's docstring to the --help info.
|
|
148
|
+
|
|
149
|
+
:param func:
|
|
150
|
+
"""
|
|
151
|
+
func.__name__ = func.__name__.lstrip('_')
|
|
152
|
+
|
|
153
|
+
cmd = cli.command()
|
|
154
|
+
|
|
155
|
+
if 'note' in inspect.signature(func).parameters.keys():
|
|
156
|
+
# prove it :
|
|
157
|
+
func = click.option(
|
|
158
|
+
'--fuzzy',
|
|
159
|
+
is_flag=True,
|
|
160
|
+
help='explicitly accept the closest matching note name',
|
|
161
|
+
)(func)
|
|
162
|
+
func = click.option('-n', '--note', type=str, help='the name of a note', required=True)(func)
|
|
163
|
+
|
|
164
|
+
func = arrow_call(func)
|
|
165
|
+
|
|
166
|
+
return cmd(func)
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
def create_command(func):
|
|
170
|
+
""" actually instantiating the command
|
|
171
|
+
and specifically setattr-ing here after built is necessary
|
|
172
|
+
|
|
173
|
+
:param func:
|
|
174
|
+
"""
|
|
175
|
+
c = _create_command(func)
|
|
176
|
+
setattr(sys.modules[__name__], func.__name__.lstrip('_'), c)
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
def create_commands(module, _all=False):
|
|
180
|
+
"""
|
|
181
|
+
|
|
182
|
+
:param module: an commands/module.py imported above
|
|
183
|
+
:param _all: _all=True will create a command from all leading underscore _func_name of module
|
|
184
|
+
"""
|
|
185
|
+
for k,v in module.__dict__.items():
|
|
186
|
+
# print(k) # _func's name...
|
|
187
|
+
if _all:
|
|
188
|
+
if (inspect.isfunction(v)
|
|
189
|
+
and k.startswith('_')
|
|
190
|
+
and v.__module__ == module.__name__): # ignore if imported
|
|
191
|
+
create_command(v)
|
|
192
|
+
else:
|
|
193
|
+
# leave open for additional bool switches
|
|
194
|
+
pass
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
def create_all_commands():
|
|
199
|
+
""" main function for building imported module commands
|
|
200
|
+
and tacking them onto the click.group(), & module local() name cli
|
|
201
|
+
|
|
202
|
+
"""
|
|
203
|
+
create_commands(collect, _all=True)
|
|
204
|
+
|
|
205
|
+
# Imported collection helpers are excluded by create_commands() so that
|
|
206
|
+
# module scans do not accidentally register unrelated imports. Register the
|
|
207
|
+
# five intended collection commands explicitly.
|
|
208
|
+
create_command(collect._collect_code_blocked)
|
|
209
|
+
create_command(collect._collect_tasks_note)
|
|
210
|
+
create_command(collect._collect_public_graph)
|
|
211
|
+
create_command(collect._collect_all_graphs)
|
|
212
|
+
create_command(collect._collect_subl_projs)
|
|
213
|
+
|
|
214
|
+
create_commands(commit, _all=True)
|
|
215
|
+
|
|
216
|
+
create_commands(correct, _all=True)
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
create_command(code._extract_code_blocks)
|
|
220
|
+
create_command(code._extract_all_code_blocks)
|
|
221
|
+
|
|
222
|
+
create_command(graph._create_link_graph)
|
|
223
|
+
create_command(graph._create_tag_graph)
|
|
224
|
+
create_command(graph._delete_all_graph_dash_name)
|
|
225
|
+
|
|
226
|
+
create_command(pprint._pprint)
|
|
227
|
+
|
|
228
|
+
create_command(subl._subl_init)
|
|
229
|
+
|
|
230
|
+
create_command(tasks._task_settle)
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
# -> required to call here (pre-main) for pyproject.toml /
|
|
244
|
+
# pip install to recognize dynamically created commands
|
|
245
|
+
create_all_commands()
|
|
246
|
+
|
|
247
|
+
if __name__ == '__main__':
|
|
248
|
+
cli()
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
|
|
File without changes
|