3838from sphinxcontrib .confluencebuilder .util import first
3939from sphinxcontrib .confluencebuilder .util import handle_cli_file_subset
4040from sphinxcontrib .confluencebuilder .writer import ConfluenceWriter
41- import io
4241import os
4342import tempfile
4443
@@ -57,10 +56,10 @@ def __init__(self, app, env=None):
5756 # assigned.
5857 if sphinx_version_info >= (5 , 1 ):
5958 # pylint: disable=too-many-function-args
60- super (ConfluenceBuilder , self ).__init__ (app , env )
59+ super ().__init__ (app , env )
6160 # pylint: enable=too-many-function-args
6261 else :
63- super (ConfluenceBuilder , self ).__init__ (app )
62+ super ().__init__ (app )
6463
6564 self .cache_doctrees = {}
6665 self .cloud = False
@@ -252,7 +251,7 @@ def prepare_writing(self, docnames):
252251 for domain_name in sorted (self .env .domains ):
253252 domain = self .env .domains [domain_name ]
254253 for indexcls in domain .indices :
255- indexname = '%s-%s' % ( domain .name , indexcls .name )
254+ indexname = f' { domain .name } - { indexcls .name } '
256255
257256 if isinstance (indices_config , list ):
258257 if indexname not in indices_config :
@@ -477,11 +476,11 @@ def write_doc(self, docname, doctree):
477476 if self .writer .output is not None :
478477 ensuredir (path .dirname (outfilename ))
479478 try :
480- with io . open (outfilename , 'w' , encoding = 'utf-8' ) as file :
479+ with open (outfilename , 'w' , encoding = 'utf-8' ) as file :
481480 if self .writer .output :
482481 file .write (self .writer .output )
483482 except (IOError , OSError ) as err :
484- self .warn ('error writing file %s: %s' % ( outfilename , err ) )
483+ self .warn (f 'error writing file { outfilename } : { err } ' )
485484
486485 def publish_doc (self , docname , output ):
487486 conf = self .config
@@ -698,7 +697,7 @@ def finish(self):
698697 # build domain indexes
699698 if self .domain_indices :
700699 for indexname , indexdata in self .domain_indices .items ():
701- self .info ('generating index ({})...' . format ( indexname ) ,
700+ self .info (f 'generating index ({ indexname } )...' ,
702701 nonl = (not self ._verbose ))
703702
704703 self ._generate_special_document (indexname ,
@@ -733,12 +732,12 @@ def finish(self):
733732 docfile = path .join (self .outdir , self .file_transform (docname ))
734733
735734 try :
736- with io . open (docfile , 'r' , encoding = 'utf-8' ) as file :
735+ with open (docfile , 'r' , encoding = 'utf-8' ) as file :
737736 output = file .read ()
738737 self .publish_doc (docname , output )
739738
740739 except (IOError , OSError ) as err :
741- self .warn ('error reading file %s: %s' % ( docfile , err ) )
740+ self .warn (f 'error reading file { docfile } : { err } ' )
742741
743742 self .info ('building intersphinx... ' , nonl = (not self ._verbose ))
744743 build_intersphinx (self )
@@ -769,7 +768,7 @@ def to_asset_name(asset):
769768 output = file .read ()
770769 self .publish_asset (key , docname , output , type_ , hash_ )
771770 except (IOError , OSError ) as err :
772- self .warn ('error reading asset %s: %s' % ( key , err ) )
771+ self .warn (f 'error reading asset { key } : { err } ' )
773772
774773 self .publish_cleanup ()
775774 self .publish_finalize ()
@@ -864,10 +863,10 @@ def _generate_special_document(self, docname, generator):
864863 fname = path .join (self .env .srcdir ,
865864 self .config .confluence_header_file )
866865 try :
867- with io . open (fname , encoding = 'utf-8' ) as file :
866+ with open (fname , encoding = 'utf-8' ) as file :
868867 header_template_data = file .read () + '\n '
869868 except (IOError , OSError ) as err :
870- self .warn ('error reading file {}: {}' . format ( fname , err ) )
869+ self .warn (f 'error reading file { fname } : { err } ' )
871870
872871 # if no data is supplied, the file is plain text
873872 if self .config .confluence_header_data is None :
@@ -886,10 +885,10 @@ def _generate_special_document(self, docname, generator):
886885 fname = path .join (self .env .srcdir ,
887886 self .config .confluence_footer_file )
888887 try :
889- with io . open (fname , encoding = 'utf-8' ) as file :
888+ with open (fname , encoding = 'utf-8' ) as file :
890889 footer_template_data = file .read () + '\n '
891890 except (IOError , OSError ) as err :
892- self .warn ('error reading file {}: {}' . format ( fname , err ) )
891+ self .warn (f 'error reading file { fname } : { err } ' )
893892
894893 # if no data is supplied, the file is plain text
895894 if self .config .confluence_footer_data is None :
@@ -902,7 +901,7 @@ def _generate_special_document(self, docname, generator):
902901 # generate/replace the document in the output directory
903902 fname = path .join (self .outdir , docname + self .file_suffix )
904903 try :
905- with io . open (fname , 'w' , encoding = 'utf-8' ) as f :
904+ with open (fname , 'w' , encoding = 'utf-8' ) as f :
906905 f .write (self ._cached_header_data )
907906 generator (self , docname , f )
908907 f .write (self ._cached_footer_data )
@@ -973,7 +972,7 @@ def _header_footer_init(self, docname, doctree):
973972 else :
974973 # unsupported source type should not pass here after this
975974 # extension's configuration check
976- assert False
975+ raise AssertionError ( 'unsupported source type' )
977976
978977 sourcelink ['url' ] = url_base + url
979978
@@ -1085,10 +1084,10 @@ def _register_doctree_title_targets(self, docname, doctree):
10851084 section_id = doc_used_names .get (target , 0 )
10861085 doc_used_names [target ] = section_id + 1
10871086 if section_id > 0 :
1088- target = '{ }.{}' . format ( target , section_id )
1087+ target = f' { target } .{ section_id } '
10891088
10901089 for id_ in section_node ['ids' ]:
1091- id_ = '{ }#{}' . format ( docname , id_ )
1090+ id_ = f' { docname } #{ id_ } '
10921091 self .state .register_target (id_ , target )
10931092
10941093 def _top_ref_check (self , node ):
@@ -1121,7 +1120,7 @@ def _parse_doctree_title(self, docname, doctree):
11211120
11221121 if not doctitle :
11231122 if not self .config .confluence_disable_autogen_title :
1124- doctitle = " autogen-{}" . format ( docname )
1123+ doctitle = f' autogen-{ docname } '
11251124 if self .publish :
11261125 self .warn ('document will be published using an '
11271126 'generated title value: {}' .format (docname ))
0 commit comments