Package: pymend
Create, update or convert docstrings in existing Python files, managing
several styles.Project StatusTest StatusSupported VersionsDescriptionCommand-line program to generate, update or transform docstrings python
source code.The app will parse the requested source files for docstrings as well as
function signatures and class bodies.This information is combined to build up complete docstrings for every
function and class including place holders for types and descriptions
where none could be found elsewhere.The output format of the docstrings can be chosen between google, numpy,
reST and epydoc. This means that the tool can also be used to transform
docstrings in the file from one format into another.Note however that not all section types are supported for all docstring
styles.Partially because they have not been added yet, but also because not
every style officially supports the sections from all others.To get further information please refer to thedocumentation.The tool offers the choice between generating patch files or directly
overwriting the python source files.Start quicklyinstall from PyPi$pipinstallpymendinstall from sources:$pipinstallgit+https://github.com/JanEricNitschke/pymend.gitor$gitclonehttps://github.com/JanEricNitschke/pymend.git$cdpymend$pythonsetup.pyinstallrun from the command line:$pymendmyfile.py# will generate a patch$pymend-wmyfile.py# will overwrite the fileget help:$pymend-hExampleTo see how pymend looks in action lets consider this example fileexample.py:"""_summary_."""defmy_func(param0,param01:int,param1:str="Some value",param2:List[str]={}):"""_summary_.

     Args:
         param0 (_type_): _description_
         param01 (int): _description_
         param1 (str, optional): _description_. Defaults to "Some value".
         param2 (List[str], optional): _description_. Defaults to {}.
     """passdefmy_single_return_func1()->str:"""_summary_.

     Returns
     -------
     int
         Wrong
     """passdefmy_multi_return_func()->Tuple[int,str,bool]:"""_summary_.

     Returns
     -------
     x :
         Some integer
     y : str
         Some string
     z : bool
         Some bool
     """passclassA:defmethod(self,param1,param2=None)->int:passNow let’s use Pyment:$pymentexample.pyThis produces the following patch fileexample.py.patch:# Patch generated by Pymend v1.0.10

--- a/example.py
+++ b/example.py
@@ -2,11 +2,16 @@
def my_func(param0, param01: int, param1: str = "Some value", param2: List[str] = {}):
   """_summary_.

-    Args:
-        param0 (_type_): _description_
-        param01 (int): _description_
-        param1 (str, optional): _description_. Defaults to "Some value".
-        param2 (List[str], optional): _description_. Defaults to {}.
+    Parameters
+    ----------
+    param0 : _type_
+        _description_
+    param01 : int
+        _description_
+    param1 : str
+        _description_. Defaults to "Some value".
+    param2 : List[str]
+        _description_. Defaults to {}.
   """
   pass

@@ -16,7 +21,7 @@

   Returns
   -------
-    int
+    str
         Wrong
   """
   pass
@@ -27,7 +32,7 @@

   Returns
   -------
-    x :
+    x : _type_
         Some integer
   y : str
         Some string
@@ -37,5 +42,21 @@
   pass

class A:
+    """_summary_.
+
+    Methods
+    -------
+    method(param1, param2=None)
+        _description_
+    """
   def method(self, param1, param2=None) -> int:
+        """_summary_.
+
+        Parameters
+        ----------
+        param1 : _type_
+            _description_
+        param2 : _type_
+            _description_ (Default value = None)
+        """
         passCalling pyment directly with$pyment--writeexample.pyprint outs this information about changed files$Modifieddocstringsofelements(my_func,my_single_return_func1,my_multi_return_func,A,method)infileexample.py.and results in the final file (the same we would have gotten when applying the patch):"""_summary_."""defmy_func(param0,param01:int,param1:str="Some value",param2:List[str]={}):"""_summary_.

   Parameters
   ----------
   param0 : _type_
      _description_
   param01 : int
      _description_
   param1 : str
      _description_. Defaults to "Some value".
   param2 : List[str]
      _description_. Defaults to {}.
   """passdefmy_single_return_func1()->str:"""_summary_.

   Returns
   -------
   str
      Wrong
   """passdefmy_multi_return_func()->Tuple[int,str,bool]:"""_summary_.

   Returns
   -------
   x : _type_
      Some integer
   y : str
      Some string
   z : bool
      Some bool
   """passclassA:"""_summary_.

   Methods
   -------
   method(param1, param2=None)
      _description_
   """defmethod(self,param1,param2=None)->int:"""_summary_.

      Parameters
      ----------
      param1 : _type_
            _description_
      param2 : _type_
            _description_ (Default value = None)
      """passPre-commitTo use pymend in apre-commithook just
add the following to your.pre-commit-config.yamlrepos:-repo:https://github.com/JanEricNitschke/pymendrev:"v1.0.10"hooks:-id:pymendlanguage:pythonargs:["--write","--check"]AcknowledgementsThis project was inspired by and is originally based uponpyment. The intended
functionality as well as the main entry point remain largerly unchanged.
However additional functionality has been added in the form of ast
traversal for extracting function and class information.The docstring parsing has been replaced completely with code taken from
the awesomedocstring_parserproject,
specificallythis
fork.So far only minor modifications have been made to the docstring parsing
functionality. Mainly the addition of the “Methods” section for numpydoc
style docstrings. Additionally the the code has been linted as well as
type hinted.The code for configuration and file handling as well as the structure of the documentation
is more or less taken directly fromblack.