Skip to content

Commit e4c74e1

Browse files
committed
Issue #8004: add a serve target to the Doc Makefile.
1 parent 2d78070 commit e4c74e1

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

Doc/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ help:
2727
@echo " suspicious to check for suspicious markup in output text"
2828
@echo " coverage to check documentation coverage for library and C API"
2929
@echo " dist to create a \"dist\" directory with archived docs for download"
30+
@echo " serve to serve the documentation on the localhost (8000)"
3031

3132
# Note: if you update versions here, do the same in make.bat and README.txt
3233
checkout:
@@ -149,3 +150,6 @@ dist:
149150

150151
check:
151152
$(PYTHON) tools/rstlint.py -i tools
153+
154+
serve:
155+
../Tools/scripts/serve.py build/html

Tools/scripts/serve.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env python
2+
import sys
3+
import os
4+
import mimetypes
5+
from wsgiref import simple_server, util
6+
7+
def app(environ, respond):
8+
9+
fn = os.path.join(path, environ['PATH_INFO'][1:])
10+
if '.' not in fn.split(os.path.sep)[-1]:
11+
fn = os.path.join(fn, 'index.html')
12+
type = mimetypes.guess_type(fn)[0]
13+
14+
if os.path.exists(fn):
15+
respond('200 OK', [('Content-Type', type)])
16+
return util.FileWrapper(open(fn))
17+
else:
18+
respond('404 Not Found', [('Content-Type', 'text/plain')])
19+
return ['not found']
20+
21+
if __name__ == '__main__':
22+
path = sys.argv[1]
23+
port = int(sys.argv[2]) if len(sys.argv) > 2 else 8000
24+
httpd = simple_server.make_server('', port, app)
25+
httpd.serve_forever()

0 commit comments

Comments
 (0)