Skip to content

Commit 89c6b2b

Browse files
authored
bpo-36329: Remove 'make -C Doc serve' in favour of 'make -C Doc htmlview' (GH-32354)
Also updated `make -C htmlview` so it used a full path with `file://`, because the original didn't open the page (macOS). For example: ```sh cd Doc # Doesn't open anything: python3 -c "import webbrowser; webbrowser.open('build/html/index.html')" # Opens the docs page e.g. file:///Users/hugo/github/cpython/Doc/build/html/index.html : python3 -c "import os, webbrowser; webbrowser.open('file://' + os.path.realpath('build/html/index.html'))" ``` https://bugs.python.org/issue36329
1 parent 64113a4 commit 89c6b2b

File tree

6 files changed

+62
-54
lines changed

6 files changed

+62
-54
lines changed

Doc/Makefile

+2-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ PAPER =
1313
SOURCES =
1414
DISTVERSION = $(shell $(PYTHON) tools/extensions/patchlevel.py)
1515
SPHINXERRORHANDLING = -W
16-
SERVE_PORT =
1716

1817
# Internal variables.
1918
PAPEROPT_a4 = -D latex_elements.papersize=a4paper
@@ -45,7 +44,6 @@ help:
4544
@echo " dist to create a \"dist\" directory with archived docs for download"
4645
@echo " suspicious to check for suspicious markup in output text"
4746
@echo " check to run a check for frequent markup errors"
48-
@echo " serve to serve the documentation on the localhost (8000)"
4947

5048
build:
5149
-mkdir -p build
@@ -141,7 +139,7 @@ pydoc-topics: build
141139
"cp build/pydoc-topics/topics.py ../Lib/pydoc_data/topics.py"
142140

143141
htmlview: html
144-
$(PYTHON) -c "import webbrowser; webbrowser.open('build/html/index.html')"
142+
$(PYTHON) -c "import os, webbrowser; webbrowser.open('file://' + os.path.realpath('build/html/index.html'))"
145143

146144
clean: clean-venv
147145
-rm -rf build/*
@@ -219,7 +217,7 @@ check:
219217
$(SPHINXLINT) ../Misc/NEWS.d/next/
220218

221219
serve:
222-
$(PYTHON) ../Tools/scripts/serve.py build/html $(SERVE_PORT)
220+
@echo "The serve target was removed, use htmlview instead (see bpo-36329)"
223221

224222
# Targets for daily automated doc build
225223
# By default, Sphinx only rebuilds pages where the page content has changed.

Doc/library/wsgiref.rst

+57-11
Original file line numberDiff line numberDiff line change
@@ -813,30 +813,76 @@ Examples
813813

814814
This is a working "Hello World" WSGI application::
815815

816+
"""
817+
Every WSGI application must have an application object - a callable
818+
object that accepts two arguments. For that purpose, we're going to
819+
use a function (note that you're not limited to a function, you can
820+
use a class for example). The first argument passed to the function
821+
is a dictionary containing CGI-style environment variables and the
822+
second variable is the callable object.
823+
"""
816824
from wsgiref.simple_server import make_server
817825

818-
# Every WSGI application must have an application object - a callable
819-
# object that accepts two arguments. For that purpose, we're going to
820-
# use a function (note that you're not limited to a function, you can
821-
# use a class for example). The first argument passed to the function
822-
# is a dictionary containing CGI-style environment variables and the
823-
# second variable is the callable object.
826+
824827
def hello_world_app(environ, start_response):
825-
status = '200 OK' # HTTP Status
826-
headers = [('Content-type', 'text/plain; charset=utf-8')] # HTTP Headers
828+
status = "200 OK" # HTTP Status
829+
headers = [("Content-type", "text/plain; charset=utf-8")] # HTTP Headers
827830
start_response(status, headers)
828831

829832
# The returned object is going to be printed
830833
return [b"Hello World"]
831834

832-
with make_server('', 8000, hello_world_app) as httpd:
835+
with make_server("", 8000, hello_world_app) as httpd:
833836
print("Serving on port 8000...")
834837

835838
# Serve until process is killed
836839
httpd.serve_forever()
837840

838841

842+
839843
Example of a WSGI application serving the current directory, accept optional
840-
directory and port number (default: 8000) on the command line:
844+
directory and port number (default: 8000) on the command line::
845+
846+
"""
847+
Small wsgiref based web server. Takes a path to serve from and an
848+
optional port number (defaults to 8000), then tries to serve files.
849+
MIME types are guessed from the file names, 404 errors are raised
850+
if the file is not found.
851+
"""
852+
import mimetypes
853+
import os
854+
import sys
855+
from wsgiref import simple_server, util
856+
857+
858+
def app(environ, respond):
859+
# Get the file name and MIME type
860+
fn = os.path.join(path, environ["PATH_INFO"][1:])
861+
if "." not in fn.split(os.path.sep)[-1]:
862+
fn = os.path.join(fn, "index.html")
863+
mime_type = mimetypes.guess_type(fn)[0]
864+
865+
# Return 200 OK if file exists, otherwise 404 Not Found
866+
if os.path.exists(fn):
867+
respond("200 OK", [("Content-Type", mime_type)])
868+
return util.FileWrapper(open(fn, "rb"))
869+
else:
870+
respond("404 Not Found", [("Content-Type", "text/plain")])
871+
return [b"not found"]
872+
873+
874+
if __name__ == "__main__":
875+
# Get the path and port from command-line arguments
876+
path = sys.argv[1] if len(sys.argv) > 1 else os.getcwd()
877+
port = int(sys.argv[2]) if len(sys.argv) > 2 else 8000
878+
879+
# Make and start the server until control-c
880+
httpd = simple_server.make_server("", port, app)
881+
print(f"Serving {path} on port {port}, control-C to stop")
882+
try:
883+
httpd.serve_forever()
884+
except KeyboardInterrupt:
885+
print("Shutting down.")
886+
httpd.server_close()
887+
841888

842-
.. literalinclude:: ../../Tools/scripts/serve.py

Doc/make.bat

+2-2
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ echo. Provided by Sphinx:
111111
echo. html, htmlhelp, latex, text
112112
echo. suspicious, linkcheck, changes, doctest
113113
echo. Provided by this script:
114-
echo. clean, check, serve, htmlview
114+
echo. clean, check, htmlview
115115
echo.
116116
echo.All arguments past the first one are passed through to sphinx-build as
117117
echo.filenames to build or are ignored. See README.rst in this directory or
@@ -184,7 +184,7 @@ cmd /S /C "%SPHINXLINT% -i tools"
184184
goto end
185185

186186
:serve
187-
cmd /S /C "%PYTHON% ..\Tools\scripts\serve.py "%BUILDDIR%\html""
187+
echo.The serve target was removed, use htmlview instead (see bpo-36329)
188188
goto end
189189

190190
:end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove 'make -C Doc serve' in favour of 'make -C Doc htmlview'

Tools/scripts/README

-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ reindent.py Change .py files to use 4-space indents
5757
reindent-rst.py Fix-up reStructuredText file whitespace
5858
rgrep.py Reverse grep through a file (useful for big logfiles)
5959
run_tests.py Run the test suite with more sensible default options
60-
serve.py Small wsgiref-based web server, used in make serve in Doc
6160
stable_abi.py Stable ABI checks and file generators.
6261
suff.py Sort a list of files by suffix
6362
texi2html.py Convert GNU texinfo files into HTML

Tools/scripts/serve.py

-36
This file was deleted.

0 commit comments

Comments
 (0)