@@ -18,10 +18,19 @@ class DocstyleDefinition:
18
18
Metadata = namedtuple ('Metadata' , ('param_start' , 'param_end' ,
19
19
'exception_start' , 'exception_end' ,
20
20
'return_sep' ))
21
+ ClassPadding = namedtuple ('ClassPadding' ,
22
+ ('top_padding' , 'bottom_padding' ))
23
+ FunctionPadding = namedtuple ('FunctionPadding' ,
24
+ ('top_padding' , 'bottom_padding' ))
25
+ DocstringTypeRegex = namedtuple ('DocstringTypeRegex' ,
26
+ ('class_sign' , 'func_sign' ))
21
27
22
28
@enforce_signature
23
29
def __init__ (self , language : str , docstyle : str , markers : (Iterable , str ),
24
- metadata : Metadata ):
30
+ metadata : Metadata , class_padding : ClassPadding ,
31
+ function_padding : FunctionPadding ,
32
+ docstring_type_regex : DocstringTypeRegex ,
33
+ docstring_position : str ):
25
34
"""
26
35
Instantiates a new DocstyleDefinition.
27
36
@@ -39,6 +48,18 @@ def __init__(self, language: str, docstyle: str, markers: (Iterable, str),
39
48
e.g. ``param_start`` defining the start symbol of
40
49
the parameter fields and ``param_end`` defining the
41
50
end.
51
+ :param class_padding: A namedtuple consisting of values about
52
+ blank lines before and after the documentation of
53
+ ``docstring_type`` class.
54
+ :param function_padding: A namedtuple consisting of values about
55
+ blank lines before and after the documentation of
56
+ ``docstring_type`` function.
57
+ :param docstring_type_regex: A namedtuple consisting of regex
58
+ about ``class`` and ``function`` of a language, which
59
+ is used to determine ``docstring_type`` of
60
+ DocumentationComment.
61
+ :param docstring_position: Defines the position where the regex of
62
+ docstring type is present(i.e. ``top`` or ``bottom``).
42
63
"""
43
64
self ._language = language .lower ()
44
65
self ._docstyle = docstyle .lower ()
@@ -58,6 +79,10 @@ def __init__(self, language: str, docstyle: str, markers: (Iterable, str),
58
79
'actually {}).' .format (length ))
59
80
60
81
self ._metadata = metadata
82
+ self ._class_padding = class_padding
83
+ self ._function_padding = function_padding
84
+ self ._docstring_type_regex = docstring_type_regex
85
+ self ._docstring_position = docstring_position
61
86
62
87
@property
63
88
def language (self ):
@@ -127,6 +152,48 @@ def metadata(self):
127
152
"""
128
153
return self ._metadata
129
154
155
+ @property
156
+ def class_padding (self ):
157
+ """
158
+ A namedtuple ``ClassPadding`` consisting of values about blank lines
159
+ before and after the documentation of ``docstring_type`` class.
160
+
161
+ These values are official standard of following blank lines before and
162
+ after the documentation of ``docstring_type`` class.
163
+ """
164
+ return self ._class_padding
165
+
166
+ @property
167
+ def function_padding (self ):
168
+ """
169
+ A namedtuple ``FunctionPadding`` consisting of values about blank
170
+ lines before and after the documentation of ``docstring_type``
171
+ function.
172
+
173
+ These values are official standard of following blank lines before and
174
+ after the documentation of ``docstring_type`` function.
175
+ """
176
+ return self ._function_padding
177
+
178
+ @property
179
+ def docstring_type_regex (self ):
180
+ """
181
+ A namedtuple ``DocstringTypeRegex`` consisting of regex about ``class``
182
+ and ``function`` of a language, which is used to determine
183
+ ``docstring_type`` of DocumentationComment.
184
+ """
185
+ return self ._docstring_type_regex
186
+
187
+ @property
188
+ def docstring_position (self ):
189
+ """
190
+ Defines the position, where the regex of docstring type is present.
191
+ Depending on different languages the docstrings are present below or
192
+ above the defined class or function. This expicitly defines where the
193
+ class regex or function regex is present(i.e. ``top`` or ``bottom``).
194
+ """
195
+ return self ._docstring_position
196
+
130
197
@classmethod
131
198
@enforce_signature
132
199
def load (cls , language : str , docstyle : str , coalang_dir = None ):
@@ -186,13 +253,44 @@ def load(cls, language: str, docstyle: str, coalang_dir=None):
186
253
metadata = cls .Metadata (* (str (docstyle_settings .get (req_setting , '' ))
187
254
for req_setting in metadata_settings ))
188
255
256
+ try :
257
+ class_padding = cls .ClassPadding (
258
+ * (int (padding ) for padding in tuple (
259
+ docstyle_settings ['class_padding' ])))
260
+ except IndexError :
261
+ class_padding = cls .ClassPadding ('' , '' )
262
+
263
+ try :
264
+ function_padding = cls .FunctionPadding (
265
+ * (int (padding ) for padding in tuple (
266
+ docstyle_settings ['function_padding' ])))
267
+ except IndexError :
268
+ function_padding = cls .FunctionPadding ('' , '' )
269
+
270
+ try :
271
+ docstring_type_regex = cls .DocstringTypeRegex (
272
+ * (str (sign ) for sign in tuple (
273
+ docstyle_settings ['docstring_type_regex' ])))
274
+ except IndexError :
275
+ docstring_type_regex = cls .DocstringTypeRegex ('' , '' )
276
+
277
+ try :
278
+ docstring_position = docstyle_settings ['docstring_position' ].value
279
+ except IndexError :
280
+ docstring_position = ''
281
+
282
+ ignore_keys = (('class_padding' , 'function_padding' ,
283
+ 'docstring_type_regex' , 'docstring_position' ) +
284
+ metadata_settings )
285
+
189
286
marker_sets = (tuple (value )
190
287
for key , value in
191
288
docstyle_settings .contents .items ()
192
- if key not in metadata_settings and
289
+ if key not in ignore_keys and
193
290
not key .startswith ('comment' ))
194
291
195
- return cls (language , docstyle , marker_sets , metadata )
292
+ return cls (language , docstyle , marker_sets , metadata , class_padding ,
293
+ function_padding , docstring_type_regex , docstring_position )
196
294
197
295
@staticmethod
198
296
def get_available_definitions ():
0 commit comments