You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Doc: make serve uses http.server instead of Tools/scripts/server.py #80526
The Makefile of Doc/ has a serve target. Currently, this one uses [Tools/scripts/serve.py](https://github.com/python/cpython/blob/main/Tools/scripts/serve.py). But since 3.7, this script could be replaced by python -m http.server -d directory.
@mdk and myself thinking we could deprecate [Tools/scripts/serve.py](https://github.com/python/cpython/blob/main/Tools/scripts/serve.py) with a warning and propose to use -m http.server -d directory
I'm ok with modifying "make server" to reuse http.server, but I'm not sure about deprecating Tools/scripts/serve.py.
serve.py uses wsgiref which is different than http.server. Does anyone use it? I would prefer to keep it. If you want to remove it, please send an email to python-dev to ask who uses it.
If it's appreciated as a demo for wsgiref, wouldn't it be better to move it inside Doc/library/wsgiref.rst?
It was written specifically for the Doc/Makefile, it's no longer needed for the Doc/Makefile, so the question pops: is it usefull to anyone? If not it's better to drop it (or move it to the documentation as a nice, time-proven example).
I agree that if it's a good example of using wsgiref then it should exist in the wsgiref docs as an example. Then that would mean dropping the script and updating the Makefile.
The files in the Tools directory are installed on user systems by various distributions: for example, in Debian, as part of the python3.x-examples package and by the macOS python.org installer. If you move serve.py, it will no longer be available to end users there. I don't think there is any benefit to removing the file in Tools/scripts and there is some downside; let's leave it there.
New changeset 360e1e4 by Brett Cannon (Stéphane Wirtel) in branch 'master': bpo-36345: Add a new example in the documentation of wsgiref (bpo-12511) 360e1e4
Would it me sense to use ".. literalinclude:: ../../Tools/scripts/serve.py" in the wsgi doc to keep serve.py and and this example up to date? It seems like serve.py is going to stay.
I actually still think we should remove serve.py as the person who had needed to clean up that directory when we realized we had massive bitrot in /Tools. :) I don't' think that just because Debian packages means we need to continue supporting and maintaining it (e.g. if wsgiref was changed who is going to remember to update this script?).
Please revert 360e1e4. It's not a good example to put into the documentation.
It uses different naming convention. It would only confuse users relatively new to the wsgiref module and WSGI protocol.
FileWrapper was supposed to support __getitem__ and __iter__ protocols for compatibility with older Python versions, but its __getiem__ implementation is buggy and is already deprecated. It has no use case in modern Python code.
It has zero exception handling and will return a cryptic traceback if mimetype cannot detect type of the file.
The examples in the wsgiref documentation already cover most of the cases. There is no need to add more similar ones.
Please revert 360e1e4. It's not a good example to put into the documentation.
I looked at other examples: they are nice but far from a "real application". I like the last example which combines multiple wsgiref features and is written like a real application: parse command line arguments, handle CTRL+c, etc.
It uses different naming convention. It would only confuse users relatively new to the wsgiref module and WSGI protocol.
Would you mind to elaborate? I don't understand what you mean by "naming convention" here, sorry.
FileWrapper was supposed to support __getitem__ and __iter__ protocols for compatibility with older Python versions, but its __getiem__ implementation is buggy and is already deprecated. It has no use case in modern Python code.
Do you mean that app() must not return FileWrapper? How do you return file content in that case?
Maybe FileWrapper API should be clarified? It's surprising to read Python 3.8 mentioning compatibility with Python 2.1 :-)
It has zero exception handling and will return a cryptic traceback if mimetype cannot detect type of the file.
Which kind of exceptions do you expect? The example checks if the file exists for example.
I looked at other examples: they are nice but far from a "real application".
You can use the same argument for pretty much every example in the stdlib documentation :)
wsgiref is a low level module, users should use projects like WebOb instead. Also, a complete example would need to contain basic routing and middleware support (which is not easy to implement correctly)
Would you mind to elaborate? I don't understand what you mean by "naming convention" here, sorry.
For example, the response() callable in the example is explicitly documented as start_response() in PEP-3333:
Do you mean that app() must not return FileWrapper? How do you return file content in that case?
Maybe FileWrapper API should be clarified? It's surprising to read Python 3.8 mentioning compatibility with Python 2.1 :-)
The whole point of the API was to support both __getitem__ and __iter__ protocols at the same time without breaking user code. I've already deprecated the support for __getitem__ protocol (84a13fb) because it wasn't working as expected (it ignores its 'index' argument)
Its only valid use case is to read a file chunk by chunk by using its blksize argument, but there are much better ways to achieve the same thing (use os.sendfile() or nginx :))
Which kind of exceptions do you expect? The example checks if the file exists for example.
I'm talking about exceptions that can be raised by the application code, such as the one that I've mentioned (i.e. mimetypes) in my earlier comment.
Sorry, but it's not really a good example to put into documentation and it would be much better if we could save our bikeshedding bandwidth to other issues :)
changed the title [-]Deprecate Tools/scripts/serve.py in favour of python -m http.server -d[/-][+]Doc: make serve uses http.server instead of Tools/scripts/server.py[/+]on May 15, 2019
Activity
matrixise commentedon Mar 18, 2019
The Makefile of Doc/ has a
servetarget. Currently, this one uses[Tools/scripts/serve.py](https://github.com/python/cpython/blob/main/Tools/scripts/serve.py). But since 3.7, this script could be replaced bypython -m http.server -d directory.@mdk and myself thinking we could deprecate
[Tools/scripts/serve.py](https://github.com/python/cpython/blob/main/Tools/scripts/serve.py)with a warning and propose to use-m http.server -d directoryvstinner commentedon Mar 18, 2019
I'm ok with modifying "make server" to reuse http.server, but I'm not sure about deprecating Tools/scripts/serve.py.
serve.py uses wsgiref which is different than http.server. Does anyone use it? I would prefer to keep it. If you want to remove it, please send an email to python-dev to ask who uses it.
"make serve" has been added by bpo-8004 which added Tools/scripts/serve.py.
commit e4c74e1
Author: Dirkjan Ochtman <dirkjan@ochtman.nl>
Date: Wed Feb 24 04:12:11 2010 +0000
serhiy-storchaka commentedon Mar 18, 2019
I disagree with deprecating serve.py. It is a demo for the wsgiref module.
JulienPalard commentedon Mar 18, 2019
If it's appreciated as a demo for wsgiref, wouldn't it be better to move it inside Doc/library/wsgiref.rst?
It was written specifically for the Doc/Makefile, it's no longer needed for the Doc/Makefile, so the question pops: is it usefull to anyone? If not it's better to drop it (or move it to the documentation as a nice, time-proven example).
brettcannon commentedon Mar 19, 2019
I agree that if it's a good example of using wsgiref then it should exist in the wsgiref docs as an example. Then that would mean dropping the script and updating the Makefile.
matrixise commentedon Mar 23, 2019
Hi @mdk and @brett
with your suggestions, I will move the serve.py in the documentation of wsgiref and change Doc/Makefile.
vstinner commentedon Mar 23, 2019
I suggest to write two separated PRs for each change.
matrixise commentedon Mar 23, 2019
@vstinner
I propose two PRs.
The first one will remove the Tools/scripts/serve.py file and update the Makefile.
The second and independent PR just add a new example in the documentation of wsgiref, the example is based on Tools/scripts/serve.py
vstinner commentedon Mar 23, 2019
I would remove to move the script into the doc in 1 PR and just modify
Makefile in the other one. So the Makefile can be updated first.
vstinner commentedon Mar 23, 2019
Maybe others prefer to do both changes at once. I don't know.
ned-deily commentedon Mar 24, 2019
The files in the Tools directory are installed on user systems by various distributions: for example, in Debian, as part of the python3.x-examples package and by the macOS python.org installer. If you move serve.py, it will no longer be available to end users there. I don't think there is any benefit to removing the file in Tools/scripts and there is some downside; let's leave it there.
https://packages.debian.org/sid/all/python3.7-examples/filelist
matrixise commentedon Mar 24, 2019
Hi Ned,
There are 3 PRs, part-0, part-1 and part-2
We can ignore the part-1, this one remove serve.py and the two others are independent.
1 remaining item
brettcannon commentedon Mar 25, 2019
New changeset 360e1e4 by Brett Cannon (Stéphane Wirtel) in branch 'master':
bpo-36345: Add a new example in the documentation of wsgiref (bpo-12511)
360e1e4
matrixise commentedon Mar 26, 2019
Thank you for the merge.
Stéphane
vstinner commentedon Mar 26, 2019
Would it me sense to use ".. literalinclude:: ../../Tools/scripts/serve.py" in the wsgi doc to keep serve.py and and this example up to date? It seems like serve.py is going to stay.
brettcannon commentedon Mar 26, 2019
I actually still think we should remove serve.py as the person who had needed to clean up that directory when we realized we had massive bitrot in /Tools. :) I don't' think that just because Debian packages means we need to continue supporting and maintaining it (e.g. if wsgiref was changed who is going to remember to update this script?).
matrixise commentedon Apr 16, 2019
New changeset 2b7f93b by Stéphane Wirtel in branch 'master':
bpo-36345: Update wsgiref example (GH-12562)
2b7f93b
berkerpeksag commentedon Apr 30, 2019
Please revert 360e1e4. It's not a good example to put into the documentation.
It uses different naming convention. It would only confuse users relatively new to the wsgiref module and WSGI protocol.
FileWrapper was supposed to support __getitem__ and __iter__ protocols for compatibility with older Python versions, but its __getiem__ implementation is buggy and is already deprecated. It has no use case in modern Python code.
It has zero exception handling and will return a cryptic traceback if mimetype cannot detect type of the file.
The examples in the wsgiref documentation already cover most of the cases. There is no need to add more similar ones.
vstinner commentedon May 10, 2019
Berker Peksag:
I looked at other examples: they are nice but far from a "real application". I like the last example which combines multiple wsgiref features and is written like a real application: parse command line arguments, handle CTRL+c, etc.
Would you mind to elaborate? I don't understand what you mean by "naming convention" here, sorry.
Do you mean that app() must not return FileWrapper? How do you return file content in that case?
Maybe FileWrapper API should be clarified? It's surprising to read Python 3.8 mentioning compatibility with Python 2.1 :-)
Which kind of exceptions do you expect? The example checks if the file exists for example.
berkerpeksag commentedon May 10, 2019
You can use the same argument for pretty much every example in the stdlib documentation :)
wsgiref is a low level module, users should use projects like WebOb instead. Also, a complete example would need to contain basic routing and middleware support (which is not easy to implement correctly)
For example, the response() callable in the example is explicitly documented as start_response() in PEP-3333:
You can read PEP-3333 for more details.
The whole point of the API was to support both __getitem__ and __iter__ protocols at the same time without breaking user code. I've already deprecated the support for __getitem__ protocol (84a13fb) because it wasn't working as expected (it ignores its 'index' argument)
Its only valid use case is to read a file chunk by chunk by using its blksize argument, but there are much better ways to achieve the same thing (use os.sendfile() or nginx :))
I'm talking about exceptions that can be raised by the application code, such as the one that I've mentioned (i.e. mimetypes) in my earlier comment.
Sorry, but it's not really a good example to put into documentation and it would be much better if we could save our bikeshedding bandwidth to other issues :)
vstinner commentedon May 10, 2019
Ok, thanks Berker for your longer answer. I have no opinion on this example anymore. Stéphane and others: I let you decide how to handle it ;-)
[-]Deprecate Tools/scripts/serve.py in favour of python -m http.server -d[/-][+]Doc: make serve uses http.server instead of Tools/scripts/server.py[/+]hugovk commentedon Nov 18, 2024
make servehas since been replaced withmake htmllive, which uses https://github.com/sphinx-doc/sphinx-autobuild:make servewas removed in use the right python "make -C Doc/ serve" #80510.make htmllivewas added in Docs: Addmake htmlliveto rebuild and reload HTML files in your browser #111900.