Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doc: make serve uses http.server instead of Tools/scripts/server.py #80526

Open
matrixise opened this issue Mar 18, 2019 · 22 comments
Open

Doc: make serve uses http.server instead of Tools/scripts/server.py #80526

matrixise opened this issue Mar 18, 2019 · 22 comments
Labels
3.8 only security fixes docs Documentation in the Doc dir

Comments

@matrixise
Copy link
Member

BPO 36345
Nosy @brettcannon, @vstinner, @ned-deily, @berkerpeksag, @serhiy-storchaka, @matrixise, @JulienPalard
PRs
  • bpo-36345: Doc: make serve uses http.server instead of Tools/scripts/server.py  #12408
  • bpo-36345: Add a new example in the documentation of wsgiref #12511
  • WIP: bpo-36345: Remove the deprecated Tools/scripts/serve.py script #12522
  • bpo-36345: Include the code from Tools/scripts/serve.py for the wsgiref-base web server example #12562
  • 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:

    assignee = None
    closed_at = None
    created_at = <Date 2019-03-18.13:57:39.273>
    labels = ['3.8', 'docs']
    title = 'Doc: make serve uses http.server instead of Tools/scripts/server.py'
    updated_at = <Date 2019-05-15.08:43:26.810>
    user = 'https://github.com/matrixise'

    bugs.python.org fields:

    activity = <Date 2019-05-15.08:43:26.810>
    actor = 'matrixise'
    assignee = 'docs@python'
    closed = False
    closed_date = None
    closer = None
    components = ['Documentation']
    creation = <Date 2019-03-18.13:57:39.273>
    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']

    @matrixise
    Copy link
    Member Author

    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

    @matrixise matrixise added the 3.8 only security fixes label Mar 18, 2019
    @matrixise matrixise added the docs Documentation in the Doc dir label Mar 18, 2019
    @vstinner
    Copy link
    Member

    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

    Issue bpo-8004: add a serve target to the Doc Makefile.
    

    @serhiy-storchaka
    Copy link
    Member

    I disagree with deprecating serve.py. It is a demo for the wsgiref module.

    @JulienPalard
    Copy link
    Member

    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
    Copy link
    Member

    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
    Copy link
    Member Author

    Hi @mdk and @brett

    with your suggestions, I will move the serve.py in the documentation of wsgiref and change Doc/Makefile.

    @vstinner
    Copy link
    Member

    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.

    @matrixise
    Copy link
    Member Author

    @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
    Copy link
    Member

    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
    Copy link
    Member

    Maybe others prefer to do both changes at once. I don't know.

    @ned-deily
    Copy link
    Member

    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
    Copy link
    Member Author

    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.

    @ned-deily
    Copy link
    Member

    Just dropping part-1 is fine with me, thanks.

    @brettcannon
    Copy link
    Member

    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
    Copy link
    Member Author

    Thank you for the merge.

    Stéphane

    @vstinner
    Copy link
    Member

    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
    Copy link
    Member

    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
    Copy link
    Member Author

    New changeset 2b7f93b by Stéphane Wirtel in branch 'master':
    bpo-36345: Update wsgiref example (GH-12562)
    2b7f93b

    @matrixise matrixise reopened this Apr 19, 2019
    @berkerpeksag
    Copy link
    Member

    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
    Copy link
    Member

    Berker Peksag:

    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.

    @berkerpeksag
    Copy link
    Member

    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 (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 :)

    @vstinner
    Copy link
    Member

    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 ;-)

    @matrixise matrixise 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 May 15, 2019
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.8 only security fixes docs Documentation in the Doc dir
    Projects
    None yet
    Development

    No branches or pull requests

    7 participants