Skip to content

Commit 924e394

Browse files
committed
docs: remove documentation in markdown to support python 3.13
Since json-schema-for-humans dependency does not support python 3.13, remove the generation of documentation in markdown of main docling types. Remove 'ds' prefix from documentation scripts. Signed-off-by: Cesar Berrospi Ramis <[email protected]>
1 parent 3194f56 commit 924e394

File tree

9 files changed

+87
-13177
lines changed

9 files changed

+87
-13177
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ repos:
5252
hooks:
5353
- id: docs
5454
name: Docs
55-
entry: poetry run ds_generate_docs docs
55+
entry: poetry run generate_docs docs
5656
pass_filenames: false
5757
language: system
5858
files: '\.py$'

docling_core/utils/ds_generate_docs.py

Lines changed: 0 additions & 144 deletions
This file was deleted.
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#
2+
# Copyright IBM Corp. 2024 - 2024
3+
# SPDX-License-Identifier: MIT
4+
#
5+
6+
"""Generate documentation of Docling types as JSON schema.
7+
8+
Example:
9+
python docling_core/utils/generate_docs.py /tmp/docling_core_files
10+
"""
11+
import argparse
12+
import json
13+
import os
14+
from argparse import BooleanOptionalAction
15+
from pathlib import Path
16+
from shutil import rmtree
17+
from typing import Final
18+
19+
from docling_core.utils.generate_jsonschema import generate_json_schema
20+
21+
MODELS: Final = ["Document", "Record", "Generic"]
22+
23+
24+
def _prepare_directory(folder: str, clean: bool = False) -> None:
25+
"""Create a directory or empty its content if it already exists.
26+
27+
Args:
28+
folder: The name of the directory.
29+
clean: Whether any existing content in the directory should be removed.
30+
"""
31+
if os.path.isdir(folder):
32+
if clean:
33+
for path in Path(folder).glob("**/*"):
34+
if path.is_file():
35+
path.unlink()
36+
elif path.is_dir():
37+
rmtree(path)
38+
else:
39+
os.makedirs(folder, exist_ok=True)
40+
41+
42+
def generate_collection_jsonschema(folder: str):
43+
"""Generate the JSON schema of Docling collections and export them to a folder.
44+
45+
Args:
46+
folder: The name of the directory.
47+
"""
48+
for item in MODELS:
49+
json_schema = generate_json_schema(item)
50+
with open(
51+
os.path.join(folder, f"{item}.json"), mode="w", encoding="utf8"
52+
) as json_file:
53+
json.dump(json_schema, json_file, ensure_ascii=False, indent=2)
54+
55+
56+
def main() -> None:
57+
"""Generate the JSON Schema of Docling collections and export documentation."""
58+
argparser = argparse.ArgumentParser()
59+
argparser.add_argument(
60+
"directory",
61+
help=(
62+
"Directory to generate files. If it exists, any existing content will be"
63+
" removed."
64+
),
65+
)
66+
argparser.add_argument(
67+
"--clean",
68+
help="Whether any existing content in directory should be removed.",
69+
action=BooleanOptionalAction,
70+
dest="clean",
71+
default=False,
72+
required=False,
73+
)
74+
args = argparser.parse_args()
75+
76+
_prepare_directory(args.directory, args.clean)
77+
78+
generate_collection_jsonschema(args.directory)
79+
80+
81+
if __name__ == "__main__":
82+
main()

docling_core/utils/ds_generate_jsonschema.py renamed to docling_core/utils/generate_jsonschema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"""Generate the JSON Schema of pydantic models and export them to files.
77
88
Example:
9-
python docling_core/utils/ds_generate_jsonschema.py doc.base.TableCell
9+
python docling_core/utils/generate_jsonschema.py doc.base.TableCell
1010
1111
"""
1212
import argparse

0 commit comments

Comments
 (0)