From 33a057f98c2a3adebf41da094af28e4aeff30c48 Mon Sep 17 00:00:00 2001 From: Ali Khan Date: Sun, 1 Dec 2024 13:06:13 -0500 Subject: [PATCH] auto updating readme --- .github/workflows/update_readme.yml | 41 +++++++++++++++++++++++++++++ hippunfold_plot/update_readme.py | 35 ++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 .github/workflows/update_readme.yml create mode 100644 hippunfold_plot/update_readme.py diff --git a/.github/workflows/update_readme.yml b/.github/workflows/update_readme.yml new file mode 100644 index 0000000..0d1d2ce --- /dev/null +++ b/.github/workflows/update_readme.yml @@ -0,0 +1,41 @@ +name: Update README + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + update-readme: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.x' + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install . + + - name: Update README + run: | + python update_readme.py + + - name: Commit and push changes + run: | + git config --global user.name 'github-actions[bot]' + git config --global user.email 'github-actions[bot]@users.noreply.github.com' + git add README.md + git commit -m "Update README.md with function docstrings" + git push + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/hippunfold_plot/update_readme.py b/hippunfold_plot/update_readme.py new file mode 100644 index 0000000..a43b9ef --- /dev/null +++ b/hippunfold_plot/update_readme.py @@ -0,0 +1,35 @@ +import ast +import inspect +import os + +def get_function_docstrings(module): + functions = [obj for name, obj in inspect.getmembers(module) if inspect.isfunction(obj)] + docstrings = {} + for func in functions: + docstrings[func.__name__] = inspect.getdoc(func) + return docstrings + +def update_readme(readme_path, docstrings): + with open(readme_path, 'r') as file: + lines = file.readlines() + + start_functions = lines.index("## 🛠️ Functions\n") + end_functions = lines.index("## 🧪 Testing\n") + + new_lines = lines[:start_functions + 2] + for func_name, docstring in docstrings.items(): + new_lines.append(f"### `{func_name}`\n\n") + new_lines.append("```python\n") + new_lines.append(f"{docstring}\n") + new_lines.append("```\n\n") + + new_lines.extend(lines[end_functions:]) + + with open(readme_path, 'w') as file: + file.writelines(new_lines) + +if __name__ == "__main__": + import plotting + readme_path = 'README.md' + docstrings = get_function_docstrings(plotting) + update_readme(readme_path, docstrings) \ No newline at end of file