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
Comments
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() |
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').) |
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. |
Ah, windows. And if it was there, I'd probably use it. Let's see what Georg things. |
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. |
Hello Some remarks about the code.
Regards |
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. |
Looks like a nice one for Tools/scripts, and it's a demo of how to use wsgiref too! |
Georg: could we also add a targets in the Docs Makefile and make.bat to fire up the script? |
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. |
Fixed in r78416. |
Please add
Thanks! |
Since it’s still new, perhaps the script (and the make target) could be given a more specific name, like docserve. |
The script serves any directory (of HTML files). The Makefile target probably needs no other name since it is already the Doc/Makefile :) |
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 :) |
Improved in r78430. |
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: