Skip to content

Commit 9028bda

Browse files
authored
Merge pull request p12tic#74 from PeterFeicht/formatting
Preprocess: improve formatting
2 parents 0666258 + a719f65 commit 9028bda

File tree

6 files changed

+36
-36
lines changed

6 files changed

+36
-36
lines changed

commands/preprocess.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ def build_rename_map(root):
128128
if num > 0:
129129
name, ext = os.path.splitext(fn)
130130
# add file with its path -> only rename that occurrence
131-
result[os.path.join(dir, fn)] = "{}.{}{}".format(name, num + 1,
132-
ext)
131+
result[os.path.join(dir, fn)] = \
132+
"{}.{}{}".format(name, num + 1, ext)
133133
seen[low] += 1
134134

135135
return result
@@ -221,8 +221,8 @@ def trasform_relative_link(rename_map, target, file):
221221
new_fn = rename_map.get(fn)
222222
if new_fn:
223223
# look for case conflict of the renamed file
224-
abstarget = os.path.normpath(os.path.join(os.path.dirname(file),
225-
dir, new_fn))
224+
abstarget = os.path.normpath(
225+
os.path.join(os.path.dirname(file), dir, new_fn))
226226
new_fn = rename_map.get(abstarget, new_fn)
227227
else:
228228
# original filename unchanged, look for case conflict
@@ -240,7 +240,6 @@ def trasform_relative_link(rename_map, target, file):
240240
# file is the path of the file the link came from.
241241
# root is the path to the root of the archive.
242242
def transform_link(rename_map, target, file, root):
243-
244243
if is_loader_link(target):
245244
return transform_loader_link(target, file, root)
246245

commands/preprocess_cssless.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ def convert_span_table_to_tr_td(table_el):
163163
remove_css_property(table_el, 'display')
164164

165165
for element in table_el.getchildren():
166-
tag_renamed = convert_display_property_to_html_tag(element, 'tr',
167-
'table-row')
166+
tag_renamed = convert_display_property_to_html_tag(
167+
element, 'tr', 'table-row')
168168
if tag_renamed:
169169
if needs_td_wrapper(element):
170170
td = etree.Element('td')
@@ -176,8 +176,8 @@ def convert_span_table_to_tr_td(table_el):
176176
element.text = None
177177
else:
178178
for child in element:
179-
convert_display_property_to_html_tag(child, 'td',
180-
'table-cell')
179+
convert_display_property_to_html_tag(
180+
child, 'td', 'table-cell')
181181

182182

183183
def wrap_element(el, tag_name, style):

index2ddg.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,10 @@ def get_item_type(el):
7474
if el.get('link') == '.':
7575
return ITEM_TYPE_FUNCTION_INLINEMEM
7676
return ITEM_TYPE_FUNCTION
77-
78-
if el.tag == 'variable':
79-
if el.get('link') == '.':
80-
return ITEM_TYPE_VARIABLE_INLINEMEM
81-
return ITEM_TYPE_VARIABLE
77+
if el.tag == 'variable':
78+
if el.get('link') == '.':
79+
return ITEM_TYPE_VARIABLE_INLINEMEM
80+
return ITEM_TYPE_VARIABLE
8281
if el.tag == 'constructor':
8382
if el.get('link') == '.':
8483
return ITEM_TYPE_CONSTRUCTOR_INLINEMEM
@@ -145,7 +144,7 @@ def process_item_hook(self, el, full_name, full_link):
145144

146145
def get_html_files(root):
147146
files = []
148-
for dir, dirnames, filenames in os.walk(root):
147+
for dir, _, filenames in os.walk(root):
149148
for filename in fnmatch.filter(filenames, '*.html'):
150149
files.append(os.path.join(dir, filename))
151150
return files
@@ -207,8 +206,8 @@ def build_abstract(decls, desc, max_code_lines, split_code_lines,
207206
# limit the number of code snippets to be included so that total number
208207
# of lines is less than max_code_lines. The limit becomes active only
209208
# for the second and subsequent snippets.
210-
first = True if i == 0 else False
211-
last = True if i == len(decls)-1 else False
209+
first = (i == 0)
210+
last = (i == len(decls)-1)
212211

213212
if not first:
214213
if last:
@@ -424,31 +423,31 @@ def process_identifier(out, redirects, root, link, item_ident, item_type,
424423
elif item_type in [ITEM_TYPE_FUNCTION_INLINEMEM,
425424
ITEM_TYPE_CONSTRUCTOR_INLINEMEM,
426425
ITEM_TYPE_DESTRUCTOR_INLINEMEM]:
427-
raise DdgException("INLINEMEM") # not implemented
428426
''' Implementation notes:
429427
* the declarations are possibly versioned
430428
* declaration is selected from the member table
431429
* the member table is found according to the identifier
432430
(last part after :: is enough, hopefully)
433431
'''
432+
raise DdgException("INLINEMEM") # not implemented
434433

435434
elif item_type in [ITEM_TYPE_VARIABLE,
436435
ITEM_TYPE_VARIABLE_INLINEMEM,
437436
ITEM_TYPE_ENUM]:
438-
raise DdgException("ENUM") # not implemented
439437
''' Implementation notes:
440438
* the declarations are possibly versioned
441439
'''
440+
raise DdgException("ENUM") # not implemented
442441

443442
elif item_type == ITEM_TYPE_ENUM_CONST:
444-
raise DdgException("ENUM_CONST") # not implemented
445443
''' Implementation notes:
446444
* the abstract will come from the const -> definition table,
447445
which is always put before the first heading.
448446
* the declaration will come from the dcl template. We need
449447
to split the content at ';' and ',', then search for the
450448
name of the enum. If we find duplicates, signal an error.
451449
'''
450+
raise DdgException("ENUM_CONST") # not implemented
452451

453452
if debug.enabled:
454453
debug.debug_abstracts_file.write("--------------\n")

preprocess.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,11 @@ def main():
5151
file_list = preprocess.find_html_files(root)
5252

5353
with concurrent.futures.ProcessPoolExecutor() as executor:
54-
futures = [executor.submit(preprocess.preprocess_html_file, root, fn,
55-
rename_map)
56-
for fn in file_list]
54+
futures = [
55+
executor.submit(preprocess.preprocess_html_file,
56+
root, fn, rename_map)
57+
for fn in file_list
58+
]
5759

5860
for future in futures:
5961
output = future.result()

preprocess_qch.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,18 @@ def main():
5353
src_path = os.path.join(root, file)
5454
rel_path = os.path.relpath(src_path, source_root)
5555
dst_path = os.path.join(dest_root, rel_path)
56-
tuple = (src_path, dst_path)
57-
paths_list.append(tuple)
56+
paths_list.append((src_path, dst_path))
5857

5958
with concurrent.futures.ProcessPoolExecutor() as executor:
6059
futures = [
61-
(executor.submit(preprocess_cssless.preprocess_html_merge_cssless,
62-
src_path, dst_path),
63-
i)
64-
for i, (src_path, dst_path) in enumerate(paths_list)
60+
executor.submit(preprocess_cssless.preprocess_html_merge_cssless,
61+
src_path, dst_path)
62+
for src_path, dst_path in paths_list
6563
]
6664

67-
for future, i in futures:
68-
print('Processing file: {}/{}: {}'.format(i, len(paths_list),
69-
paths_list[i][1]))
65+
for i, future in enumerate(futures):
66+
print('Processing file: {}/{}: {}'.format(
67+
i, len(paths_list), paths_list[i][1]))
7068
output = future.result()
7169
if verbose:
7270
print(output)

tests/test_preprocess.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,10 @@ def test_transform_ranges_placeholder(self):
231231
'../algorithm/all_any_none_of.html'),
232232
]
233233

234+
def msg(target, file, root):
235+
return "target='{}', file='{}', root='{}'".format(
236+
target, file, root)
237+
234238
# transform_ranges_placeholder(target, file, root)
235239
# target: the placeholder link
236240
# file: path of the file that contains the link
@@ -239,14 +243,12 @@ def test_transform_ranges_placeholder(self):
239243
for target, file, expected in entries:
240244
res = transform_ranges_placeholder(target, file, root)
241245
self.assertEqual(expected, res,
242-
msg="target='{}', file='{}', root='{}'".format(
243-
target, file, root))
246+
msg=msg(target, file, root))
244247

245248
target = target.replace('http://', 'https://')
246249
res = transform_ranges_placeholder(target, file, root)
247250
self.assertEqual(expected, res,
248-
msg="target='{}', file='{}', root='{}'".format(
249-
target, file, root))
251+
msg=msg(target, file, root))
250252

251253

252254
class TestPreprocessHtml(unittest.TestCase):

0 commit comments

Comments
 (0)