Skip to content

Commit 678b186

Browse files
committed
added some scripts for manual building
1 parent ab00265 commit 678b186

File tree

9 files changed

+175
-1
lines changed

9 files changed

+175
-1
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
1+
12
# Documentation
23

34
This repo contains the official documentation for Hackspace Manchester.
45

56
All members can push edits or new documentation to this repo and it will automatically build and will be available at https://docs.hacman.org.uk
67

78
This uses Github Actions and MKDocs
9+
10+
## Build Process
11+
12+
### Automated Build
13+
14+
For most folks they only want to add pages or images via Github so are not interested in how the main page is built.
15+
However for those interested the documentation pages are built into a site using mkdocs and the mkdocs material theme using a ci script
16+
[.github\workflows\ci.yml](.github\workflows\ci.yml)
17+
18+
## Manual Build
19+
20+
If you want to experiment manually building the documentation for experimenting with plugins etc. There's a script in the root directory called **build.py** which can be used with python 3.8 / mkdocs / mkdocs material / any other plugins required.
21+
22+
There's also a **virtenv** directory that can be used to setup a virtual python environment.

build.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#! python3
2+
import os, sys, subprocess, shutil
3+
4+
# MkDocs Build Script
5+
class MkDocsBuild(object):
6+
7+
# Class Init
8+
def __init__(self):
9+
self.SRCDIR = "docs"
10+
self.BUILDDIR = "site"
11+
self.MKDOCSDIR = "./"
12+
13+
# Run a command
14+
def run_cmd(self, cmdarray, workingdir):
15+
proc = subprocess.Popen(cmdarray, cwd=workingdir, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
16+
proc_out, proc_err = proc.communicate()
17+
print(proc_out)
18+
print(proc_err)
19+
if proc.returncode != 0:
20+
raise RuntimeError("Failure to run command")
21+
return
22+
23+
# Empty a directory
24+
def emptydir(self, top):
25+
if(top == '/' or top == "\\"): return
26+
else:
27+
for root, dirs, files in os.walk(top, topdown=False):
28+
for name in files:
29+
os.remove(os.path.join(root, name))
30+
for name in dirs:
31+
os.rmdir(os.path.join(root, name))
32+
33+
# Print Usage
34+
def usage(self):
35+
print ("Please use build.py <target> where <target> is one of")
36+
print (" build to build the standalone HTML files into the " + self.BUILDDIR + " directory")
37+
print (" clean to clean the output directory:" + self.BUILDDIR)
38+
print (" publish publish the site to the gh-pages branch")
39+
print (" serve Serve the site out on a port for previewing")
40+
41+
# Do the main build of doxygen html
42+
def build(self):
43+
self.clean()
44+
print("Building MkDocs Files")
45+
cmdopts = ["mkdocs", "build", "--clean"]
46+
self.run_cmd(cmdopts, self.MKDOCSDIR)
47+
print ("Build finished. The HTML pages are in " + self.BUILDDIR)
48+
49+
# Publish the Site
50+
def publish(self):
51+
print("Publishing MkDocs Files")
52+
cmdopts = ["mkdocs", "gh-deploy"]
53+
self.run_cmd(cmdopts, self.MKDOCSDIR)
54+
print ("Publish finished.")
55+
56+
def serve(self):
57+
print("Starting MkDocs Server http://127.0.0.1:8000")
58+
cmdopts = ["mkdocs", "serve"]
59+
self.run_cmd(cmdopts, self.MKDOCSDIR)
60+
print ("Server Closed.")
61+
62+
# Clean the Build directory
63+
def clean(self):
64+
self.emptydir("site")
65+
print ("Clean finished")
66+
67+
def main(self):
68+
if len(sys.argv) != 2:
69+
self.usage()
70+
return
71+
if sys.argv[1] == "build":
72+
self.build()
73+
if sys.argv[1] == "clean":
74+
self.clean()
75+
if sys.argv[1] == "publish":
76+
self.publish()
77+
if sys.argv[1] == "serve":
78+
self.serve()
79+
80+
if __name__ == "__main__":
81+
MkDocsBuild().main()

test.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

virtenv/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Ignore tox dirs
2+
.tox-dev/
3+
4+
# Ignore python virtual environment directory
5+
py38dev/

virtenv/Readme.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Readme
2+
3+
## Python Virtual Environment
4+
5+
If you have **python 3.8** and **tox** installed
6+
you can use the scripts in this directory to setup a virtual python environment
7+
8+
* **setup_venv.bat** - Setup a virtual python environment under Windows
9+
* **setup_venv.sh** - Setup a virtual python environment under Linux / Unix
10+

virtenv/dev_requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Depends
2+
mkdocs
3+
mkdocs-material

virtenv/setup_venv.bat

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
@echo off
2+
SETLOCAL
3+
4+
set "venv=%1"
5+
if "%venv%" == "" ( set "venv=py38dev" )
6+
7+
IF EXIST "%venv%" (
8+
echo "Entering virtual environment %venv%"
9+
echo "use deactivate to leave"
10+
cmd /k "%venv%\Scripts\activate.bat"
11+
12+
) ELSE (
13+
echo "Creating virtual environment %venv%"
14+
tox -c tox_dev.ini
15+
echo "Entering virtual environment %venv%"
16+
echo "use deactivate to leave"
17+
cmd /k "%venv%\Scripts\activate.bat"
18+
)
19+
20+
ENDLOCAL

virtenv/setup_venv.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#! /bin/bash
2+
3+
if [ -z "$1" ]
4+
then
5+
venv=$1
6+
else
7+
venv="py38dev"
8+
fi
9+
10+
if [ ! -d "./$venv" ]; then
11+
echo "Creating virtual environment $venv"
12+
tox -c tox_dev.ini
13+
source $venv/bin/activate
14+
fi
15+
16+
# Enter the python virtual enviro on the current shell
17+
echo "Entering virtual environment $venv"
18+
bash --rcfile <(echo '. ./py37dev/Scripts/activate')
19+
20+
# use echo $BASHPID to check the bash prompt process id

virtenv/tox_dev.ini

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Tox file for setting up python virtual environments for development
2+
3+
# To setup all use "tox -c tox_dev.ini"
4+
# To setup an individual environment "tox -c tox_dev.ini -e py37"
5+
6+
[tox]
7+
minversion = 3.0
8+
skipsdist=True
9+
setupdir = {toxinidir}/..
10+
distdir = {toxinidir}/.tox-dev/distshare
11+
toxworkdir = {toxinidir}/.tox-dev
12+
13+
# List of environments
14+
# make sure to update environment list in travis.yml and appveyor.yml
15+
envlist =
16+
py38
17+
18+
# Python 3.8 Development environment
19+
[testenv:py38]
20+
envdir = py38dev
21+
deps = -rdev_requirements.txt

0 commit comments

Comments
 (0)