1111import os .path
1212
1313from docutils import io , statemachine
14- from docutils .utils .error_reporting import SafeString , ErrorString
1514from docutils .parsers .rst import directives
15+ from docutils .utils .error_reporting import ErrorString , SafeString
1616from sphinx .util .docutils import SphinxDirective
1717
1818
@@ -41,8 +41,7 @@ def run(self):
4141 docset = self .options .get ('docset' , None )
4242 if docset is not None and \
4343 docset not in self .config .ncs_include_mapping :
44- raise self .severe ('The supplied "docset" was not found: "%s"' %
45- docset )
44+ raise self .severe (f'The supplied "docset" was not found: "{ docset } "' )
4645
4746 indent = self .options .get ('indent' , 0 )
4847 dedent = self .options .get ('dedent' , 0 )
@@ -56,7 +55,7 @@ def run(self):
5655 raise self .severe ('Choose one of "dedent" and "auto-dedent" only' )
5756
5857 if not self .state .document .settings .file_insertion_enabled :
59- raise self .warning ('"%s " directive disabled.' % self . name )
58+ raise self .warning (f'" { self . name } " directive disabled.' )
6059
6160 if docset is None :
6261 # without a docset fallback to Sphinx style include
@@ -76,13 +75,11 @@ def run(self):
7675 encoding = encoding ,
7776 error_handler = e_handler )
7877 except UnicodeEncodeError :
79- raise self .severe ('Problems with "%s" directive path:\n '
80- 'Cannot encode input file path "%s" '
81- '(wrong locale?).' %
82- (self .name , SafeString (path )))
83- except IOError as error :
84- raise self .severe ('Problems with "%s" directive path:\n %s.' %
85- (self .name , ErrorString (error )))
78+ raise self .severe (f'Problems with "{ self .name } " directive path:\n '
79+ f'Cannot encode input file path "{ SafeString (path )} " '
80+ '(wrong locale?).' )
81+ except OSError as error :
82+ raise self .severe (f'Problems with "{ self .name } " directive path:\n { ErrorString (error )} .' )
8683
8784 # Get to-be-included content
8885 startline = self .options .get ('start-line' , None )
@@ -94,8 +91,7 @@ def run(self):
9491 else :
9592 rawtext = include_file .read ()
9693 except UnicodeError as error :
97- raise self .severe (u'Problem with "%s" directive:\n %s' %
98- (self .name , ErrorString (error )))
94+ raise self .severe (f'Problem with "{ self .name } " directive:\n { ErrorString (error )} ' )
9995 # start-after/end-before: no restrictions on newlines in match-text,
10096 # and no restrictions on matching inside lines vs. line boundaries
10197 start_at_text = self .options .get ('start-at' , None )
@@ -104,8 +100,8 @@ def run(self):
104100 # skip content in rawtext before *and incl.* a matching text
105101 after_index = rawtext .find (after_text )
106102 if after_index < 0 :
107- raise self .severe ('Problem with "start-after" option of "%s " '
108- 'directive:\n Text not found.' % self . name )
103+ raise self .severe (f 'Problem with "start-after" option of "{ self . name } " '
104+ 'directive:\n Text not found.' )
109105 if start_at_text :
110106 rawtext = rawtext [after_index :]
111107 else :
@@ -116,8 +112,8 @@ def run(self):
116112 # skip content in rawtext after *and incl.* a matching text
117113 before_index = rawtext .find (before_text )
118114 if before_index < 0 :
119- raise self .severe ('Problem with "end-before" option of "%s " '
120- 'directive:\n Text not found.' % self . name )
115+ raise self .severe (f 'Problem with "end-before" option of "{ self . name } " '
116+ 'directive:\n Text not found.' )
121117 if end_at_text :
122118 rawtext = rawtext [:before_index + len (end_at_text )]
123119 else :
0 commit comments