Skip to content

Commit 6c31af9

Browse files
committed
STYLE: Consistently format python files with 'black' formatting
Reduce git diffs in future code modifications
1 parent 27e632c commit 6c31af9

14 files changed

Lines changed: 650 additions & 412 deletions

docs/code/CompareITKTypes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
import itk
44

5-
itk.F == itk.ctype('float') # True
5+
itk.F == itk.ctype("float") # True

docs/code/CreateBaseline.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
import itk
44
import sys
55

6-
image = itk.Image[itk.UC,2].New()
7-
image.SetRegions([10,10])
8-
image.SetOrigin([0,0])
9-
image.SetSpacing([0.5,0.5])
6+
image = itk.Image[itk.UC, 2].New()
7+
image.SetRegions([10, 10])
8+
image.SetOrigin([0, 0])
9+
image.SetSpacing([0.5, 0.5])
1010
image.Allocate()
1111
image.FillBuffer(1)
1212
itk.imwrite(image, sys.argv[1])

docs/code/ExplicitInstantiation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
# An apriori ImageType
99
PixelType = itk.F
10-
ImageType = itk.Image[PixelType,2]
10+
ImageType = itk.Image[PixelType, 2]
1111
image = itk.imread(input_filename, PixelType)
1212

1313
# An image type dynamically determined from the type on disk

docs/code/InstantiateITKObjects.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import itk
44

55
# Instantiate SmartPointer objects
6-
InputType = itk.Image[itk.F,3]
7-
OutputType = itk.Image[itk.F,3]
6+
InputType = itk.Image[itk.F, 3]
7+
OutputType = itk.Image[itk.F, 3]
88
median = itk.MedianImageFilter[InputType, OutputType].New()
99

1010
# Instantiate non-SmartPointer objects

docs/code/MixingITKAndNumPy.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
import sys
44
from pathlib import Path
55

6-
data_dir = Path(__file__).parent.resolve() / '..' / 'data'
6+
data_dir = Path(__file__).parent.resolve() / ".." / "data"
77

88
input_image_filename = sys.argv[1]
99
temp_dir = Path(input_image_filename).parent
1010
output_image_filename = sys.argv[2]
11-
input_mesh_filename = data_dir / 'cow.vtk'
12-
output_mesh_filename = temp_dir / 'cow.vtk'
13-
input_transform_filename = data_dir / 'rigid.tfm'
14-
output_transform_filename = temp_dir / 'rigid.tfm'
11+
input_mesh_filename = data_dir / "cow.vtk"
12+
output_mesh_filename = temp_dir / "cow.vtk"
13+
input_transform_filename = data_dir / "rigid.tfm"
14+
output_transform_filename = temp_dir / "rigid.tfm"
1515

1616
import itk
1717
import numpy as np
@@ -116,7 +116,7 @@
116116

117117

118118
# VNL matrix from np.ndarray
119-
arr = np.zeros([3,3], np.uint8)
119+
arr = np.zeros([3, 3], np.uint8)
120120
matrix = itk.vnl_matrix_from_array(arr)
121121

122122
# Array from VNL matrix

docs/code/test.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,20 @@
66
import tempfile
77
import shutil
88

9+
910
def add_test(cmd):
1011
cmd.insert(0, sys.executable)
1112
subprocess.check_call(cmd)
1213

14+
1315
def cleanup(files):
1416
for f in files:
1517
if os.path.isdir(f):
1618
shutil.rmtree(f)
1719
else:
1820
os.remove(f)
1921

22+
2023
# Create temporary folder to save output images
2124
temp_folder = tempfile.mkdtemp()
2225
# Change current working directory to find scripts

docs/conf.py

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
23
# -*- coding: utf-8 -*-
34
#
45
# ITKPythonPackage documentation build configuration file, created by
@@ -34,30 +35,30 @@
3435
extensions = []
3536

3637
# Add any paths that contain templates here, relative to this directory.
37-
templates_path = ['_templates']
38+
templates_path = ["_templates"]
3839

3940
# The suffix(es) of source filenames.
4041
# You can specify multiple suffix as a list of string:
4142
#
4243
# source_suffix = ['.rst', '.md']
43-
source_suffix = '.rst'
44+
source_suffix = ".rst"
4445

4546
# The master toctree document.
46-
master_doc = 'index'
47+
master_doc = "index"
4748

4849
# General information about the project.
49-
project = u'ITKPythonPackage'
50-
copyright = u'2017, Jean-Christophe Fillion-Robin and Matt McCormick'
51-
author = u'Jean-Christophe Fillion-Robin and Matt McCormick'
50+
project = "ITKPythonPackage"
51+
copyright = "2017, Jean-Christophe Fillion-Robin and Matt McCormick"
52+
author = "Jean-Christophe Fillion-Robin and Matt McCormick"
5253

5354
# The version info for the project you're documenting, acts as replacement for
5455
# |version| and |release|, also used in various other places throughout the
5556
# built documents.
5657
#
5758
# The short X.Y version.
58-
version = u''
59+
version = ""
5960
# The full version, including alpha/beta/rc tags.
60-
release = u''
61+
release = ""
6162

6263
# The language for content autogenerated by Sphinx. Refer to documentation
6364
# for a list of supported languages.
@@ -69,10 +70,10 @@
6970
# List of patterns, relative to source directory, that match files and
7071
# directories to ignore when looking for source files.
7172
# This patterns also effect to html_static_path and html_extra_path
72-
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
73+
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
7374

7475
# The name of the Pygments (syntax highlighting) style to use.
75-
pygments_style = 'sphinx'
76+
pygments_style = "sphinx"
7677

7778
# If true, `todo` and `todoList` produce output, else they produce nothing.
7879
todo_include_todos = False
@@ -83,7 +84,7 @@
8384
# The theme to use for HTML and HTML Help pages. See the documentation for
8485
# a list of builtin themes.
8586
#
86-
html_theme = 'default'
87+
html_theme = "default"
8788

8889
# Theme options are theme-specific and customize the look and feel of a theme
8990
# further. For a list of options available for each theme, see the
@@ -94,13 +95,13 @@
9495
# Add any paths that contain custom static files (such as style sheets) here,
9596
# relative to this directory. They are copied after the builtin static files,
9697
# so a file named "default.css" will overwrite the builtin "default.css".
97-
html_static_path = ['_static']
98+
html_static_path = ["_static"]
9899

99100

100101
# -- Options for HTMLHelp output ------------------------------------------
101102

102103
# Output file base name for HTML help builder.
103-
htmlhelp_basename = 'ITKPythonPackagedoc'
104+
htmlhelp_basename = "ITKPythonPackagedoc"
104105

105106

106107
# -- Options for LaTeX output ---------------------------------------------
@@ -109,15 +110,12 @@
109110
# The paper size ('letterpaper' or 'a4paper').
110111
#
111112
# 'papersize': 'letterpaper',
112-
113113
# The font size ('10pt', '11pt' or '12pt').
114114
#
115115
# 'pointsize': '10pt',
116-
117116
# Additional stuff for the LaTeX preamble.
118117
#
119118
# 'preamble': '',
120-
121119
# Latex figure (float) alignment
122120
#
123121
# 'figure_align': 'htbp',
@@ -127,8 +125,13 @@
127125
# (source start file, target name, title,
128126
# author, documentclass [howto, manual, or own class]).
129127
latex_documents = [
130-
(master_doc, 'ITKPythonPackage.tex', u'ITKPythonPackage Documentation',
131-
u'Jean-Christophe Fillion-Robin and Matt McCormick', 'manual'),
128+
(
129+
master_doc,
130+
"ITKPythonPackage.tex",
131+
"ITKPythonPackage Documentation",
132+
"Jean-Christophe Fillion-Robin and Matt McCormick",
133+
"manual",
134+
),
132135
]
133136

134137

@@ -137,8 +140,7 @@
137140
# One entry per manual page. List of tuples
138141
# (source start file, name, description, authors, manual section).
139142
man_pages = [
140-
(master_doc, 'itkpythonpackage', u'ITKPythonPackage Documentation',
141-
[author], 1)
143+
(master_doc, "itkpythonpackage", "ITKPythonPackage Documentation", [author], 1)
142144
]
143145

144146

@@ -148,19 +150,25 @@
148150
# (source start file, target name, title, author,
149151
# dir menu entry, description, category)
150152
texinfo_documents = [
151-
(master_doc, 'ITKPythonPackage', u'ITKPythonPackage Documentation',
152-
author, 'ITKPythonPackage', 'One line description of project.',
153-
'Miscellaneous'),
153+
(
154+
master_doc,
155+
"ITKPythonPackage",
156+
"ITKPythonPackage Documentation",
157+
author,
158+
"ITKPythonPackage",
159+
"One line description of project.",
160+
"Miscellaneous",
161+
),
154162
]
155163

156164

157165
# -- Read The Docs -----------------------------------------------------
158166

159167
# on_rtd is whether we are on readthedocs.io
160-
on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
168+
on_rtd = os.environ.get("READTHEDOCS", None) == "True"
161169

162170
if not on_rtd: # only import and set the theme if we're building docs locally
163171
import sphinx_rtd_theme
164-
html_theme = 'sphinx_rtd_theme'
165-
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
166172

173+
html_theme = "sphinx_rtd_theme"
174+
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]

itkVersion.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
VERSION = '6.0b1'
1+
VERSION = "6.0b1"
2+
23

34
def get_versions():
45
"""Returns versions for the ITK Python package.
@@ -20,6 +21,6 @@ def get_versions():
2021
get_versions()['package-version']
2122
"""
2223
versions = {}
23-
versions['version'] = VERSION
24-
versions['package-version'] = VERSION.split('+')[0]
24+
versions["version"] = VERSION
25+
versions["package-version"] = VERSION.split("+")[0]
2526
return versions

scripts/internal/wheel_builder_utils.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
"""This module provides convenient function facilitating scripting.
32
43
These functions have been copied from scikit-build project.
@@ -29,8 +28,7 @@ def mkdir_p(path):
2928

3029
@contextmanager
3130
def push_env(**kwargs):
32-
"""This context manager allow to set/unset environment variables.
33-
"""
31+
"""This context manager allow to set/unset environment variables."""
3432
saved_env = dict(os.environ)
3533
for var, value in kwargs.items():
3634
if value is not None:
@@ -39,7 +37,7 @@ def push_env(**kwargs):
3937
del os.environ[var]
4038
yield
4139
os.environ.clear()
42-
for (saved_var, saved_value) in saved_env.items():
40+
for saved_var, saved_value in saved_env.items():
4341
os.environ[saved_var] = saved_value
4442

4543

@@ -62,12 +60,13 @@ def __call__(self, func):
6260
def inner(*args, **kwds): # pylint:disable=missing-docstring
6361
with self:
6462
return func(*args, **kwds)
63+
6564
return inner
6665

6766

6867
class push_dir(ContextDecorator):
69-
"""Context manager to change current directory.
70-
"""
68+
"""Context manager to change current directory."""
69+
7170
def __init__(self, directory=None, make_directory=False):
7271
"""
7372
:param directory:
@@ -81,7 +80,8 @@ def __init__(self, directory=None, make_directory=False):
8180
self.make_directory = None
8281
self.old_cwd = None
8382
super(push_dir, self).__init__(
84-
directory=directory, make_directory=make_directory)
83+
directory=directory, make_directory=make_directory
84+
)
8585

8686
def __enter__(self):
8787
self.old_cwd = os.getcwd()

scripts/internal/windows_build_common.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__all__ = ['DEFAULT_PY_ENVS', 'venv_paths']
1+
__all__ = ["DEFAULT_PY_ENVS", "venv_paths"]
22

33
from subprocess import check_call
44
import os
@@ -9,6 +9,7 @@
99
SCRIPT_DIR = os.path.dirname(__file__)
1010
ROOT_DIR = os.path.abspath(os.path.join(SCRIPT_DIR, "..", ".."))
1111

12+
1213
def venv_paths(python_version):
1314

1415
# Create venv
@@ -44,9 +45,11 @@ def venv_paths(python_version):
4445
# Update PATH
4546
path = os.path.join(venv_dir, "Scripts")
4647

47-
return python_executable, \
48-
python_include_dir, \
49-
python_library, \
50-
pip, \
51-
ninja_executable, \
52-
path
48+
return (
49+
python_executable,
50+
python_include_dir,
51+
python_library,
52+
pip,
53+
ninja_executable,
54+
path,
55+
)

0 commit comments

Comments
 (0)