From f841e221213f366b0272734df5c614f2ecb32cf6 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Wed, 6 Apr 2022 12:26:28 +0300 Subject: [PATCH 1/4] bpo-36329: Replace 'make serve' with 'make htmlview' --- Makefile | 11 +++++------ make.bat | 19 ++++++++++++------- tools/serve.py | 37 ------------------------------------- 3 files changed, 17 insertions(+), 50 deletions(-) delete mode 100755 tools/serve.py diff --git a/Makefile b/Makefile index 3f3963296..550f539f1 100644 --- a/Makefile +++ b/Makefile @@ -14,12 +14,12 @@ PAPEROPT_letter = -D latex_paper_size=letter ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp \ - devhelp epub latex latexpdf text man changes linkcheck doctest check \ - serve + devhelp epub latex latexpdf text man changes linkcheck doctest htmlview check help: @echo "Please use \`make ' where is one of" @echo " html to make standalone HTML files" + @echo " htmlview to open the index page built by the html target in your browser" @echo " dirhtml to make HTML files named index.html in directories" @echo " singlehtml to make a single large HTML file" @echo " pickle to make pickle files" @@ -36,7 +36,6 @@ help: @echo " linkcheck to check all external links for integrity" @echo " doctest to run all doctests embedded in the documentation (if enabled)" @echo " check to run a check for frequent markup errors" - @echo " serve to serve devguide on the localhost (8000)" clean: -rm -rf $(BUILDDIR)/* @@ -139,8 +138,8 @@ doctest: venv @echo "Testing of doctests in the sources finished, look at the " \ "results in $(BUILDDIR)/doctest/output.txt." +htmlview: html + $(PYTHON) -c "import os, webbrowser; webbrowser.open('file://' + os.path.realpath('_build/html/index.html'))" + check: $(PYTHON) tools/rstlint.py -i tools -i venv - -serve: html - tools/serve.py _build/html diff --git a/make.bat b/make.bat index aeb35f313..08299d07e 100644 --- a/make.bat +++ b/make.bat @@ -17,7 +17,6 @@ if NOT "%PAPER%" == "" ( ) if "%1" == "check" goto check -if "%1" == "serve" goto serve if "%1" == "" goto help if "%1" == "help" ( @@ -39,7 +38,6 @@ if "%1" == "help" ( echo. linkcheck to check all external links for integrity echo. doctest to run all doctests embedded in the documentation if enabled echo. check to check for stylistic and formal issues using rstlint - echo. serve to serve devguide on the localhost ^(8000^) goto end ) @@ -49,7 +47,7 @@ if "%1" == "clean" ( goto end ) -rem Targets other than "clean", "check", "serve", "help", or "" need the +rem Targets other than "clean", "check", "help", or "" need the rem Sphinx build command, which the user may define via SPHINXBUILD. if not defined SPHINXBUILD ( @@ -72,6 +70,17 @@ if "%1" == "html" ( goto end ) +if "%1" == "htmlview" ( + cmd /C %this% html + + if EXIST "%BUILDDIR%\html\index.html" ( + echo.Opening "%BUILDDIR%\html\index.html" in the default web browser... + start "" "%BUILDDIR%\html\index.html" + ) + + goto end +) + if "%1" == "dirhtml" ( %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml if errorlevel 1 exit /b 1 @@ -195,10 +204,6 @@ results in %BUILDDIR%/doctest/output.txt. cmd /C %PYTHON% tools\rstlint.py -i tools -i venv goto end -:serve -cmd /C %PYTHON% tools\serve.py %BUILDDIR%\html -goto end - :end popd endlocal diff --git a/tools/serve.py b/tools/serve.py deleted file mode 100755 index 98b1e5d46..000000000 --- a/tools/serve.py +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env python3 -''' -Small wsgiref based web server. Takes a path to serve from and an -optional port number (defaults to 8000), then tries to serve files. -Mime types are guessed from the file names, 404 errors are raised -if the file is not found. Used for the make serve target in Doc. -''' -import sys -import os -import mimetypes -from wsgiref import simple_server, util - - -def app(environ, respond): - - fn = os.path.join(path, environ['PATH_INFO'][1:]) - if '.' not in fn.split(os.path.sep)[-1]: - fn = os.path.join(fn, 'index.html') - type = mimetypes.guess_type(fn)[0] - - if os.path.exists(fn): - respond('200 OK', [('Content-Type', type)]) - return util.FileWrapper(open(fn, "rb")) - else: - respond('404 Not Found', [('Content-Type', 'text/plain')]) - return [b'not found'] - - -if __name__ == '__main__': - path = sys.argv[1] - port = int(sys.argv[2]) if len(sys.argv) > 2 else 8000 - httpd = simple_server.make_server('', port, app) - print("Serving {} on http://localhost:{}, control-C to stop".format(path, port)) - try: - httpd.serve_forever() - except KeyboardInterrupt: - print("\b\bShutting down.") From 3e1625c763d2de80d6b9833edce920839a46a082 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Mon, 18 Apr 2022 19:47:12 +0300 Subject: [PATCH 2/4] Document htmlview in help --- make.bat | 1 + 1 file changed, 1 insertion(+) diff --git a/make.bat b/make.bat index 08299d07e..b03ad2ba2 100644 --- a/make.bat +++ b/make.bat @@ -23,6 +23,7 @@ if "%1" == "help" ( :help echo.Please use `make ^` where ^ is one of echo. html to make standalone HTML files + echo. htmlview to open the index page built by the html target in your browser echo. dirhtml to make HTML files named index.html in directories echo. singlehtml to make a single large HTML file echo. pickle to make pickle files From df0e47dee510c523c2ac0630d74299914374c9ba Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Fri, 29 Apr 2022 22:14:34 +0300 Subject: [PATCH 3/4] Direct users of serve towards htmlview instead --- Makefile | 4 ++++ make.bat | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/Makefile b/Makefile index 550f539f1..90d8fbe78 100644 --- a/Makefile +++ b/Makefile @@ -143,3 +143,7 @@ htmlview: html check: $(PYTHON) tools/rstlint.py -i tools -i venv + +serve: + @echo "The serve target was removed, use htmlview instead" \ + "(see https://github.com/python/cpython/issues/80510)" diff --git a/make.bat b/make.bat index b03ad2ba2..cba6cb9d5 100644 --- a/make.bat +++ b/make.bat @@ -205,6 +205,11 @@ results in %BUILDDIR%/doctest/output.txt. cmd /C %PYTHON% tools\rstlint.py -i tools -i venv goto end +:serve + echo.The serve target was removed, use htmlview instead ^ +(see https://github.com/python/cpython/issues/80510) +goto end + :end popd endlocal From 95e71189b78a07eae4a7473760258799722c26e6 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Sat, 30 Apr 2022 11:50:44 +0300 Subject: [PATCH 4/4] Add quotes around target names for clarity --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 90d8fbe78..38b476628 100644 --- a/Makefile +++ b/Makefile @@ -145,5 +145,5 @@ check: $(PYTHON) tools/rstlint.py -i tools -i venv serve: - @echo "The serve target was removed, use htmlview instead" \ + @echo "The 'serve' target was removed, use 'htmlview' instead" \ "(see https://github.com/python/cpython/issues/80510)"