dadadel / pyment

Format and convert Python docstrings and generates patches
GNU General Public License v3.0
905 stars 62 forks source link

created patch-file not correct #10

Closed theilen closed 7 years ago

theilen commented 9 years ago

When trying to convert my handwritten docstrings to something more consisting I ran into a corrupted patch-file. I attached a shortened patch-file and the corresponding original file that reproduce the bug. I was using pyment v0.3.0 with Python 2.7.6 (in a WinPython distribution).

1) As you can see, the whole docstring is supposed to be changed to convert ''' to """. But only the first line of the new docstring is marked with +, the other 3 lines are not marked, ergo they are treated as context that should be equal in both files. Therefore the line count of the hunk does not fit anymore and the patching fails. 2) Also note that the last 3 lines got an extra whitespace in the beginning of the line. This is not present in the original file. 3) As a side-note: pyment creates an a/ and an b/ in the beginning of the paths of source and target of the patch. Note that these are not the actual folders of the files. I executed pyment in the folder of the file. Comparing with patches created from diff, I would guess that you could just omit this behavior.

I do not think it is of importance here, but note that I am using pyment on Windows 7.

patchfile (created running pyment __init__short.py in the same folder as __init__short.py)

# Patch generated by Pyment v0.3.0

--- a/__init__ short.py
+++ b/__init__ short.py
@@ -12,12 +12,7 @@

 def init_test():
-    '''
-    Only working when in WinPython root directory.
-    
-    Returns:
-    maske, data0, data1, no_motion, motion
-    '''
+    """Only working when in WinPython root directory.

    Returns:
    maske, data0, data1, no_motion, motion"""

     maske = read_mask('./MRR/Testdaten/55_mask.bmp')
     display(maske)
     data0 = read_dicom_set('./MRR/Testdaten/188_13-12-10_56_1',

original file:

# -*- coding: utf-8 -*-

__version__ = '1.3.1'
# $Source$

#Some commentary

from .mod1 import *
#import mod2
from . import mod3, mod4

def init_test():
    '''
    Only working when in WinPython root directory.

    Returns:
    maske, data0, data1, no_motion, motion
    '''
    maske = read_mask('./MRR/Testdaten/55_mask.bmp')
    display(maske)
    data0 = read_dicom_set('./MRR/Testdaten/188_13-12-10_56_1',
                               unwrap=True, mask=maske, verbose=False)
    data1 = read_dicom_set('./MRR/Testdaten/188_13-12-10_54_1',
                               unwrap=True, mask=maske, verbose=False)
    no_motion = mean(data0, axis=0)
    motion = mean(data1, axis=0)
    return maske , data0, data1, no_motion, motion

edit: files now reproduce the bug.

dadadel commented 9 years ago

Thank you @theilen for reporting this issue. Can you please provide the whole command that you run? What about the version number of Pyment and of Python? And can you confirm that the code above can as is produce the bug?

theilen commented 9 years ago

I updated my above report accordingly. Let me know if you need anything else.

dadadel commented 9 years ago

Hi @theilen! I'm sorry to be long to answer but I am quite busy. What is your input format? It seems to be a kind of Google/Numpydoc style format. And what is your expected output format? Anyway, if I run Pyment on your file and ask for reST, google or numpydoc format, it generates valid patches (but the return type is missing for the two last formats). Note that I tried it under Linux. Unfortunately I haven't Windows. I coded Pyment in order to be OS independent but I didn't try it under Windows. My apologies. I will try it as soon as I have access to a computer under Windows.

theilen commented 9 years ago

Hi @dadadel! My input format does not follow any predifined format. I wanted to use pyment to achieve a consistent doc-format. My impression was that pyment should be able to handle all input, I did not realize it expects already formatted code. I'm sorry if i misread your description!

As described above, I used pyment without any additional keywords, so I would expect it to create reStructured text.

I do not believe, that the problem is with me using windows. Since windows does not have a native way of dealing with patch-files, I used a ported version of unix's patch to test it. It should work just the same. Maybe the failure was just me and my unstructured input.

dadadel commented 7 years ago

Hi @theilen, Do you still have the problem ? I wasn't able to reproduce with your example.

dadadel commented 7 years ago

As there is nothing new and the test for the issue is ok, I close this issue.