Skip to content

Commit 2b069bf

Browse files
committed
chore: Run black + isort with string normalization (one time diff)
1 parent e505308 commit 2b069bf

File tree

47 files changed

+1896
-1898
lines changed

Some content is hidden

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

47 files changed

+1896
-1898
lines changed

docs/_ext/aafig.py

+45-45
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
logger = logging.getLogger(__name__)
3434

35-
DEFAULT_FORMATS = dict(html='svg', latex='pdf', text=None)
35+
DEFAULT_FORMATS = dict(html="svg", latex="pdf", text=None)
3636

3737

3838
def merge_dict(dst, src):
@@ -42,17 +42,17 @@ def merge_dict(dst, src):
4242
return dst
4343

4444

45-
def get_basename(text, options, prefix='aafig'):
45+
def get_basename(text, options, prefix="aafig"):
4646
options = options.copy()
47-
if 'format' in options:
48-
del options['format']
47+
if "format" in options:
48+
del options["format"]
4949
hashkey = text + str(options)
50-
id = sha(hashkey.encode('utf-8')).hexdigest()
51-
return '%s-%s' % (prefix, id)
50+
id = sha(hashkey.encode("utf-8")).hexdigest()
51+
return "%s-%s" % (prefix, id)
5252

5353

5454
class AafigError(SphinxError):
55-
category = 'aafig error'
55+
category = "aafig error"
5656

5757

5858
class AafigDirective(images.Image):
@@ -76,22 +76,22 @@ class AafigDirective(images.Image):
7676

7777
def run(self):
7878
aafig_options = dict()
79-
own_options_keys = [self.own_option_spec.keys()] + ['scale']
79+
own_options_keys = [self.own_option_spec.keys()] + ["scale"]
8080
for (k, v) in self.options.items():
8181
if k in own_options_keys:
8282
# convert flags to booleans
8383
if v is None:
8484
v = True
8585
# convert percentage to float
86-
if k == 'scale' or k == 'aspect':
86+
if k == "scale" or k == "aspect":
8787
v = float(v) / 100.0
8888
aafig_options[k] = v
8989
del self.options[k]
90-
self.arguments = ['']
90+
self.arguments = [""]
9191
(image_node,) = images.Image.run(self)
9292
if isinstance(image_node, nodes.system_message):
9393
return [image_node]
94-
text = '\n'.join(self.content)
94+
text = "\n".join(self.content)
9595
image_node.aafig = dict(options=aafig_options, text=text)
9696
return [image_node]
9797

@@ -101,45 +101,45 @@ def render_aafig_images(app, doctree):
101101
merge_dict(format_map, DEFAULT_FORMATS)
102102
if aafigure is None:
103103
logger.warn(
104-
'aafigure module not installed, ASCII art images '
105-
'will be redered as literal text'
104+
"aafigure module not installed, ASCII art images "
105+
"will be redered as literal text"
106106
)
107107
for img in doctree.traverse(nodes.image):
108-
if not hasattr(img, 'aafig'):
108+
if not hasattr(img, "aafig"):
109109
continue
110110
if aafigure is None:
111111
continue
112-
options = img.aafig['options']
113-
text = img.aafig['text']
112+
options = img.aafig["options"]
113+
text = img.aafig["text"]
114114
format = app.builder.format
115115
merge_dict(options, app.builder.config.aafig_default_options)
116116
if format in format_map:
117-
options['format'] = format_map[format]
117+
options["format"] = format_map[format]
118118
else:
119119
logger.warn(
120120
'unsupported builder format "%s", please '
121-
'add a custom entry in aafig_format config '
122-
'option for this builder' % format
121+
"add a custom entry in aafig_format config "
122+
"option for this builder" % format
123123
)
124124
img.replace_self(nodes.literal_block(text, text))
125125
continue
126-
if options['format'] is None:
126+
if options["format"] is None:
127127
img.replace_self(nodes.literal_block(text, text))
128128
continue
129129
try:
130130
fname, outfn, id, extra = render_aafigure(app, text, options)
131131
except AafigError as exc:
132-
logger.warn('aafigure error: ' + str(exc))
132+
logger.warn("aafigure error: " + str(exc))
133133
img.replace_self(nodes.literal_block(text, text))
134134
continue
135-
img['uri'] = fname
135+
img["uri"] = fname
136136
# FIXME: find some way to avoid this hack in aafigure
137137
if extra:
138138
(width, height) = [x.split('"')[1] for x in extra.split()]
139-
if 'width' not in img:
140-
img['width'] = width
141-
if 'height' not in img:
142-
img['height'] = height
139+
if "width" not in img:
140+
img["width"] = width
141+
if "height" not in img:
142+
img["height"] = height
143143

144144

145145
def render_aafigure(app, text, options):
@@ -148,36 +148,36 @@ def render_aafigure(app, text, options):
148148
"""
149149

150150
if aafigure is None:
151-
raise AafigError('aafigure module not installed')
151+
raise AafigError("aafigure module not installed")
152152

153153
fname = get_basename(text, options)
154-
fname = '%s.%s' % (get_basename(text, options), options['format'])
155-
if app.builder.format == 'html':
154+
fname = "%s.%s" % (get_basename(text, options), options["format"])
155+
if app.builder.format == "html":
156156
# HTML
157-
imgpath = relative_uri(app.builder.env.docname, '_images')
157+
imgpath = relative_uri(app.builder.env.docname, "_images")
158158
relfn = posixpath.join(imgpath, fname)
159-
outfn = path.join(app.builder.outdir, '_images', fname)
159+
outfn = path.join(app.builder.outdir, "_images", fname)
160160
else:
161161
# Non-HTML
162-
if app.builder.format != 'latex':
162+
if app.builder.format != "latex":
163163
logger.warn(
164-
'aafig: the builder format %s is not officially '
165-
'supported, aafigure images could not work. '
166-
'Please report problems and working builder to '
167-
'avoid this warning inthe future' % app.builder.format
164+
"aafig: the builder format %s is not officially "
165+
"supported, aafigure images could not work. "
166+
"Please report problems and working builder to "
167+
"avoid this warning inthe future" % app.builder.format
168168
)
169169
relfn = fname
170170
outfn = path.join(app.builder.outdir, fname)
171-
metadata_fname = '%s.aafig' % outfn
171+
metadata_fname = "%s.aafig" % outfn
172172

173173
try:
174174
if path.isfile(outfn):
175175
extra = None
176-
if options['format'].lower() == 'svg':
176+
if options["format"].lower() == "svg":
177177
f = None
178178
try:
179179
try:
180-
f = open(metadata_fname, 'r')
180+
f = open(metadata_fname, "r")
181181
extra = f.read()
182182
except Exception:
183183
raise AafigError()
@@ -197,20 +197,20 @@ def render_aafigure(app, text, options):
197197
raise AafigError(str(e))
198198

199199
extra = None
200-
if options['format'].lower() == 'svg':
200+
if options["format"].lower() == "svg":
201201
extra = visitor.get_size_attrs()
202-
f = open(metadata_fname, 'w')
202+
f = open(metadata_fname, "w")
203203
f.write(extra)
204204
f.close()
205205

206206
return relfn, outfn, id, extra
207207

208208

209209
def setup(app):
210-
app.add_directive('aafig', AafigDirective)
211-
app.connect('doctree-read', render_aafig_images)
212-
app.add_config_value('aafig_format', DEFAULT_FORMATS, 'html')
213-
app.add_config_value('aafig_default_options', dict(), 'html')
210+
app.add_directive("aafig", AafigDirective)
211+
app.connect("doctree-read", render_aafig_images)
212+
app.add_config_value("aafig_format", DEFAULT_FORMATS, "html")
213+
app.add_config_value("aafig_default_options", dict(), "html")
214214

215215

216216
# vim: set expandtab shiftwidth=4 softtabstop=4 :

0 commit comments

Comments
 (0)