Skip to content

Commit

Permalink
Add simple script to fill placeholders in docs
Browse files Browse the repository at this point in the history
  • Loading branch information
teekuningas committed Feb 22, 2024
1 parent 5844aa5 commit 4d336c0
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 6 deletions.
1 change: 1 addition & 0 deletions .github/workflows/gh-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
- name: Build and deploy
run: |
make update_docs
mkdocs gh-deploy -b gh-pages-test --force
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
13 changes: 7 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
build
conda-bld
dist
meggie.egg-info
preferences.cfg
site
docs_updated
*.swm
*.pyc
*.swm
*.swo
*.swn
*.swp
*~
build
conda-bld
dist
meggie.egg-info
preferences.cfg
site
*.~lock.*
*.orig
.project
Expand Down
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,13 @@ format:
check:
black --check -t py39 meggie
pylama meggie

.PHONY: update_docs
update_docs:
rm -fr docs_updated
cp -fr docs docs_updated
python update_docs.py docs_updated

.PHONY: serve_docs
serve_docs: update_docs
mkdocs serve
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
site_name: Meggie
site_url: https://cibr-jyu.github.io/meggie
docs_dir: docs_updated

nav:
- Home: index.md
Expand Down
5 changes: 5 additions & 0 deletions release_pypi.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#!/bin/bash

# Before, remember to:
# 1) Update setup.py
# 2) Update CHANGES.rst
# 3) Add a tag

if [[ -z "${INTERP}" ]]; then
INTERP=python
fi
Expand Down
37 changes: 37 additions & 0 deletions update_docs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import os
import sys

docs_dir = sys.argv[1]

def list_files(directory):
for root, dirs, files in os.walk(directory):
for file in files:
yield os.path.join(root, file)

if __name__ == '__main__':

# parse version from setup.py
with open("setup.py", "r") as f:
lines = f.readlines()

version = [
line.split("=")[1].split(",")[0].strip("'") for line in lines if "version" in line
][0]

# Search and replace the version in the md file
for file_path in list_files(docs_dir):
if not file_path.endswith('.md'):
continue

# Read the contents of the file
with open(file_path, 'r') as f:
file_contents = f.read()

# Replace '{{VERSION}}' with the actual version
file_contents = file_contents.replace('{{VERSION}}', version)

# Write the modified contents back to the file
with open(file_path, 'w') as f:
f.write(file_contents)

print("Updated the docs successfully.")

0 comments on commit 4d336c0

Please sign in to comment.