-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: improving documentation generation
- Loading branch information
1 parent
945c879
commit 94e948a
Showing
1 changed file
with
41 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
|