Open matrixise opened 5 years ago
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.
"make serve" has been added by bpo-8004 which added Tools/scripts/serve.py.
commit e4c74e1ea26e77b065a8999b7192160595474211 Author: Dirkjan Ochtman \dirkjan@ochtman.nl\ Date: Wed Feb 24 04:12:11 2010 +0000
Issue bpo-8004: add a serve target to the Doc Makefile.
I disagree with deprecating serve.py. It is a demo for the wsgiref module.
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.
Hi @mdk and @brett
with your suggestions, I will move the serve.py in the documentation of wsgiref and change Doc/Makefile.
with your suggestions, I will move the serve.py in the documentation of wsgiref and change Doc/Makefile.
I suggest to write two separated PRs for each change.
@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
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.
Maybe others prefer to do both changes at once. I don't know.
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
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.
Just dropping part-1 is fine with me, thanks.
New changeset 360e1e4c519cfc139de707bcdd1e6c871eec79ee by Brett Cannon (Stéphane Wirtel) in branch 'master': bpo-36345: Add a new example in the documentation of wsgiref (bpo-12511) https://github.com/python/cpython/commit/360e1e4c519cfc139de707bcdd1e6c871eec79ee
Thank you for the merge.
Stéphane
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?).
New changeset 2b7f93b99afbe78e4e567d9252d9470d29f387c8 by Stéphane Wirtel in branch 'master': bpo-36345: Update wsgiref example (GH-12562) https://github.com/python/cpython/commit/2b7f93b99afbe78e4e567d9252d9470d29f387c8
Please revert 360e1e4c519cfc139de707bcdd1e6c871eec79ee. 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.
Berker Peksag:
Please revert 360e1e4c519cfc139de707bcdd1e6c871eec79ee. 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:
https://www.python.org/dev/peps/pep-3333/#the-start-response-callable
You can read PEP-3333 for more details.
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 (84a13fbda0d79789e3c9efcc9f64752261ce1e8d) 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 :)
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 ;-)
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields: ```python assignee = None closed_at = None created_at =
labels = ['3.8', 'docs']
title = 'Doc: make serve uses http.server instead of Tools/scripts/server.py'
updated_at =
user = 'https://github.com/matrixise'
```
bugs.python.org fields:
```python
activity =
actor = 'matrixise'
assignee = 'docs@python'
closed = False
closed_date = None
closer = None
components = ['Documentation']
creation =
creator = 'matrixise'
dependencies = []
files = []
hgrepos = []
issue_num = 36345
keywords = ['patch']
message_count = 22.0
messages = ['338224', '338247', '338258', '338276', '338396', '338631', '338637', '338662', '338665', '338666', '338739', '338741', '338743', '338833', '338864', '338874', '338909', '340338', '341162', '342046', '342060', '342135']
nosy_count = 8.0
nosy_names = ['brett.cannon', 'vstinner', 'ned.deily', 'docs@python', 'berker.peksag', 'serhiy.storchaka', 'matrixise', 'mdk']
pr_nums = ['12408', '12511', '12522', '12562']
priority = 'normal'
resolution = None
stage = 'resolved'
status = 'open'
superseder = None
type = None
url = 'https://bugs.python.org/issue36345'
versions = ['Python 3.8']
```