Skip to content

Commit bbaa1a5

Browse files
authored
Merge pull request #19 from adambullmer/tests
Added style tests to the project.
2 parents 082968f + 8d495d0 commit bbaa1a5

File tree

18 files changed

+335
-106
lines changed

18 files changed

+335
-106
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
*.sublime-package
1+
.tox
2+
*.sublime-package

DocblockrPython.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
"""DocBlockr for Python.
2+
3+
Author: Adam Bullmer <[email protected]>
4+
Website: https://github.com/adambullmer/sublime-docblockr-python
5+
6+
Credit to `spadgos` and the team at DocBlockr for providing some source code
7+
to support this project
8+
"""
19
import sublime
210

311
from .formatters.registry import populate_registry
@@ -12,4 +20,4 @@ def plugin_loaded():
1220
global plugin_is_loaded
1321
plugin_is_loaded = True
1422

15-
window = sublime.active_window()
23+
sublime.active_window()

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include requirements.txt

commands.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
"""
2-
DocBlockr Python v1.3.0
1+
"""DocBlockr for Python.
32
43
Author: Adam Bullmer <[email protected]>
54
Website: https://github.com/adambullmer/sublime-docblockr-python
@@ -8,9 +7,10 @@
87
to support this project
98
"""
109
import logging
10+
import re
11+
1112
import sublime
1213
import sublime_plugin
13-
import re
1414

1515
from .formatters.utils import get_formatter, get_setting
1616
from .parsers.parser import get_parser
@@ -19,7 +19,7 @@
1919

2020

2121
def write(view, string):
22-
"""Writes a string to the view as a snippet.
22+
"""Write a string to the view as a snippet.
2323
2424
Arguments:
2525
view {sublime.View} -- view to have content written to
@@ -30,7 +30,7 @@ def write(view, string):
3030

3131

3232
def escape(string):
33-
"""Escapes the special characters.
33+
r"""Escape the special characters.
3434
3535
Escapes characters that are also in snippet tab fields so that inserting into the view
3636
doesn't accidentally create another tabbable field
@@ -65,6 +65,7 @@ class DocblockrPythonCommand(sublime_plugin.TextCommand):
6565
line {String}
6666
contents {String}
6767
"""
68+
6869
position = 0
6970
trailing_rgn = ''
7071
trailing_string = ''
@@ -77,7 +78,7 @@ class DocblockrPythonCommand(sublime_plugin.TextCommand):
7778
project_settings = None
7879

7980
def run(self, edit):
80-
"""Sublime Command Entrypoint
81+
"""Sublime Command Entrypoint.
8182
8283
Entrypoint for the Sublime Text Command. Outputs the result of the parsing to
8384
the view.
@@ -130,6 +131,17 @@ def initialize(self, view):
130131
log.debug('contents -- {}'.format(self.contents))
131132

132133
def create_snippet(self, parsed_attributes):
134+
"""Format a Sublime Text snippet syntax string.
135+
136+
Iterates through the list of field groups, and then through each item
137+
in the group to create the snippets using the user specified formatter.
138+
139+
Arguments:
140+
parsed_attributes {dict} -- key value of attributes groups
141+
142+
Returns:
143+
str -- sublime text formatted snippet string
144+
"""
133145
project_formatter = self.project_settings.get('formatter', None)
134146
formatter = get_formatter(project_formatter or get_setting('formatter'))()
135147

formatters/PEP0257.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
1+
"""Default Formatter for PEP-257."""
12
from .base import Base
23

34

45
class Pep0257Formatter(Base):
6+
"""Documentation Formatter Class."""
7+
58
name = 'PEP0257'
69

710
def decorators(self, attributes):
11+
"""Create snippet string for a list of decorators."""
812
return ''
913

1014
def extends(self, attributes):
15+
"""Create snippet string for a list of extended objects."""
1116
return ''
1217

1318
def arguments(self, attributes):
19+
"""Create snippet string for a list of arguments."""
1420
section = '\nArguments:\n'
1521
template = '\t{name} -- {description}\n'
1622

@@ -28,6 +34,7 @@ def arguments(self, attributes):
2834
return section
2935

3036
def keyword_arguments(self, attributes):
37+
"""Create snippet string for a list of keyword arguments."""
3138
section = '\nKeyword arguments:\n'
3239
template = '\t{name} -- {description} (default: {{{default}}})\n'
3340

@@ -44,12 +51,15 @@ def keyword_arguments(self, attributes):
4451
return section
4552

4653
def returns(self, attribute):
54+
"""Create snippet string for a list of return values."""
4755
return ''
4856

4957
def yields(self, attribute):
58+
"""Create snippet string for a list of yielded results."""
5059
return ''
5160

5261
def raises(self, attributes):
62+
"""Create snippet string for a list of raiased exceptions."""
5363
section = '\n'
5464
template = 'Raises a {{{attribute}}} ${{{tab_index_1}:[description]}}\n'
5565

@@ -62,6 +72,7 @@ def raises(self, attributes):
6272
return section
6373

6474
def variables(self, attributes):
75+
"""Create snippet string for a list of variables."""
6576
section = '\nVariables:\n'
6677
template = '\t{name} -- {description}\n'
6778

formatters/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Default documentation formatting classes."""

formatters/base.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
"""Base formatter class."""
12
from abc import abstractmethod, ABCMeta
23

34
from .registry import register
45

6+
57
def counter():
68
"""Simple Iteratable Counter.
79
@@ -18,12 +20,14 @@ def counter():
1820

1921

2022
class FormatterMeta(ABCMeta):
21-
"""Registers the class in the formatter
23+
"""Register the class in the formatter.
2224
2325
Extends:
2426
ABCMeta
2527
"""
28+
2629
def __new__(mcs, classname, bases, attributes):
30+
"""---."""
2731
newclass = super(FormatterMeta, mcs).__new__(mcs, classname, bases, attributes)
2832
register(newclass)
2933
return newclass
@@ -51,10 +55,12 @@ class Base(metaclass=FormatterMeta):
5155
tab_index {generator} -- Provides a simple count generator for convenience
5256
in making tabbable fields
5357
"""
58+
5459
name = None
5560
tab_index = counter()
5661

5762
def __dict__(self):
63+
"""---."""
5864
return {
5965
'summary': self.summary,
6066
'description': self.description,
@@ -69,11 +75,12 @@ def __dict__(self):
6975
}
7076

7177
def __iter__(self):
78+
"""---."""
7279
for attr, value in self.__dict__().items():
7380
yield attr, value
7481

7582
def _generate_field(self, name, value=None):
76-
"""Makes Sublime Text snippet fields.
83+
"""Make a Sublime Text snippet field.
7784
7885
If a value is passed and it is not None, it will be returned. Otherwise,
7986
this will generate a snippet field in the next tabbable index.
@@ -96,65 +103,85 @@ def _generate_field(self, name, value=None):
96103
)
97104

98105
def summary(self):
106+
"""Create snippet string for the summary line."""
99107
return '{}'.format(self._generate_field('summary'))
100108

101109
def description(self):
110+
"""Create snippet string for the description body."""
102111
return '\n\n{}\n'.format(self._generate_field('description'))
103112

104113
@abstractmethod
105114
def decorators(self, attributes):
115+
"""Create snippet string for a list of decorators."""
106116
return ''
107117

108118
@abstractmethod
109119
def extends(self, attributes):
120+
"""Create snippet string for a list of extended objects."""
110121
return ''
111122

112123
@abstractmethod
113124
def arguments(self, attributes):
125+
"""Create snippet string for a list of arguments."""
114126
return ''
115127

116128
@abstractmethod
117129
def keyword_arguments(self, attributes):
130+
"""Create snippet string for a list of keyword arguments."""
118131
return ''
119132

120133
@abstractmethod
121134
def returns(self, attribute):
135+
"""Create snippet string for a list of return values."""
122136
return ''
123137

124138
@abstractmethod
125139
def yields(self, attribute):
140+
"""Create snippet string for a list of yielded results."""
126141
return ''
127142

128143
@abstractmethod
129144
def raises(self, attributes):
145+
"""Create snippet string for a list of raiased exceptions."""
130146
return ''
131147

132148
@abstractmethod
133149
def variables(self, attributes):
150+
"""Create snippet string for a list of variables."""
134151
return ''
135152

136153

137154
class BaseFormatter(Base):
155+
"""Documentation Formatter Class."""
156+
138157
def decorators(self, attributes):
158+
"""Create snippet string for a list of decorators."""
139159
return '{}\n'.format(self._generate_field('decorators'))
140160

141161
def extends(self, attributes):
162+
"""Create snippet string for a list of extended objects."""
142163
return '{}\n'.format(self._generate_field('extends'))
143164

144165
def arguments(self, attributes):
166+
"""Create snippet string for a list of arguments."""
145167
return '{}\n'.format(self._generate_field('arguments'))
146168

147169
def keyword_arguments(self, attributes):
170+
"""Create snippet string for a list of keyword arguments."""
148171
return '{}\n'.format(self._generate_field('keyword arguments'))
149172

150173
def returns(self, attribute):
174+
"""Create snippet string for a list of return values."""
151175
return '{}\n'.format(self._generate_field('returns'))
152176

153177
def yields(self, attribute):
178+
"""Create snippet string for a list of yielded results."""
154179
return '{}\n'.format(self._generate_field('yields'))
155180

156181
def raises(self, attributes):
182+
"""Create snippet string for a list of raiased exceptions."""
157183
return '{}\n'.format(self._generate_field('raises'))
158184

159185
def variables(self, attributes):
186+
"""Create snippet string for a list of variables."""
160187
return '{}\n'.format(self._generate_field('variables'))

formatters/docblock.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
"""Default Formatter for DocBlock."""
12
from .base import Base
23

34

45
class DocblockFormatter(Base):
6+
"""Documentation Formatter Class."""
7+
58
name = 'docblock'
69

710
def decorators(self, attributes):
11+
"""Create snippet string for a list of decorators."""
812
section = '\nDecorators:\n'
913
template = '\t{}\n'
1014

@@ -14,6 +18,7 @@ def decorators(self, attributes):
1418
return section
1519

1620
def extends(self, attributes):
21+
"""Create snippet string for a list of extended objects."""
1722
section = '\nExtends:\n'
1823
template = '\t{}\n'
1924

@@ -23,6 +28,7 @@ def extends(self, attributes):
2328
return section
2429

2530
def arguments(self, attributes):
31+
"""Create snippet string for a list of arguments."""
2632
section = '\nArguments:\n'
2733
template = '\t{name} {{{type}}} -- {description}\n'
2834

@@ -41,6 +47,7 @@ def arguments(self, attributes):
4147
return section
4248

4349
def keyword_arguments(self, attributes):
50+
"""Create snippet string for a list of keyword arguments."""
4451
section = '\nKeyword Arguments:\n'
4552
template = '\t{name} {{{type}}} -- {description} (default: {{{default}}})\n'
4653

@@ -58,6 +65,7 @@ def keyword_arguments(self, attributes):
5865
return section
5966

6067
def returns(self, attribute):
68+
"""Create snippet string for a list of return values."""
6169
section = '\nReturns:\n'
6270
template = '\t{type} -- {description}\n'
6371

@@ -69,6 +77,7 @@ def returns(self, attribute):
6977
return section
7078

7179
def yields(self, attribute):
80+
"""Create snippet string for a list of yielded results."""
7281
section = '\nYields:\n'
7382
template = '\t{type} -- {description}\n'
7483

@@ -80,6 +89,7 @@ def yields(self, attribute):
8089
return section
8190

8291
def raises(self, attributes):
92+
"""Create snippet string for a list of raiased exceptions."""
8393
section = '\nRaises:\n'
8494
template = '\t{name} -- {description}\n'
8595

@@ -92,6 +102,7 @@ def raises(self, attributes):
92102
return section
93103

94104
def variables(self, attributes):
105+
"""Create snippet string for a list of variables."""
95106
section = '\nVariables:\n'
96107
template = '\t{name} {{{type}}} -- {description}\n'
97108

0 commit comments

Comments
 (0)