Last active
January 8, 2023 16:22
-
-
Save SpotlightForBugs/3cc9d6cd18696966d7d8c697bf2ef500 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import os | |
import html2text | |
import pdoc | |
def main(): | |
""" | |
The main function runs the write_docs.py script. | |
It overwrites the old documentation with the new documentation. | |
in the docs folder. | |
:return: The documentation for the project | |
:doc-author: Johannes Häusler | |
""" | |
# Set the directory where the Python files are located | |
directory = os.path.dirname(os.path.abspath(__file__)) | |
# Set the directory where the documentation will be stored | |
docs_directory = os.path.join(directory, "docs") | |
# delete old docs | |
for file in os.listdir(docs_directory): | |
if file.endswith(".py.md"): | |
os.remove(os.path.join(docs_directory, file)) | |
logger.info(f"Deleted {file}") | |
# Create an HTML to Markdown converter | |
html_to_markdown = html2text.HTML2Text() | |
# Iterate through all files in the directory | |
for filename in os.listdir(directory): | |
# Check if the file is a Python file | |
if filename.endswith(".py"): | |
# Extract the module name from the file name | |
module_name = os.path.splitext(filename)[0] | |
logger.info(f"Generating documentation for {module_name}") | |
# Use pdoc3 to generate the documentation for the module | |
doc = pdoc.html(module_name) | |
# Convert the HTML to Markdown | |
markdown = html_to_markdown.handle(doc) | |
# Create a new Markdown file for the current Python file | |
with open( | |
os.path.join(docs_directory, f"{filename}.md"), "w", encoding="utf-8" | |
) as f: | |
# Write the Markdown to the file | |
f.write( | |
markdown.replace("EXPAND SOURCE CODE".capitalize(), "").replace( | |
"# INDEX".replace("INDEX", "Index"), "" | |
) | |
) | |
if __name__ == "__main__": | |
main() |
This file contains hidden or 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
name: Create pull request | |
on: [push] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Set up Python | |
uses: actions/setup-python@v2 | |
with: | |
python-version: 3.8 | |
- name: Install dependencies | |
run: | | |
sudo apt-get install portaudio19-dev | |
pip install -r requirements.txt | |
- name: Run Python script | |
run: | | |
python write_docs.py | |
- name: Commit changes | |
uses: EndBug/add-and-commit@v7 | |
with: | |
author_name: Docs Bot | |
author_email: [email protected] | |
author_image: https://raw.githubusercontent.com/github/explore/0a84ca418425da147e4e43b1c74aa169d3265870/topics/bot/bot.png | |
message: "Update docs" | |
add: "docs" | |
- name: Push changes | |
uses: ad-m/github-push-action@master | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
branch: 'pro' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment