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

add small program to serve docs #52252

Closed
djc opened this issue Feb 23, 2010 · 16 comments
Closed

add small program to serve docs #52252

djc opened this issue Feb 23, 2010 · 16 comments
Assignees
Labels
docs Documentation in the Doc dir type-feature A feature request or enhancement

Comments

@djc
Copy link
Member

djc commented Feb 23, 2010

BPO 8004
Nosy @birkenfeld, @benjaminp, @djc, @merwok, @bitdancer

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 = 'https://github.com/djc'
closed_at = <Date 2010-02-24.04:12:38.097>
created_at = <Date 2010-02-23.21:22:05.130>
labels = ['type-feature', 'docs']
title = 'add small program to serve docs'
updated_at = <Date 2010-02-24.17:07:04.121>
user = 'https://github.com/djc'

bugs.python.org fields:

activity = <Date 2010-02-24.17:07:04.121>
actor = 'djc'
assignee = 'djc'
closed = True
closed_date = <Date 2010-02-24.04:12:38.097>
closer = 'djc'
components = ['Demos and Tools', 'Documentation']
creation = <Date 2010-02-23.21:22:05.130>
creator = 'djc'
dependencies = []
files = []
hgrepos = []
issue_num = 8004
keywords = ['patch']
message_count = 16.0
messages = ['99953', '99960', '99961', '99968', '99969', '99971', '99974', '99975', '99982', '99983', '100001', '100013', '100014', '100016', '100017', '100046']
nosy_count = 5.0
nosy_names = ['georg.brandl', 'benjamin.peterson', 'djc', 'eric.araujo', 'r.david.murray']
pr_nums = []
priority = 'low'
resolution = 'fixed'
stage = 'patch review'
status = 'closed'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue8004'
versions = ['Python 2.7', 'Python 3.2']

@djc
Copy link
Member Author

djc commented Feb 23, 2010

I'd like to put something like this in Doc, to make it easier to actually review the built documentation. (I guess we could put it in Tools, I'd just like it better if it was right there with the other stuff.)

Good idea? Thomas Wouters kind of liked it but said I should ask you.

from wsgiref.simple_server import make_server
import mimetypes, sys, os

CWD = os.path.dirname(os.path.abspath(__file__))
ROOT = os.path.join(CWD, 'build', 'html')

def app(environ, respond):

    fn = os.path.join(ROOT, 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 [open(fn).read()]
    else:
        respond('404 Not Found', [('Content-Type', 'text/plain')])
        return ['not found']

if __name__ == '__main__':
    port = int(sys.argv[1]) if len(sys.argv) > 1 else 8000
    httpd = make_server('', port, app)
    httpd.serve_forever()

@djc djc self-assigned this Feb 23, 2010
@djc djc added docs Documentation in the Doc dir type-feature A feature request or enhancement labels Feb 23, 2010
@bitdancer
Copy link
Member

How does this make it easier to review the built documentation? Most web browsers are happy to read off disk, and that seems easier than firing up a server.

(I would actually have a use case for this, since the machine I build the docs on isn't the machine my web browser runs on; but even there it seems easier to just run firefox remotely (or, in firefox's weird parlance, 'firefox --no-remote').)

@djc
Copy link
Member Author

djc commented Feb 23, 2010

I do almost all of my development on servers, so while I guess I could mount the remote file system and do that, that's not very easy to do (since I access my servers from multiple boxes, some of which run Windows, etc). I guess if not many people do that there's not much point, but I figured the script is small and straightforward enough that it might be nice.

@bitdancer
Copy link
Member

Ah, windows. And if it was there, I'd probably use it. Let's see what Georg things.

@djc
Copy link
Member Author

djc commented Feb 23, 2010

Well, even on my MacBook I wouldn't really like having to establish a file mount to my server just to check something out in my browser.

@merwok
Copy link
Member

merwok commented Feb 23, 2010

Hello

Some remarks about the code.

  1. The imports do not follow PEP 8 (have one per line, sort by importance (os, sys, wsgiref)).
  2. Isn’t there pitfalls with __file__?
  3. Can’t you return the file object as WSGI body? Or use a direct sendfile system call?

Regards

@merwok merwok changed the title add small server to serve docs add small program to serve docs Feb 23, 2010
@djc
Copy link
Member Author

djc commented Feb 23, 2010

Sure, I'm happy to fix up the little things. The point is that this works and solves (IMO) a real problem, so I wonder if we can get this in.

@birkenfeld
Copy link
Member

Looks like a nice one for Tools/scripts, and it's a demo of how to use wsgiref too!

@bitdancer
Copy link
Member

Georg: could we also add a targets in the Docs Makefile and make.bat to fire up the script?

@djc
Copy link
Member Author

djc commented Feb 24, 2010

Oh yeah, if we can add a make target I'd be happy to have it live wherever, I guess. That's a great idea.

@djc
Copy link
Member Author

djc commented Feb 24, 2010

Fixed in r78416.

@djc djc closed this as completed Feb 24, 2010
@birkenfeld
Copy link
Member

Please add

  • a docstring for serve.py
  • a line in scripts/README for it

Thanks!

@merwok
Copy link
Member

merwok commented Feb 24, 2010

Since it’s still new, perhaps the script (and the make target) could be given a more specific name, like docserve.

@birkenfeld
Copy link
Member

The script serves any directory (of HTML files).

The Makefile target probably needs no other name since it is already the Doc/Makefile :)

@merwok
Copy link
Member

merwok commented Feb 24, 2010

Indeed, I forgot the hard-coded path has been removed, and didn’t notice the makefile was in Doc. Perfect then, and thanks for pointing these things to my sleepy self :)

@djc
Copy link
Member Author

djc commented Feb 24, 2010

Improved in r78430.

@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
docs Documentation in the Doc dir type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

4 participants