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

README.rst: recommend python -OO compatible usage #515

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 9 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ and instead can write only the help message--*the way you want it*.

.. code:: python

"""Naval Fate.
DOC = """Naval Fate.

Usage:
naval_fate.py ship new <name>...
Expand All @@ -70,11 +70,15 @@ and instead can write only the help message--*the way you want it*.
--drifting Drifting mine.

"""
# Used a var instead of docstring syntax to survive `python -OO` stripping them.
# Assigning to __doc__ is optional but good for `pydoc` and `help()`.
__doc__ = DOC

from docopt import docopt


if __name__ == '__main__':
arguments = docopt(__doc__, version='Naval Fate 2.0')
arguments = docopt(DOC, version='Naval Fate 2.0')
print(arguments)

Beat that! The option parser is generated based on the docstring above
Expand All @@ -87,6 +91,9 @@ information in it to make a parser*.

Also, `PEP 257 <http://www.python.org/dev/peps/pep-0257/>`_ recommends
putting help message in the module docstrings.
However, docstring syntax gets stripped in `python -OO` mode;
the recipe above uses a regular variable which works either way
(and still assigns `__doc__` at run time so pydoc will find it).

Installation
======================================================================
Expand Down