Chilipp / docrep

A Python Module for intelligent reuse of docstrings
Apache License 2.0
30 stars 4 forks source link

Handle single line short summary #3

Closed amnona closed 6 years ago

amnona commented 6 years ago

Handle the case (as in the numpydoc standard) where the short summary is attached to the triple quote. i.e. '''Short summary

longer summary...

Parameters
------------

... ''' Without this PR, dedent does not remove the spaces at the beginning of Parameters (since lowest number of spaces at line0 is 0) and then the regexp fails.

Don't know if this is the best regexp, but seems to do the job.

coveralls commented 6 years ago

Coverage Status

Coverage increased (+0.1%) to 96.269% when pulling 74067bfbdfa06f764e5b3d2f9ad06ae24cead59c on amnona:master into 0f9853cf8fab419f46c5ec7ed91003b296567903 on Chilipp:master.

Chilipp commented 6 years ago

Hey @amnona, just to mention: I also added a with_indent method that can be used to replace within these kind of docstrings. Here is the example from the docs

In [9]: @docstrings.get_sectionsf('do_something')
   ...: def second_example_source(a, b):
   ...:     """Summary is on the first line
   ...: 
   ...:     Parameters
   ...:     ----------
   ...:     a: int
   ...:         The first number
   ...:     b: int
   ...:         The second number
   ...: 
   ...:     Returns
   ...:     -------
   ...:     int
   ...:         `a` + `b`"""
   ...:     return a + b
   ...: 

In [10]: @docstrings.with_indent(4)  # we indent the replacements with 4 spaces
   ....: def second_example_target(*args, **kwargs):
   ....:     """Target docstring with summary on the first line
   ....: 
   ....:     Parameters
   ....:     ----------
   ....:     %(do_something.parameters)s
   ....: 
   ....:     Returns
   ....:     -------
   ....:     int
   ....:         (`a` + `b`) * 2"""
   ....:     return second_example_source(*args, **kargs) * 2

In [11]: help(second_example_target)
Help on function second_example_target in module __main__:

second_example_target(*args, **kwargs)
    Target docstring with summary on the first line

    Parameters
    ----------
    a: int
        The first number
    b: int
        The second number

    Returns
    -------
    int
        (`a` + `b`) * 2

I will make a new release now and then it will be available by PyPi and the conda-forge channel.