Skip to content

Commit c9145c5

Browse files
committed
fix code style
1 parent a8a500d commit c9145c5

7 files changed

+136
-91
lines changed

docutils_readers_rep.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@
22
# Author: David Goodger <[email protected]>
33
# Copyright: This module has been placed in the public domain.
44

5-
"""
6-
Python Enhancement Proposal (REP) Reader.
7-
"""
5+
"""Python Enhancement Proposal (REP) Reader."""
86

97
__docformat__ = 'reStructuredText'
108

119

1210
from docutils.readers import standalone
13-
from docutils.transforms import references, misc, frontmatter
11+
from docutils.transforms import frontmatter
1412
import docutils_transforms_reps as reps
1513
from docutils.parsers import rst
1614

docutils_transforms_reps.py

+20-21
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,27 @@
1313

1414
__docformat__ = 'reStructuredText'
1515

16-
import sys
1716
import os
1817
import re
1918
import time
2019
from docutils import nodes, utils, languages
21-
from docutils import ApplicationError, DataError
22-
from docutils.transforms import Transform, TransformError
20+
from docutils import DataError
21+
from docutils.transforms import Transform
2322
from docutils.transforms import parts, references, misc
2423

2524

2625
class Headers(Transform):
2726

28-
"""
29-
Process fields in a REP's initial RFC-2822 header.
30-
"""
27+
"""Process fields in a REP's initial RFC-2822 header."""
3128

3229
default_priority = 360
3330

3431
rep_url = 'rep-%04d'
35-
rep_git_url = 'https://github.com/ros-infrastructure/rep/blob/master/rep-%04d.rst'
32+
rep_git_url = \
33+
'https://github.com/ros-infrastructure/rep/blob/master/rep-%04d.rst'
3634
rcs_keyword_substitutions = (
37-
(re.compile(r'\$' r'RCSfile: (.+),v \$$', re.IGNORECASE), r'\1'),
38-
(re.compile(r'\$[a-zA-Z]+: (.+) \$$'), r'\1'),)
35+
(re.compile(r'\$' r'RCSfile: (.+),v \$$', re.IGNORECASE), r'\1'),
36+
(re.compile(r'\$[a-zA-Z]+: (.+) \$$'), r'\1'),)
3937

4038
def apply(self):
4139
self.document.settings.rep_base_url = 'http://ros.org/reps/'
@@ -45,12 +43,12 @@ def apply(self):
4543
raise DataError('Document tree is empty.')
4644
header = self.document[0]
4745
if not isinstance(header, nodes.field_list) or \
48-
'rfc2822' not in header['classes']:
46+
'rfc2822' not in header['classes']:
4947
raise DataError('Document does not begin with an RFC-2822 '
5048
'header; it is not a REP.')
5149
rep = None
5250
for field in header:
53-
if field[0].astext().lower() == 'rep': # should be the first field
51+
if field[0].astext().lower() == 'rep': # should be the first field
5452
value = field[1].astext()
5553
try:
5654
rep = int(value)
@@ -94,8 +92,8 @@ def apply(self):
9492
% field.pformat(level=1))
9593
elif name == 'last-modified':
9694
date = time.strftime(
97-
'%d-%b-%Y',
98-
time.localtime(os.stat(self.document['source'])[8]))
95+
'%d-%b-%Y',
96+
time.localtime(os.stat(self.document['source'])[8]))
9997
if repo_url:
10098
body += nodes.paragraph(
10199
'', '', nodes.reference('', date, refuri=repo_url))
@@ -121,7 +119,7 @@ def apply(self):
121119
refuri=(self.document.settings.rep_base_url
122120
+ self.rep_url % repno)))
123121
newbody.append(space)
124-
para[:] = newbody[:-1] # drop trailing space
122+
para[:] = newbody[:-1] # drop trailing space
125123
elif name == 'last-modified':
126124
utils.clean_rcs_keywords(para, self.rcs_keyword_substitutions)
127125
if repo_url:
@@ -147,9 +145,11 @@ class Contents(Transform):
147145
def apply(self):
148146
try:
149147
#incompatible API change in docutils
150-
language = languages.get_language(self.document.settings.language_code, None)
148+
language = languages.get_language(
149+
self.document.settings.language_code, None)
151150
except TypeError:
152-
language = languages.get_language(self.document.settings.language_code )
151+
language = languages.get_language(
152+
self.document.settings.language_code)
153153
name = language.labels['contents']
154154
title = nodes.title('', name)
155155
topic = nodes.topic('', title, classes=['contents'])
@@ -215,11 +215,9 @@ def cleanup_callback(self, pending):
215215

216216
class REPZero(Transform):
217217

218-
"""
219-
Special processing for REP 0.
220-
"""
218+
"""Special processing for REP 0."""
221219

222-
default_priority =760
220+
default_priority = 760
223221

224222
def apply(self):
225223
visitor = REPZeroSpecial(self.document)
@@ -264,7 +262,7 @@ def visit_row(self, node):
264262

265263
def visit_entry(self, node):
266264
self.document.settings.rep_base_url = 'http://ros.org/reps/'
267-
265+
268266
self.entry += 1
269267
if self.rep_table and self.entry == 2 and len(node) == 1:
270268
node['classes'].append('num')
@@ -284,6 +282,7 @@ def visit_entry(self, node):
284282
285283
286284

285+
287286
def mask_email(ref, repno=None):
288287
"""
289288
Mask the email address in `ref` and return a replacement node.

genrepindex.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
3. Output the REP (both by category and numerical index).
1515
1616
"""
17-
from __future__ import absolute_import, with_statement
17+
from __future__ import absolute_import
18+
from __future__ import print_function
19+
from __future__ import with_statement
1820

1921
import sys
2022
import os
@@ -38,13 +40,16 @@ def main(argv):
3840
abs_file_path = os.path.join(path, file_path)
3941
if not os.path.isfile(abs_file_path):
4042
continue
41-
if file_path.startswith("rep-") and file_path.endswith(".rst") and not file_path == 'rep-0000.rst':
42-
with codecs.open(abs_file_path, 'r', encoding='UTF-8') as rep_file:
43+
if file_path.startswith("rep-") and \
44+
file_path.endswith(".rst") and \
45+
not file_path == 'rep-0000.rst':
46+
with codecs.open(
47+
abs_file_path, 'r', encoding='UTF-8') as rep_file:
4348
try:
4449
rep = REP(rep_file)
4550
if rep.number != int(file_path[4:-4]):
46-
raise REPError('REP number does not match file name',
47-
file_path, rep.number)
51+
raise REPError('REP number does not match file ' +
52+
'name', file_path, rep.number)
4853
reps.append(rep)
4954
except REPError as e:
5055
errmsg = "Error processing REP %s (%s), excluding:" % \

rep0/output.py

+23-12
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414

1515
indent = u' '
1616

17+
1718
def write_column_headers(output):
1819
"""Output the column headers for the REP indices."""
1920
column_headers = {'status': u'', 'type': u'', 'number': u'num',
20-
'title': u'title', 'authors': u'owner'}
21+
'title': u'title', 'authors': u'owner'}
2122
print(constants.column_format % column_headers, file=output)
2223
underline_headers = {}
2324
for key, value in column_headers.items():
@@ -26,8 +27,12 @@ def write_column_headers(output):
2627

2728

2829
def sort_reps(reps):
29-
"""Sort REPs into meta, informational, accepted, open, finished,
30-
and essentially dead."""
30+
"""
31+
Sort REPs into categories.
32+
33+
Current these categories include: meta, informational, accepted, open,
34+
finished, and essentially dead.
35+
"""
3136
meta = []
3237
info = []
3338
accepted = []
@@ -41,8 +46,8 @@ def sort_reps(reps):
4146
meta.append(rep)
4247
elif rep.status == 'Draft':
4348
open_.append(rep)
44-
elif rep.status in ('Rejected', 'Withdrawn', 'Deferred',
45-
'Incomplete', 'Replaced'):
49+
elif rep.status in [
50+
'Rejected', 'Withdrawn', 'Deferred', 'Incomplete', 'Replaced']:
4651
dead.append(rep)
4752
elif rep.type_ == 'Informational':
4853
info.append(rep)
@@ -99,6 +104,7 @@ def sort_authors(authors_dict):
99104
authors_list.sort(key=attrgetter('sort_by'))
100105
return authors_list
101106

107+
102108
def normalized_last_first(name):
103109
return len(unicodedata.normalize('NFC', name.last_first))
104110

@@ -125,7 +131,8 @@ def write_rep0(reps, output=sys.stdout):
125131
for rep in info:
126132
print(u'%s' % rep, file=output)
127133
print('', file=output)
128-
print(u" Accepted REPs (accepted; may not be implemented yet)", file=output)
134+
print(u" Accepted REPs (accepted; may not be implemented yet)",
135+
file=output)
129136
print('', file=output)
130137
for rep in accepted:
131138
print(u'%s' % rep, file=output)
@@ -135,7 +142,8 @@ def write_rep0(reps, output=sys.stdout):
135142
for rep in open_:
136143
print(u'%s' % rep, file=output)
137144
print('', file=output)
138-
print(u" Finished REPs (done, implemented in code repository)", file=output)
145+
print(u" Finished REPs (done, implemented in code repository)",
146+
file=output)
139147
print('', file=output)
140148
for rep in finished:
141149
print(u'%s' % rep, file=output)
@@ -172,15 +180,18 @@ def write_rep0(reps, output=sys.stdout):
172180
authors_dict = verify_email_addresses(reps)
173181
max_name = max(list(authors_dict.keys()), key=normalized_last_first)
174182
max_name_len = len(max_name.last_first)
175-
print(u" %s %s" % ('name'.ljust(max_name_len), 'email address'), file=output)
176-
print(u" %s %s" % ((len('name')*'-').ljust(max_name_len),
177-
len('email address')*'-'), file=output)
183+
print(u" %s %s" % ('name'.ljust(max_name_len), 'email address'),
184+
file=output)
185+
print(u" %s %s" %
186+
((len('name')*'-').ljust(max_name_len), len('email address')*'-'),
187+
file=output)
178188
sorted_authors = sort_authors(authors_dict)
179189
for author in sorted_authors:
180190
# Use the email from authors_dict instead of the one from 'author' as
181191
# the author instance may have an empty email.
182-
print((u" %s %s" %
183-
(author.last_first.ljust(max_name_len), authors_dict[author])), file=output)
192+
print(u" %s %s" %
193+
(author.last_first.ljust(max_name_len), authors_dict[author]),
194+
file=output)
184195
print('', file=output)
185196
print('', file=output)
186197
print(u"References", file=output)

rep0/rep.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ def sort_by(self):
8989
if part[0].isupper():
9090
break
9191
else:
92-
raise ValueError("last name missing a capital letter: %r"
93-
% name_parts)
92+
raise ValueError(
93+
"last name missing a capital letter: %r" % name_parts)
9494
base = u' '.join(name_parts[index:]).lower()
9595
return unicodedata.normalize('NFKD', base).encode('ASCII', 'ignore')
9696

@@ -121,7 +121,7 @@ def _last_name(self, full_name):
121121
class REP(object):
122122

123123
"""Representation of REPs.
124-
124+
125125
Attributes:
126126
127127
+ number : int
@@ -177,8 +177,7 @@ def __init__(self, rep_file):
177177
(header_name, current_header),
178178
rep_file.name)
179179
except StopIteration:
180-
raise REPError("headers missing or out of order",
181-
rep_file.name)
180+
raise REPError("headers missing or out of order", rep_file.name)
182181
required = False
183182
try:
184183
while not required:
@@ -232,9 +231,9 @@ def _parse_author(self, data):
232231
# Watch out for commas separating multiple names.
233232
regex += u'(,\s*)?'
234233
for match in re.finditer(regex, data):
235-
# Watch out for suffixes like 'Jr.' when they are comma-separated
236-
# from the name and thus cause issues when *all* names are only
237-
# separated by commas.
234+
# Watch out for suffixes like 'Jr.' when they are
235+
# comma-separated from the name and thus cause issues when
236+
# *all* names are only separated by commas.
238237
match_dict = match.groupdict()
239238
author = match_dict['author']
240239
if not author.partition(' ')[1] and author.endswith('.'):
@@ -280,9 +279,10 @@ def title_abbr(self):
280279

281280
def __str__(self):
282281
"""Return the line entry for the REP."""
283-
rep_info = {'type': self.type_abbr, 'number': str(self.number),
284-
'title': self.title_abbr, 'status': self.status_abbr,
285-
'authors': self.author_abbr}
282+
rep_info = {
283+
'type': self.type_abbr, 'number': str(self.number),
284+
'title': self.title_abbr, 'status': self.status_abbr,
285+
'authors': self.author_abbr}
286286
return constants.column_format % rep_info
287287

288288
def __unicode__(self):

0 commit comments

Comments
 (0)