Skip to content

Commit

Permalink
Allow to normalize leading and trailing white space as well as indent…
Browse files Browse the repository at this point in the history
…ation of doc strings
  • Loading branch information
witsch committed Sep 24, 2011
1 parent 0ae8c73 commit 4b8d9a5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 8 additions & 3 deletions PythonTidy.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@
MAX_SEPS_DICT = 3 # 2007 May 24
MAX_LINES_BEFORE_SPLIT_LIT = 2
LEFT_MARGIN = NULL
NORMALIZE_DOC_STRINGS = False
LEFTJUST_DOC_STRINGS = False
WRAP_DOC_STRINGS = False # 2007 May 25
DOUBLE_QUOTED_STRINGS = False # 2006 Dec 05
Expand Down Expand Up @@ -1926,14 +1927,18 @@ def fix_newlines(text): # 2010 Mar 10

doc = self.get_as_repr() # 2010 Mar 10
doc = doc.replace('\t', DOC_TAB_REPLACEMENT) # 2007 May 24
indent = self.indent
if NORMALIZE_DOC_STRINGS:
doc = '""" %s """' % doc.strip("'\"").strip()
indent += 1
if LEFTJUST_DOC_STRINGS:
lines = leftjust_lines(doc.strip().splitlines()) # 2007 May 25
lines.extend([NULL, NULL])
margin = '%s%s' % (OUTPUT.newline, INDENTATION * self.indent) # 2006 Dec 05
margin = '%s%s' % (OUTPUT.newline, INDENTATION * indent) # 2006 Dec 05
doc = margin.join(lines)
if WRAP_DOC_STRINGS: # 2007 May 25
margin = '%s%s' % (OUTPUT.newline, INDENTATION * self.indent) # 2006 Dec 05
line_length = COL_LIMIT - (len(INDENTATION) * self.indent)
margin = '%s%s' % (OUTPUT.newline, INDENTATION * indent) # 2006 Dec 05
line_length = COL_LIMIT - (len(INDENTATION) * indent)
line_length = max(line_length, 20)
lines = wrap_lines(doc.strip().splitlines(), width=line_length)
lines.extend([NULL, NULL])
Expand Down
2 changes: 2 additions & 0 deletions PythonTidyWrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ def from_pythontidy_namespace(self):
, 'int'),
('LEFT_MARGIN', 'This is how the left margin is to appear.'
),
('NORMALIZE_DOC_STRINGS',
'If true, normalize white space in doc strings.', 'bool'),
('LEFTJUST_DOC_STRINGS',
'If true, left justify doc strings.', 'bool'),
('WRAP_DOC_STRINGS',
Expand Down

0 comments on commit 4b8d9a5

Please sign in to comment.