Skip to content

Commit

Permalink
docs: improving documentation generation
Browse files Browse the repository at this point in the history
  • Loading branch information
201st-Luka committed Sep 11, 2023
1 parent 945c879 commit 94e948a
Showing 1 changed file with 41 additions and 8 deletions.
49 changes: 41 additions & 8 deletions docs/doc_autogen.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,55 @@
import os
import shutil


def get_project_dir() -> str:
return "/" + os.getcwd().strip("docs/doc_autogen.py")


def create_markdown_structure(package_path, output_path):
"""
Create a directory structure mirroring the Python package structure, with
markdown files containing '::: pyclasher.path.filename' for each module.
Args:
package_path (str): The path to the Python package.
output_path (str): The path where the directory structure and markdown files will be generated.
"""
for dirpath, dirnames, filenames in os.walk(package_path):
# Create corresponding directory structure in the output path
relative_dir = os.path.relpath(dirpath, package_path)
output_dir = os.path.join(output_path, relative_dir)
os.makedirs(output_dir, exist_ok=True)

for filename in filenames:
if filename.endswith('.py') and filename != "__init__.py":
module_name = os.path.splitext(filename)[0]
import_path = "pyclasher." + '/'.join(
os.path.split(
os.path.join(relative_dir, module_name))
).replace('.', '').replace('/', '.')
print(import_path)
markdown_content = f"::: {import_path}\n"

# Create a markdown file with the import path as content
markdown_file_path = os.path.join(output_dir,
f"{module_name}.md")
with open(markdown_file_path, 'w') as markdown_file:
markdown_file.write(markdown_content)


if __name__ == '__main__':
project_dir = get_project_dir()

doc_dir = os.path.join(project_dir, "docs")

api_ref_dir = os.path.join(doc_dir, "API Reference")
api_dir = os.path.join(project_dir, "pyclasher", "api")

print(os.listdir(),
os.listdir(project_dir),
os.listdir(doc_dir),
os.listdir(api_ref_dir),
os.listdir(api_dir),
sep="\n")
pyclasher_dir = os.path.join(project_dir, "pyclasher")

shutil.rmtree(api_ref_dir)

os.mkdir(api_ref_dir)

create_markdown_structure(pyclasher_dir, api_ref_dir)


0 comments on commit 94e948a

Please sign in to comment.