Skip to content

Commit bb63277

Browse files
committed
switch to f-string
Updating various format calls to use f-string instead. Signed-off-by: James Knight <[email protected]>
1 parent e73b7e5 commit bb63277

25 files changed

+93
-93
lines changed

sphinxcontrib/confluencebuilder/assets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ def _handle_entry(self, path, docname, standalone=False):
295295
idx = 1
296296
while key in self.keys:
297297
idx += 1
298-
key = '{}_{}{}'.format(filename, idx, file_ext)
298+
key = f'{filename}_{idx}{file_ext}'
299299
self.keys.add(key)
300300

301301
asset = ConfluenceAsset(key, path, type_, hash_)

sphinxcontrib/confluencebuilder/builder.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ def prepare_writing(self, docnames):
251251
for domain_name in sorted(self.env.domains):
252252
domain = self.env.domains[domain_name]
253253
for indexcls in domain.indices:
254-
indexname = '%s-%s' % (domain.name, indexcls.name)
254+
indexname = f'{domain.name}-{indexcls.name}'
255255

256256
if isinstance(indices_config, list):
257257
if indexname not in indices_config:
@@ -480,7 +480,7 @@ def write_doc(self, docname, doctree):
480480
if self.writer.output:
481481
file.write(self.writer.output)
482482
except (IOError, OSError) as err:
483-
self.warn('error writing file %s: %s' % (outfilename, err))
483+
self.warn(f'error writing file {outfilename}: {err}')
484484

485485
def publish_doc(self, docname, output):
486486
conf = self.config
@@ -697,7 +697,7 @@ def finish(self):
697697
# build domain indexes
698698
if self.domain_indices:
699699
for indexname, indexdata in self.domain_indices.items():
700-
self.info('generating index ({})...'.format(indexname),
700+
self.info(f'generating index ({indexname})...',
701701
nonl=(not self._verbose))
702702

703703
self._generate_special_document(indexname,
@@ -737,7 +737,7 @@ def finish(self):
737737
self.publish_doc(docname, output)
738738

739739
except (IOError, OSError) as err:
740-
self.warn('error reading file %s: %s' % (docfile, err))
740+
self.warn(f'error reading file {docfile}: {err}')
741741

742742
self.info('building intersphinx... ', nonl=(not self._verbose))
743743
build_intersphinx(self)
@@ -768,7 +768,7 @@ def to_asset_name(asset):
768768
output = file.read()
769769
self.publish_asset(key, docname, output, type_, hash_)
770770
except (IOError, OSError) as err:
771-
self.warn('error reading asset %s: %s' % (key, err))
771+
self.warn(f'error reading asset {key}: {err}')
772772

773773
self.publish_cleanup()
774774
self.publish_finalize()
@@ -866,7 +866,7 @@ def _generate_special_document(self, docname, generator):
866866
with open(fname, encoding='utf-8') as file:
867867
header_template_data = file.read() + '\n'
868868
except (IOError, OSError) as err:
869-
self.warn('error reading file {}: {}'.format(fname, err))
869+
self.warn(f'error reading file {fname}: {err}')
870870

871871
# if no data is supplied, the file is plain text
872872
if self.config.confluence_header_data is None:
@@ -888,7 +888,7 @@ def _generate_special_document(self, docname, generator):
888888
with open(fname, encoding='utf-8') as file:
889889
footer_template_data = file.read() + '\n'
890890
except (IOError, OSError) as err:
891-
self.warn('error reading file {}: {}'.format(fname, err))
891+
self.warn(f'error reading file {fname}: {err}')
892892

893893
# if no data is supplied, the file is plain text
894894
if self.config.confluence_footer_data is None:
@@ -1084,10 +1084,10 @@ def _register_doctree_title_targets(self, docname, doctree):
10841084
section_id = doc_used_names.get(target, 0)
10851085
doc_used_names[target] = section_id + 1
10861086
if section_id > 0:
1087-
target = '{}.{}'.format(target, section_id)
1087+
target = f'{target}.{section_id}'
10881088

10891089
for id_ in section_node['ids']:
1090-
id_ = '{}#{}'.format(docname, id_)
1090+
id_ = f'{docname}#{id_}'
10911091
self.state.register_target(id_, target)
10921092

10931093
def _top_ref_check(self, node):
@@ -1120,7 +1120,7 @@ def _parse_doctree_title(self, docname, doctree):
11201120

11211121
if not doctitle:
11221122
if not self.config.confluence_disable_autogen_title:
1123-
doctitle = "autogen-{}".format(docname)
1123+
doctitle = f'autogen-{docname}'
11241124
if self.publish:
11251125
self.warn('document will be published using an '
11261126
'generated title value: {}'.format(docname))

sphinxcontrib/confluencebuilder/cmd/report.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def report_main(args_parser):
187187
else:
188188
logger.error('bad response from server ({})'.format(
189189
rsp.status_code))
190-
info += ' fetched: error ({})\n'.format(rsp.status_code)
190+
info += f' fetched: error ({rsp.status_code})\n'
191191
rv = 1
192192
except Exception:
193193
sys.stdout.flush()
@@ -279,7 +279,7 @@ def sensitive_config(key):
279279
print('(configuration)')
280280
if config:
281281
for k, v in OrderedDict(sorted(config.items())).items():
282-
print('{}: {}'.format(k, v))
282+
print(f'{k}: {v}')
283283
else:
284284
print('~default configuration~')
285285

sphinxcontrib/confluencebuilder/config/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ def process_ask_configs(config):
5050
default_user = config.confluence_server_user
5151
u_str = ''
5252
if default_user:
53-
u_str = ' [{}]'.format(default_user)
53+
u_str = f' [{default_user}]'
5454

55-
target_user = input(' User{}: '.format(u_str)) or default_user
55+
target_user = input(f' User{u_str}: ') or default_user
5656
if not target_user:
5757
raise ConfluenceConfigurationError('no user provided')
5858

sphinxcontrib/confluencebuilder/config/notifications.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def deprecated(validator):
4545
# inform users of a deprecated configuration being used
4646
for key, msg in DEPRECATED_CONFIGS.items():
4747
if config[key] is not None:
48-
logger.warn('%s deprecated; %s' % (key, msg))
48+
logger.warn(f'{key} deprecated; {msg}')
4949

5050

5151
def warnings(validator):

sphinxcontrib/confluencebuilder/config/validation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def docnames(self):
163163
os.path.join(self.env.srcdir, docname + suffix))
164164
for suffix in self.config.source_suffix):
165165
raise ConfluenceConfigurationError(
166-
'%s is missing document %s' % (self.key, docname))
166+
f'{self.key} is missing document {docname}')
167167

168168
return self
169169

@@ -198,7 +198,7 @@ def docnames_from_file(self):
198198
os.path.join(self.env.srcdir, docname + suffix))
199199
for suffix in self.config.source_suffix):
200200
raise ConfluenceConfigurationError(
201-
'%s is missing document %s' % (self.key, docname))
201+
f'{self.key} is missing document {docname}')
202202

203203
return self
204204

sphinxcontrib/confluencebuilder/intersphinx.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ def escape(string):
3636
# header
3737
f.write((
3838
'# Sphinx inventory version 2\n'
39-
'# Project: %s\n'
40-
'# Version: %s\n'
41-
'# The remainder of this file is compressed using zlib.\n' % (
39+
'# Project: {}\n'
40+
'# Version: {}\n'
41+
'# The remainder of this file is compressed using zlib.\n'.format(
4242
escape(builder.env.config.project),
4343
escape(builder.env.config.version))).encode())
4444

@@ -53,7 +53,7 @@ def escape(string):
5353
if not page_id:
5454
continue
5555

56-
target_name = '{}#{}'.format(docname, raw_anchor)
56+
target_name = f'{docname}#{raw_anchor}'
5757
target = builder.state.target(target_name)
5858

5959
if raw_anchor and target:

sphinxcontrib/confluencebuilder/publisher.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def archive_page(self, page_id):
173173
while attempt <= MAX_WAIT_FOR_PAGE_ARCHIVE:
174174
time.sleep(0.5)
175175

176-
rsp = self.rest_client.get('longtask/{}'.format(longtask_id))
176+
rsp = self.rest_client.get(f'longtask/{longtask_id}')
177177
if rsp['finished']:
178178
break
179179

@@ -370,7 +370,7 @@ def get_attachment(self, page_id, name):
370370
attachment = None
371371
attachment_id = None
372372

373-
url = 'content/{}/child/attachment'.format(page_id)
373+
url = f'content/{page_id}/child/attachment'
374374
rsp = self.rest_client.get(url, {
375375
'filename': name,
376376
})
@@ -397,7 +397,7 @@ def get_attachments(self, page_id):
397397
"""
398398
attachment_info = {}
399399

400-
url = 'content/{}/child/attachment'.format(page_id)
400+
url = f'content/{page_id}/child/attachment'
401401
search_fields = {}
402402

403403
# Configure a larger limit value than the default (no provided
@@ -474,7 +474,7 @@ def get_page_by_id(self, page_id, expand='version'):
474474
the page id and page object
475475
"""
476476

477-
page = self.rest_client.get('content/{}'.format(page_id), {
477+
page = self.rest_client.get(f'content/{page_id}', {
478478
'status': 'current',
479479
'expand': expand,
480480
})
@@ -589,7 +589,7 @@ def store_attachment(self, page_id, name, data, mimetype, hash_, force=False):
589589
try:
590590
# split hash comment into chunks to minimize rendering issues with a
591591
# single one-world-long-hash value
592-
hash_ = '{}:{}'.format(HASH_KEY, hash_)
592+
hash_ = f'{HASH_KEY}:{hash_}'
593593
chunked_hash = '\n'.join(
594594
[hash_[i:i + 16] for i in range(0, len(hash_), 16)])
595595

@@ -603,7 +603,7 @@ def store_attachment(self, page_id, name, data, mimetype, hash_, force=False):
603603
data['minorEdit'] = 'true'
604604

605605
if not attachment:
606-
url = 'content/{}/child/attachment'.format(page_id)
606+
url = f'content/{page_id}/child/attachment'
607607
rsp = self.rest_client.post(url, None, files=data)
608608
uploaded_attachment_id = rsp['results'][0]['id']
609609
else:
@@ -711,7 +711,7 @@ def store_page(self, page_name, data, parent_id=None):
711711
# initial labels need to be applied in their own request
712712
labels = new_page['metadata']['labels']
713713
if not self.cloud and labels:
714-
url = 'content/{}/label'.format(uploaded_page_id)
714+
url = f'content/{uploaded_page_id}/label'
715715
self.rest_client.post(url, labels)
716716

717717
except ConfluenceBadApiError as ex:
@@ -1064,7 +1064,7 @@ def _dryrun(self, msg, id_=None, misc=''):
10641064
if id_ and id_ in self._name_cache:
10651065
s += ' ' + self._name_cache[id_]
10661066
if id_:
1067-
s += ' ({})'.format(id_)
1067+
s += f' ({id_})'
10681068
if misc:
10691069
s += ' ' + misc
10701070
logger.info(s + min(80, 80 - len(s)) * ' ') # 80c-min clearing
@@ -1086,7 +1086,7 @@ def _onlynew(self, msg, id_=None):
10861086
if id_ and id_ in self._name_cache:
10871087
s += ' ' + self._name_cache[id_]
10881088
if id_:
1089-
s += ' ({})'.format(id_)
1089+
s += f' ({id_})'
10901090
logger.info(s + min(80, 80 - len(s)) * ' ') # 80c-min clearing
10911091

10921092
def _populate_labels(self, page, labels):

sphinxcontrib/confluencebuilder/rest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,12 +326,12 @@ def close(self):
326326

327327
def _format_error(self, rsp, key):
328328
err = ""
329-
err += "REQ: {0}\n".format(rsp.request.method)
329+
err += f"REQ: {rsp.request.method}\n"
330330
err += "RSP: " + str(rsp.status_code) + "\n"
331331
err += "URL: " + self.url + self.bind_path + "\n"
332332
err += "API: " + key + "\n"
333333
try:
334-
err += 'DATA: {}'.format(json.dumps(rsp.json(), indent=2))
334+
err += f'DATA: {json.dumps(rsp.json(), indent=2)}'
335335
except: # noqa: E722
336336
err += 'DATA: <not-or-invalid-json>'
337337
return err

sphinxcontrib/confluencebuilder/singlebuilder.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def assemble_toc_secnumbers(self):
3333

3434
for docname, secnums in self.env.toc_secnumbers.items():
3535
for id_, secnum in secnums.items():
36-
alias = '{}/{}'.format(docname, id_)
36+
alias = f'{docname}/{id_}'
3737
new_secnumbers[alias] = secnum
3838

3939
return {self.config.root_doc: new_secnumbers}
@@ -43,7 +43,7 @@ def assemble_toc_fignumbers(self):
4343

4444
for docname, fignumlist in self.env.toc_fignumbers.items():
4545
for figtype, fignums in fignumlist.items():
46-
alias = '{}/{}'.format(docname, figtype)
46+
alias = f'{docname}/{figtype}'
4747
new_fignumbers.setdefault(alias, {})
4848

4949
for id_, fignum in fignums.items():
@@ -215,7 +215,7 @@ def _register_doctree_title_targets(self, docname, doctree):
215215
for id_ in section_node['ids']:
216216
target = title_name
217217

218-
anchorname = '%s/#%s' % (docname, id_)
218+
anchorname = f'{docname}/#{id_}'
219219
if anchorname not in secnumbers:
220220
anchorname = '%s/' % id_
221221

@@ -228,7 +228,7 @@ def _register_doctree_title_targets(self, docname, doctree):
228228
section_id = doc_used_names.get(target, 0)
229229
doc_used_names[target] = section_id + 1
230230
if section_id > 0:
231-
target = '{}.{}'.format(target, section_id)
231+
target = f'{target}.{section_id}'
232232

233233
self.state.register_target(anchorname, target)
234234

0 commit comments

Comments
 (0)