Skip to content

Commit 5badb7d

Browse files
committed
STYLE: Apply pre-commit mechanical fixes across the tree
end-of-file/trailing-whitespace normalization, exec bits on shebang scripts, black and pyupgrade modernization of utility and example Python.
1 parent 290abfc commit 5badb7d

117 files changed

Lines changed: 225 additions & 230 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CMake/DownloadDoxygenTAG.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
file(DOWNLOAD https://github.com/InsightSoftwareConsortium/ITK/releases/download/v5.3.0/InsightDoxygenDocTag-5.3.0.gz
22
${ITKDoxygenTAG_TEMP_DIR}/InsightDoxygen.tag.gz SHOW_PROGRESS
33
)
4-

CMake/ITKDoxygen.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,3 @@ add_custom_command(OUTPUT ${ITKDoxygen_DIR}/index.html
1212

1313
add_custom_target(ITKDoxygen ${CMAKE_COMMAND} -E echo "Finished obtaining Doxygen"
1414
DEPENDS ${ITKDoxygen_DIR}/index.html)
15-

CMake/ITKDoxygenTAG.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,3 @@ add_custom_command(OUTPUT ${ITKDoxygenTAG_DIR}/InsightDoxygen.tag
1515
)
1616
add_custom_target(ITKDoxygenTAG ${CMAKE_COMMAND} -E echo "Finished obtaining Doxygen TAG"
1717
DEPENDS ${ITKDoxygenTAG_DIR}/InsightDoxygen.tag)
18-

Documentation/Build/index.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,4 +247,3 @@ VV
247247
.. _Qt: https://www.qt.io/developers/
248248
.. _VTK: https://vtk.org/
249249
.. _VV: https://www.creatis.insa-lyon.fr/rio/vv
250-

Documentation/Credits.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ Credits
66
:avatars:
77
:exclude: itkrobot
88
:limit: 100
9-
:order: DESC
9+
:order: DESC

Formatting/static/pace.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Formatting/templates/page.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@
3232
</p>
3333
{%- endif %}
3434
{{ body }}
35-
{% endblock %}
35+
{% endblock %}

Utilities/CookieCutter/hooks/post_gen_project.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
# limitations under the License.
1616

1717

18-
""" Post-generate cookiecutter hook script to incorporate the example to the
19-
ITKSphinxExamples source tree.
18+
"""Post-generate cookiecutter hook script to incorporate the example to the
19+
ITKSphinxExamples source tree.
2020
"""
2121

2222
import os
@@ -146,7 +146,7 @@ def print_instructions(itk_examples_src, example_dir, example_name, group_name):
146146
example_cxx = pjoin(example_dir, "Code.cxx")
147147
example_py = pjoin(example_dir, "Code.py")
148148

149-
print("Example {} added successfully!".format(example_name))
149+
print(f"Example {example_name} added successfully!")
150150

151151
print("Please:")
152152
print(" 1- Edit the following files:")

Utilities/CreateDownloadableArchive.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python
22

3-
""" Build archives for the examples.
3+
"""Build archives for the examples.
44
55
Build the .tar.gz and .zip for the example, and copy them along with the
66
supporting files into the html output.
@@ -56,7 +56,7 @@
5656
# archive CMakeLists.txt. This so the input images can be found.
5757
archive_cmakelist = os.path.join(example_dir, "CMakeLists.txt.archive")
5858
with open(archive_cmakelist, "w") as new_list_file:
59-
with open(os.path.join(example_dir, "CMakeLists.txt"), "r") as old_list_file:
59+
with open(os.path.join(example_dir, "CMakeLists.txt")) as old_list_file:
6060
for line in old_list_file:
6161
newline = line.replace(
6262
"CMAKE_CURRENT_BINARY_DIR", "CMAKE_CURRENT_SOURCE_DIR"

Utilities/CreateNewExample.py.in

Lines changed: 128 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
# limitations under the License.
1616

1717

18-
""" Script that uses cookiecutter to add a new example to the ITKSphinxExamples.
19-
Usage: python CreateNewExample.py
18+
"""Script that uses cookiecutter to add a new example to the ITKSphinxExamples.
19+
Usage: python CreateNewExample.py
2020
"""
2121

2222
import argparse
@@ -47,20 +47,22 @@ if sys.version_info[:2] <= (2, 7):
4747

4848
def write_all_itk_headers(itk_source_dir):
4949
output = StringIO()
50-
for root, dirs, files in os.walk(pjoin(itk_source_dir, 'Modules')):
51-
for f in fnmatch.filter(files, 'itk*.h'):
52-
output.write(f + u'\n')
50+
for root, dirs, files in os.walk(pjoin(itk_source_dir, "Modules")):
51+
for f in fnmatch.filter(files, "itk*.h"):
52+
output.write(f + "\n")
5353
return output
5454

55+
5556
def get_all_itk_headers(itk_source_dir):
5657
output = []
57-
for root, dirs, files in os.walk(pjoin(itk_source_dir, 'Modules')):
58-
for f in fnmatch.filter(files, 'itk*.h'):
58+
for root, dirs, files in os.walk(pjoin(itk_source_dir, "Modules")):
59+
for f in fnmatch.filter(files, "itk*.h"):
5960
output.append(f)
6061
return output
6162

63+
6264
def words(text):
63-
temp = re.findall('itk[A-Z][a-zA-Z_0-9]+', text)
65+
temp = re.findall("itk[A-Z][a-zA-Z_0-9]+", text)
6466
for i in range(len(temp)):
6567
var = temp[i]
6668
temp[i] = var[3:]
@@ -84,42 +86,92 @@ def edits1(word, alphabet):
8486
uppercases = [a + b[0].upper() + b[1:] for a, b in splits if b]
8587
all_lowercase = [word[:].lower()]
8688
one_uppercase = [
87-
a[:].lower() + b[0].upper() + b[1:].lower() for a, b in splits if b]
89+
a[:].lower() + b[0].upper() + b[1:].lower() for a, b in splits if b
90+
]
8891

8992
return set(
90-
deletes + transposes + replaces + inserts + lowercases + uppercases +
91-
all_lowercase + one_uppercase)
93+
deletes
94+
+ transposes
95+
+ replaces
96+
+ inserts
97+
+ lowercases
98+
+ uppercases
99+
+ all_lowercase
100+
+ one_uppercase
101+
)
92102

93103

94104
def known_edits2(word, NWORDS, alphabet):
95-
return set(e2 for e1 in edits1(word, alphabet)
96-
for e2 in edits1(e1, alphabet) if e2 in NWORDS)
105+
return {
106+
e2
107+
for e1 in edits1(word, alphabet)
108+
for e2 in edits1(e1, alphabet)
109+
if e2 in NWORDS
110+
}
97111

98112

99113
def known(words, NWORDS):
100-
return set(w for w in words if w in NWORDS)
114+
return {w for w in words if w in NWORDS}
101115

102116

103117
def itkcorrect(word, NWORDS, alphabet):
104118
candidates = (
105-
known([word], NWORDS) or
106-
known(edits1(word, alphabet), NWORDS) or
107-
known_edits2(word, NWORDS, alphabet) or [word])
119+
known([word], NWORDS)
120+
or known(edits1(word, alphabet), NWORDS)
121+
or known_edits2(word, NWORDS, alphabet)
122+
or [word]
123+
)
108124
return max(candidates, key=NWORDS.get)
109125

110126

111127
def space_out_camel_case(s):
112-
return re.sub('((?=[A-Z][a-z])|(?<=[a-z])(?=[A-Z]))', ' ', s).strip()
113-
114-
def itk_abbreviations(word,**kwargs):
115-
if word.upper() in ('ITK','VTK','RGB','VTP','FFT','FEM','TIFF','GMM','EM',
116-
'CV','GPU','BMP','CSV','DCMTK','GDCM','GE','GIPL','HDF5',
117-
'IPL','JPEG','JPEG2000','LSM','BYU','MINC','MRC','NIFTI',
118-
'NRRD','REC','PNG','RAW','XML','RTK','DICOM','2D','3D','IO'):
128+
return re.sub("((?=[A-Z][a-z])|(?<=[a-z])(?=[A-Z]))", " ", s).strip()
129+
130+
131+
def itk_abbreviations(word, **kwargs):
132+
if word.upper() in (
133+
"ITK",
134+
"VTK",
135+
"RGB",
136+
"VTP",
137+
"FFT",
138+
"FEM",
139+
"TIFF",
140+
"GMM",
141+
"EM",
142+
"CV",
143+
"GPU",
144+
"BMP",
145+
"CSV",
146+
"DCMTK",
147+
"GDCM",
148+
"GE",
149+
"GIPL",
150+
"HDF5",
151+
"IPL",
152+
"JPEG",
153+
"JPEG2000",
154+
"LSM",
155+
"BYU",
156+
"MINC",
157+
"MRC",
158+
"NIFTI",
159+
"NRRD",
160+
"REC",
161+
"PNG",
162+
"RAW",
163+
"XML",
164+
"RTK",
165+
"DICOM",
166+
"2D",
167+
"3D",
168+
"IO",
169+
):
119170
return word.upper()
120171

172+
121173
def get_group_and_module_from_class_name(itk_src, class_name):
122-
""" Get the ITK group and module a class belongs to.
174+
"""Get the ITK group and module a class belongs to.
123175
124176
Parameters
125177
----------
@@ -134,107 +186,118 @@ def get_group_and_module_from_class_name(itk_src, class_name):
134186
found, and the ITK group and module names found.
135187
"""
136188

137-
cmakefile = pjoin(itk_src, 'CMake', 'UseITK.cmake')
189+
cmakefile = pjoin(itk_src, "CMake", "UseITK.cmake")
138190
result = dict()
139-
result['bool'] = False
191+
result["bool"] = False
140192

141193
if class_name is None:
142194
return result
143195

144196
if not os.path.exists(cmakefile):
145-
print('Error: wrong path')
197+
print("Error: wrong path")
146198
else:
147-
path = ''
199+
path = ""
148200

149-
for root, dirs, files in os.walk(pjoin(itk_src, 'Modules')):
201+
for root, dirs, files in os.walk(pjoin(itk_src, "Modules")):
150202
for f in files:
151-
if f == 'itk' + class_name + '.h':
203+
if f == "itk" + class_name + ".h":
152204
path = root
153205

154206
if len(path) != 0:
155207

156208
temp = path.split(os.path.sep)
157209
depth = len(temp)
158210

159-
result['Module'] = temp[depth - 2]
160-
result['Group'] = temp[depth - 3]
161-
result['bool'] = True
211+
result["Module"] = temp[depth - 2]
212+
result["Group"] = temp[depth - 3]
213+
result["bool"] = True
162214

163215
else:
164-
print('Error: This class is not part of ITK: {}'.format(class_name))
216+
print(f"Error: This class is not part of ITK: {class_name}")
165217

166218
return result
167219

168220

169221
def main():
170222

171223
parser = argparse.ArgumentParser(
172-
description='Script to add a new example to the ITKSphinxExamples.')
224+
description="Script to add a new example to the ITKSphinxExamples."
225+
)
173226
args = parser.parse_args()
174227

175228
# Collect directories
176229

177230
# If no `ITK` directory is present in the ITKSphinxExamples build directory,
178231
# ITKSphinxExamples was not configured using the Superbuild functionality.
179-
itk_examples_binary_dir = os.path.abspath('@ITKSphinxExamples_BINARY_DIR@')
232+
itk_examples_binary_dir = os.path.abspath("@ITKSphinxExamples_BINARY_DIR@")
180233
itk_examples_build_dir = os.path.abspath(pjoin(itk_examples_binary_dir, os.pardir))
181-
itk_superbuild_dir = pjoin(itk_examples_build_dir, 'ITK')
234+
itk_superbuild_dir = pjoin(itk_examples_build_dir, "ITK")
182235
if not os.path.isdir(itk_superbuild_dir):
183236
# try to see if the ITK directory was setup manually and get the ITK directory from there:
184-
itk_dir = os.path.abspath('@ITK_CMAKE_DIR@')
237+
itk_dir = os.path.abspath("@ITK_CMAKE_DIR@")
185238
if not os.path.isdir(itk_dir):
186-
print('Error: ITKSphinxExamples must be configured using the Superbuild'
187-
'functionality to use this script or set ITK_DIR in cmake.')
239+
print(
240+
"Error: ITKSphinxExamples must be configured using the Superbuild"
241+
"functionality to use this script or set ITK_DIR in cmake."
242+
)
188243
sys.exit()
189244
itk_src = os.path.dirname(itk_dir)
190245
else:
191246
itk_src = itk_superbuild_dir
192247

193-
itk_examples_root_dir = os.path.abspath('@ITKSphinxExamples_SOURCE_DIR@')
248+
itk_examples_root_dir = os.path.abspath("@ITKSphinxExamples_SOURCE_DIR@")
194249
itk_examples_src = pjoin(itk_examples_root_dir, "src")
195250

196251
default_class_name = "MyClassName"
197252
default_example_name = "MyExample"
198253
default_synopsis = "MySynopsis"
199254

200255
# Prompt user for appropriate cookiecutter template variable values
201-
class_name = get_input("class_name [" + default_class_name + "]: ")\
202-
or default_class_name
203-
example_name = get_input("example_name [" + default_example_name + "]: ")\
204-
or default_example_name
205-
example_title = titlecase(space_out_camel_case(example_name), callback=itk_abbreviations)
206-
example_synopsis = get_input("example_synopsis [" + default_synopsis + "]: ")\
207-
or default_synopsis
256+
class_name = (
257+
get_input("class_name [" + default_class_name + "]: ") or default_class_name
258+
)
259+
example_name = (
260+
get_input("example_name [" + default_example_name + "]: ")
261+
or default_example_name
262+
)
263+
example_title = titlecase(
264+
space_out_camel_case(example_name), callback=itk_abbreviations
265+
)
266+
example_synopsis = (
267+
get_input("example_synopsis [" + default_synopsis + "]: ") or default_synopsis
268+
)
208269

209270
# Find the ITK module and group name
210271
itk_headers = write_all_itk_headers(itk_src)
211272

212273
NWORDS = train(words(itk_headers.getvalue()))
213274

214-
alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
275+
alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
215276

216277
temp_res = dict()
217-
temp_res['bool'] = False
278+
temp_res["bool"] = False
218279

219280
temp_res = get_group_and_module_from_class_name(itk_src, class_name)
220281

221-
while not temp_res['bool']:
282+
while not temp_res["bool"]:
222283
class_name = get_input("Please enter an ITK class name: ")
223284
class_name = itkcorrect(class_name, NWORDS, alphabet)
224285

225-
temp_res = get_group_and_module_from_class_name(
226-
itk_src, class_name)
286+
temp_res = get_group_and_module_from_class_name(itk_src, class_name)
227287

228-
group_name = temp_res['Group']
229-
module_name = temp_res['Module']
288+
group_name = temp_res["Group"]
289+
module_name = temp_res["Module"]
230290

231-
print('Found the following group and module for the provided class: {}'
232-
.format(class_name))
233-
print('Group name: {}'.format(group_name))
234-
print('Module name: {}'.format(module_name))
291+
print(
292+
"Found the following group and module for the provided class: {}".format(
293+
class_name
294+
)
295+
)
296+
print(f"Group name: {group_name}")
297+
print(f"Module name: {module_name}")
235298

236-
cookiecutter_dir = pjoin(os.path.abspath(os.path.dirname(__file__)), 'CookieCutter')
237-
cookiecutter_json = pjoin(cookiecutter_dir, 'cookiecutter.json')
299+
cookiecutter_dir = pjoin(os.path.abspath(os.path.dirname(__file__)), "CookieCutter")
300+
cookiecutter_json = pjoin(cookiecutter_dir, "cookiecutter.json")
238301

239302
data = dict()
240303
data["class_name"] = class_name
@@ -247,8 +310,8 @@ def main():
247310
data["itk_examples_src"] = itk_examples_src
248311

249312
if cookiecutter_json:
250-
with open(cookiecutter_json, 'w') as f:
251-
json.dump(data, f)
313+
with open(cookiecutter_json, "w") as f:
314+
json.dump(data, f)
252315

253316
# Call the cookiecutter
254317
cookiecutter(cookiecutter_dir, no_input=True)
@@ -257,5 +320,5 @@ def main():
257320
os.remove(cookiecutter_json)
258321

259322

260-
if __name__ == '__main__':
323+
if __name__ == "__main__":
261324
main()

0 commit comments

Comments
 (0)