Get dosctring without import

Ben Finney ben+python at benfinney.id.au
Sat Feb 27 00:58:54 CET 2010


Joan Miller <peloko45 at gmail.com> writes:

> On 26 feb, 12:35, Ben Finney <ben+pyt... at benfinney.id.au> wrote:
> > A common convention is to have a ‘README’ text file, written in
> > reStructuredText for rendering to various output formats as part of
> > the documentation. You could then have the ‘setup.py’ program read
> > the contents of that file and use it (or a slice of it) for the
> > package description.
> I get the 'README.txt' file to get the long description but I use the
> docstring because each package should include a short desciption about
> it.

I keep both in the same file:

===== README =====
FooBar, a library for spangulation.

The FooBar library provides thribbles which can be
easily frobnicated for spangulation in a sntandard manner.

Other spangulation libraries are far less weebly than this
one, which is the choice of discerning grognards everywhere.
=====

Then, the description fields are derived by splitting the file's
contents on the first paragraph break:

=====
from distutils.core import setup

readme_file = open("README")

short_description, long_description = (
    d.strip()
    for d in readme_file.read().split(u'\n\n', 1))

setup(
    # …
    description=short_description,
    long_description=long_description,
    # …
    )
=====

-- 
 \      “Some forms of reality are so horrible we refuse to face them, |
  `\     unless we are trapped into it by comedy. To label any subject |
_o__)        unsuitable for comedy is to admit defeat.” —Peter Sellers |
Ben Finney



More information about the Python-list mailing list