Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make 'Google' the default docstring style for ALL projects PyCharm

I'm aware that I can go to Settings | Tools | Python Integrated Tools | Docstrings | Docstring format | Google, but this only sets the the docstring format for the current project (as indicated by the heading 'for current project' in the window). I'm looking for a way to change the default, so that all of my projects utilize the google docstring format by default.

JetBrain's own documentation makes no mention of how to accomplish this as far as I can tell.

like image 590
Mattwmaster58 Avatar asked Jan 25 '19 17:01

Mattwmaster58


People also ask

How do I change the style of a docstring in PyCharm?

Place the caret at the function name, and press Alt+Enter . In the list of intention actions that opens, choose Insert documentation string stub. PyCharm creates a documentation stub, according to the selected docstring format, with the type specification, collected during the debugger session.

What is the standard Python docstring format?

- reST. Nowadays, the probably more prevalent format is the reStructuredText (reST) format that is used by Sphinx to generate documentation. Note: it is used by default in JetBrains PyCharm (type triple quotes after defining a method and hit enter). It is also used by default as output format in Pyment.

How do you specify the docstring of a function?

Declaring Docstrings: The docstrings are declared using ”'triple single quotes”' or “””triple double quotes””” just below the class, method or function declaration. All functions should have a docstring.

Should every function have a docstring?

A docstring is a documentation string at the beginning of the class, function or function body that briefly explains how it works. Every function you create ought to have a docstring. They're in triple-quoted strings and allow for multi-line text.


2 Answers

This isn't possible to do at the moment. Please submit a feature request about it to https://youtrack.jetbrains.com/issues/PY

EDIT: The following ticket (mentioned below) is now in In Progress status https://youtrack.jetbrains.com/issue/PY-20243. According to Fix versions field, it should be implemented in 2019.3 version.

like image 87
Sergey K. Avatar answered Sep 20 '22 17:09

Sergey K.


At the time of this writing, it is not possible. Several tickets have been submitted over the past several years requesting this feature, presumably it is being worked on.

https://youtrack.jetbrains.com/issue/PY-33833

https://youtrack.jetbrains.com/issue/PY-20243

In the short run, if you need to convert previous projects from the default, you can find the setting is stored in the ".idea/MYPROJECT.iml" file:

  <component name="PyDocumentationSettings">
    <option name="myDocStringFormat" value="Google" />
  </component>

By default, there is no PyDocumentationSettings component, so you'll need to add it. In Linux, you could run the following (very hackish) code in terminal to change all projects in any subdirectory:

new_docstring='  <component name="PyDocumentationSettings">\n    <option name="myDocStringFormat" value="Google" />\n  </component>\n</module>'
find . -type f -name '*.iml' -print0 | xargs -0 sed -i "s|</module>|$new_docstring|g"

If you simply wanted to go from e.g. Numpy to Google, you might just use:

find . -type f -name '*.iml' -print0 | xargs -0 sed -i "s|Numpy|Google|g"
like image 23
Tahlor Avatar answered Sep 19 '22 17:09

Tahlor