mdforge 0.1.0__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.
mdforge-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 mm21
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
mdforge-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,29 @@
1
+ Metadata-Version: 2.1
2
+ Name: mdforge
3
+ Version: 0.1.0
4
+ Summary: Synthesize Markdown files in a Pythonic way
5
+ Home-page: https://github.com/mm21/mdforge
6
+ Author: mm21
7
+ Author-email: mm21.dev@gmail.com
8
+ Requires-Python: >=3.12,<4.0
9
+ Classifier: Development Status :: 2 - Pre-Alpha
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Natural Language :: English
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Programming Language :: Python :: Implementation :: CPython
16
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
17
+ Classifier: Typing :: Typed
18
+ Requires-Dist: pyrollup (>=0.1.0,<0.2.0)
19
+ Description-Content-Type: text/markdown
20
+
21
+ # MDForge
22
+
23
+ Synthesize Markdown files in a Pythonic way.
24
+
25
+ [![PyPI](https://img.shields.io/pypi/v/mdforge?color=%2334D058&label=pypi%20package)](https://pypi.org/project/mdforge)
26
+ [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
27
+
28
+ Work in progress.
29
+
@@ -0,0 +1,8 @@
1
+ # MDForge
2
+
3
+ Synthesize Markdown files in a Pythonic way.
4
+
5
+ [![PyPI](https://img.shields.io/pypi/v/mdforge?color=%2334D058&label=pypi%20package)](https://pypi.org/project/mdforge)
6
+ [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
7
+
8
+ Work in progress.
@@ -0,0 +1,13 @@
1
+ """
2
+ MDForge: Forge Markdown files in a Python way.
3
+ """
4
+
5
+ from pyrollup import rollup
6
+
7
+ from .document import *
8
+ from .elements import *
9
+
10
+ from . import document
11
+ from . import elements
12
+
13
+ __all__ = rollup(document, elements)
@@ -0,0 +1,12 @@
1
+ """
2
+ Base element functionality.
3
+ """
4
+
5
+ from abc import ABC, abstractmethod
6
+ from typing import Generator
7
+
8
+
9
+ class BaseElement(ABC):
10
+
11
+ @abstractmethod
12
+ def render(self) -> Generator[str, None, None]: ...
@@ -0,0 +1,57 @@
1
+ """
2
+ Interface for Markdown document generation.
3
+ """
4
+
5
+ from pathlib import Path
6
+ from typing import Any, Iterable, Self
7
+
8
+ from ._element import BaseElement
9
+
10
+
11
+ class Document:
12
+ """
13
+ Encapsulates a Document. Add element(s) using the `+=` operator.
14
+ """
15
+
16
+ _frontmatter: dict[str, Any] | None
17
+ _elements: list[BaseElement]
18
+
19
+ def __init__(self, frontmatter: dict[str, Any] | None = None):
20
+ self._frontmatter = frontmatter
21
+ self._elements = []
22
+
23
+ def __iadd__(self, element: BaseElement | Iterable[BaseElement]) -> Self:
24
+ """
25
+ Implements `+=` operator to add element(s).
26
+ """
27
+ elements: list[BaseElement] = (
28
+ list(element) if isinstance(element, Iterable) else [element]
29
+ )
30
+ assert all(isinstance(e, BaseElement) for e in elements)
31
+
32
+ self._elements += elements
33
+
34
+ return self
35
+
36
+ def render(self, path: Path):
37
+ """
38
+ Write Markdown document to the provided path.
39
+ """
40
+ with path.open("w") as fh:
41
+ fh.write(self.render_text())
42
+
43
+ def render_text(self) -> str:
44
+ """
45
+ Return Markdown document as text.
46
+ """
47
+
48
+ lines: list[str] = []
49
+
50
+ if self._frontmatter is not None:
51
+ # TODO: write frontmatter
52
+ pass
53
+
54
+ for element in self._elements:
55
+ lines += list(element.render()) + [""]
56
+
57
+ return "\n".join(lines)
@@ -0,0 +1,65 @@
1
+ """
2
+ Exports common elements for use in document generation.
3
+ """
4
+
5
+ from __future__ import annotations
6
+ from dataclasses import dataclass
7
+ from typing import Generator
8
+
9
+ from ._element import BaseElement
10
+
11
+ __all__ = [
12
+ "Heading",
13
+ "Paragraph",
14
+ "List",
15
+ ]
16
+
17
+ INDENT = " " * 2
18
+
19
+
20
+ @dataclass
21
+ class Heading(BaseElement):
22
+ """
23
+ Heading, e.g. `# My heading`.
24
+ """
25
+
26
+ title: str
27
+ level: int = 1
28
+
29
+ def render(self) -> Generator[str, None, None]:
30
+ yield f"{'#' * self.level} {self.title}"
31
+
32
+
33
+ @dataclass
34
+ class Paragraph(BaseElement):
35
+
36
+ lines: str | list[str]
37
+
38
+ def render(self) -> Generator[str, None, None]:
39
+ lines = [self.lines] if isinstance(self.lines, str) else self.lines
40
+ assert all(isinstance(l, str) for l in lines)
41
+
42
+ yield from lines
43
+
44
+
45
+ type ListItemType = str | list[ListItemType]
46
+
47
+
48
+ @dataclass
49
+ class List(BaseElement):
50
+
51
+ items: list[ListItemType]
52
+
53
+ def render(self) -> Generator[str, None, None]:
54
+
55
+ def do_render(
56
+ items: list[ListItemType], depth: int
57
+ ) -> Generator[str, None, None]:
58
+ for item in items:
59
+ if isinstance(item, str):
60
+ yield f"{INDENT * depth}- {item}"
61
+ else:
62
+ assert isinstance(item, list)
63
+ yield from do_render(item, depth + 1)
64
+
65
+ yield from do_render(self.items, 0)
@@ -0,0 +1,41 @@
1
+ [tool.poetry]
2
+ authors = ["mm21 <mm21.dev@gmail.com>"]
3
+ classifiers = [
4
+ # Get the list of trove classifiers here: https://pypi.org/classifiers/
5
+ "Programming Language :: Python :: Implementation :: CPython",
6
+ "Operating System :: OS Independent",
7
+ "Typing :: Typed",
8
+ "Topic :: Software Development :: Libraries :: Python Modules",
9
+ "Development Status :: 2 - Pre-Alpha",
10
+ "Natural Language :: English",
11
+ "License :: OSI Approved :: MIT License"
12
+ ]
13
+ description = "Synthesize Markdown files in a Pythonic way"
14
+ homepage = "https://github.com/mm21/mdforge"
15
+ name = "mdforge"
16
+ packages = [{include = "mdforge"}]
17
+ readme = "README.md"
18
+ version = "0.1.0"
19
+
20
+ [tool.poetry.dependencies]
21
+ python = "^3.12"
22
+ pyrollup = "^0.1.0"
23
+
24
+ [tool.poetry.group.dev.dependencies]
25
+ pytest = "^8.3.2"
26
+ black = "^24.8.0"
27
+ mypy = "^1.11.2"
28
+
29
+ [tool.black]
30
+ line-length = 80
31
+
32
+ [tool.pytest.ini_options]
33
+ testpaths = ["test"]
34
+ addopts = "--import-mode=importlib -s -v -rA"
35
+ markers = [
36
+ "filename"
37
+ ]
38
+
39
+ [build-system]
40
+ build-backend = "poetry.core.masonry.api"
41
+ requires = ["poetry-core"]