heavenshell / vim-pydocstring

Generate Python docstring to your Python source code.
BSD 3-Clause "New" or "Revised" License
337 stars 53 forks source link

Unable to set custom template for docstring #85

Closed rohan-97 closed 4 years ago

rohan-97 commented 4 years ago

Hi @heavenshell ,

I wanted to add custom template for docstring. I followed template shown in Readme.rst

I copied contents from tests/templates/class.txt to another custom file (/root/.pydocstring/python_commenter.txt) Following are the contents my .vimrc

 " Store pydocstring path and template path
 nmap <silent> <C-_> <Plug>(pydocstring)
 let g:pydocstring_doq_path = '/usr/local/bin/doq'
 let g:pydocstring_templates_path = '/root/.pydocstring/python_commenter.txt'

Following are the contents and permission of python_commenter.txt

root@geek:~/source/ksa_tests# cat /root/.pydocstring/python_commenter.txt
"""{{ name }}.
"""
root@geek:~/source/ksa_tests# ls -l /root/.pydocstring/python_commenter.txt
-rw-r--r-- 1 root root 19 Mar 29 07:22 /root/.pydocstring/python_commenter.txt

However when I open Python file using vim and try to do :Pydocstring I get following error

Error detected while processing function <lambda>1[1]..<SNR>105_callback:
line    1:
E474: Invalid argument
E899: Argument of reverse() must be a List or Blob
E474: Invalid argument
E899: Argument of reverse() must be a List or Blob
E474: Invalid argument
E899: Argument of reverse() must be a List or Blob
E474: Invalid argument
E899: Argument of reverse() must be a List or Blob
E474: Invalid argument
E899: Argument of reverse() must be a List or Blob
E474: Invalid argument
E899: Argument of reverse() must be a List or Blob
E474: Invalid argument
E899: Argument of reverse() must be a List or Blob
E474: Invalid argument
E899: Argument of reverse() must be a List or Blob
E474: Invalid argument
E899: Argument of reverse() must be a List or Blob
E474: Invalid argument
E899: Argument of reverse() must be a List or Blob
E474: Invalid argument
E899: Argument of reverse() must be a List or Blob
E474: Invalid argument
E899: Argument of reverse() must be a List or Blob
E474: Invalid argument
E899: Argument of reverse() must be a List or Blob
E474: Invalid argument
E899: Argument of reverse() must be a List or Blob
E474: Invalid argument
E899: Argument of reverse() must be a List or Blob
E474: Invalid argument
E899: Argument of reverse() must be a List or Blob
E474: Invalid argument
E899: Argument of reverse() must be a List or Blob
E474: Invalid argument
E899: Argument of reverse() must be a List or Blob
E474: Invalid argument
E899: Argument of reverse() must be a List or Blob
E474: Invalid argument
-- More --

I searched for reverse in this repository and found one occurance in line 51 of /autoload/pydocstring.vim

Based on error, I think json_decode(a:msg) is not returning List or Blob, whereas reverse() requires List of Blob.

Please let me know whether this information was enough or you want some more information in order to reproduce this issue.

Or I am doing this in a wrong way.

Thanks!

heavenshell commented 4 years ago

@rohan-97 Thx for reporting.

  1. You should add three file.
    • class.txt
    • def.txt
    • noarg.txt
  2. File name should be class.txt, def.txt, noarg.txt

So, you may do

mv /root/.pydocstring/python_commenter.txt /root/.pydocstring/class.txt
cp /path/to/vim-pydocstring/tests/templates/def.txt /root/.pydocstring/def.txt
cp /path/to/vim-pydocstring/tests/templates/def.txt /root/.pydocstring/noarg.txt
alecandido commented 4 years ago
I also have a similar error.
Error detected while processing function <lambda>13[1]..<SNR>158_callback:
line    1:
E474: Invalid argument
E899: Argument of reverse() must be a List or Blob
E474: Invalid argument
E899: Argument of reverse() must be a List or Blob

It seems to happen always:

while the :PydocstringFormat works perfectly.

Do you have any idea?

heavenshell commented 4 years ago

@AleCandido Could you show me pydocstring vimrc settings?

alecandido commented 4 years ago

Yes:

let g:pydocstring_doq_path = '~/.local/bin/doq'
"let g:pydocstring_formatter = 'numpy'
"let g:pydocstring_templates_path = '~/correct/path'

and I tried also with the meaningful combinations of the commented lines.

heavenshell commented 4 years ago

@AleCandido Thx

Could you run following command at you shell?

cat foo.py | /path/to/doq --style=json --formatter=sphinx --omit=self,cls --indent=4 --ignore_exception
alecandido commented 4 years ago

If can be useful I also tried with the older releases (tags), but for 2.0.0 and 2.1.0 it is unable to find my doq installation, but I saw that in 2.2.0 you added this expand() to all the occurrences of g:pydocstring_doq_path, so I suppose it is because my path includes ~.

heavenshell commented 4 years ago

@AleCandido Yes, I fixed it ver 2.2.0 Could you update latest and try?

alecandido commented 4 years ago

I was already on the latest, now I'm back and I tried with cat, but the problem is that there is no --ignore-exception option in doq (my version is 0.4.1).

heavenshell commented 4 years ago

@AleCandido 0.4.1 is old. Lataset is 0.5.1. Could you update doq to latest?

alecandido commented 4 years ago

Sorry, I noticed just now that there is a new version of doq, so I upgraded, this is the output:

`foo.py`
def foo(x):
    pass

output:

[{"docstring": "    \"\"\"foo.\n\n    :param x:\n    \"\"\"", "start_col": 4, "start_lineno": 1, "end_col": 0, "end_lineno": 2}]
heavenshell commented 4 years ago

Good! So, what about run via pydocstring.vim?

alecandido commented 4 years ago

I don't know, I said that :PydocstringFormat is working great, so I was quite sure that doq is working as well, but the problem is :Pydocstring command itself, I don't know why (the exact error is reported above).

heavenshell commented 4 years ago

Humm strange. Could you record screencast(gif) and upload it to here? I can't reploduce.

I want to see steps.

alecandido commented 4 years ago

Even more strange: I am not able to reproduce anymore.

I was trying to record as you said, so I just installed terminalizer with yarn global add, and I started recording, while I was recording it worked, and since then it keeps working.

For sure I'm happy about this, and sorry about wasting your time, but I'm really puzzled about this change. For sure I was doing stuffs and manage system installations and so on, but they were decoupled from pydocstring and even vim, so I don't really know how it is possible.

Since I am not able to reproduce anymore I just give up for the time being, I will let you know if in the future I will come up with any idea, if you have suggestions I would be happy to make some other attempts.

Thank you for support, and for sure for your project :wink:.

heavenshell commented 4 years ago

No problem. Great to hear you can use pydocstring.vim! 🎉

rohan-97 commented 4 years ago

Hi @heavenshell ,

Thanks for quick reply and support. I tried your solution and it worked fine.

Thank You!

heavenshell commented 4 years ago

Great! your welcome!