-
-
Notifications
You must be signed in to change notification settings - Fork 34
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
Added __main__.py to execute package with python -m restview
#53
Conversation
2 similar comments
A shorter docstring makes more sense than a duplicated docstring.
Yes, please. And maybe add it to
I don't think that's necessary.
Yes, please, and also remove the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests fail on Appveyor because __main__.py
has no if __name__ == '__main__':
check and tries to run main()
on import during test discovery. This needs to be fixed.
(I wonder why tests don't break on Travis CI?)
The rest looks good, but it would look even better if more of your suggested changes were made.
Also, can you add a short entry to CHANGES.rst, something about "python -m restview
is now supported"?
I may have overdone the changes, feel free to ask to revert them... I took some input from this page on how to "do Python apps the right way", obviously, that is an opinion... Also, I didn't realize that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer it if main() stayed in restviewhttp.py. I'm not sure why this is; possibly because I don't like to see underscores in import statements (in the test suite), possibly because I learned the lesson of not putting code in __init__.py
and now am transferring that lesson to all dunder modules without proper justification.
I'll LGTM this, but leave it open for a couple of days, in case you want to make it flake8-clean etc.
src/restview/__init__.py
Outdated
@@ -0,0 +1,3 @@ | |||
|
|||
__version__ = '2.8.2.dev0' | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
flake8 is going to complain about the blank line at the end of the file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tool I use to automate releases (zest.releaser) needs to be told which Python file contains the __version__
definition so it can update it. This is specified in setup.cfg
, which now needs to be updated.
src/restview/__main__.py
Outdated
|
||
from restview import __version__ | ||
from restview import restviewhttp | ||
from restview.restviewhttp import RestViewer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This mixing of import styles feels weird to me. If you're using restviewhttp.<stuff>
, why not use restviewhttp.RestViewer
as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea, actually that is basically enough of a reason for reverting back to having it all in restviewhttp... It is an unfortunate side-effect of how Mock
and patch
work. Without using the module-specific methods, patch
wouldn't register properly.
src/restview/restviewhttp.py
Outdated
@@ -681,118 +661,3 @@ def launch_browser(url): | |||
t.start() | |||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This leaves multiple blank lines at end of file for flake8 to complain about ;)
src/restview/tests.py
Outdated
@@ -954,7 +955,8 @@ def run_main(self, *args, **kw): | |||
|
|||
def test_help(self): | |||
stdout, stderr = self.run_main('--help') | |||
self.assertTrue('restview [options] root' in stdout, stdout) | |||
self.assertTrue('restview [-h]' in stdout, stdout) | |||
self.assertTrue('[root [root ...]]' in stdout, stdout) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, this part makes me unhappy.
You moved code from one module to another and changed it at the same time, which means now I cannot see the changes in the diff.
And I had that custom usage=
argument there for a reason (purely aesthetical, but still).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I certainly wasn't trying to slip something by, sorry if that seemed the case.
I'm happy to revert. I thought there was some confusion over the rather detailed custom usage in the restviewhttp.py
docstring vs. the custom usage=
argument. I spent some time trying to use both the long-form docstring and custom usage=
, but it got ugly.... usage='\n'.join(__doc__.split('\n')[2:-3])
.
Anyway, I should have realized that this was something you cared about, due to the test.
src/restview/__main__.py
Outdated
|
||
if __name__ == '__main__': | ||
main() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
flake8 will complain about the blank line,
(I should add flake8 to my Travis config TBH.)
src/restview/restviewhttp.py
Outdated
|
||
Needs docutils and a web browser. Will syntax-highlight code or doctest blocks | ||
(needs pygments). | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would keep a short version of this, just
"""
HTTP-based ReStructuredText viewer.
"""
src/restview/__main__.py
Outdated
from restview.restviewhttp import RestViewer | ||
|
||
|
||
def main(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know why my gut feeling is against having actual code in __main__.py
. I'll have to think about it some more (and maybe re-read that blog post you linked, which I'm sure I must've read before).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, I don't have a strong preference, I just like restview :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add the CHANGES.rst entry crediting yourself with supporting python -m restview
?
parser = argparse.ArgumentParser( | ||
usage="%(prog)s [options] root [...]", | ||
description="Serve ReStructuredText files over HTTP.", | ||
prog=progname) | ||
prog="restview") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooh, what's sys.argv[0]
look like when you do python -m restview
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sys.argv[0]
is /path/to/restview/src/restview/__main__.py
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha yeah, good catch!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done, hopefully :-)
parser = argparse.ArgumentParser( | ||
usage="%(prog)s [options] root [...]", | ||
description="Serve ReStructuredText files over HTTP.", | ||
prog=progname) | ||
prog="restview") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sys.argv[0]
is /path/to/restview/src/restview/__main__.py
Thank you! |
This addresses #52. I'm not sure if it makes sense to keep the same docstring in this file. I can remove it altogether or shorten to simply:
given that argparse kinda handles the rest.
Other questions:
if __name__ == '__main__'
fromrestviewhttp.py
?__main__
instead of therestview.restviewhttp:main
?chmod -x restviewhttp.py
? (no effect on windows)