Skip to content

Commit

Permalink
Use f-strings in generate_examples.py
Browse files Browse the repository at this point in the history
  • Loading branch information
mstimberg committed Nov 18, 2022
1 parent 386f83a commit 915fbc2
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions brian2/sphinxext/generate_examples.py
Expand Up @@ -46,7 +46,7 @@ def main(rootpath, destdir):
additional_files = [fname for fname in GlobDirectoryWalker(rootpath, '*.[!py]*')
if not os.path.basename(fname) == '.gitignore']

print('Documenting %d examples' % len(examplesfnames))
print(f'Documenting {len(examplesfnames)} examples')

examplespaths = []
examplesbasenames = []
Expand Down Expand Up @@ -139,12 +139,12 @@ def main(rootpath, destdir):
output += '\n'.join([' ' + line for line in afterdoccode.split('\n')])
output += '\n\n'

eximgpattern = os.path.join(eximgpath, '%s.*' % exname)
eximgpattern = os.path.join(eximgpath, f'{exname}.*')
images = glob.glob(eximgpattern + '.png') + glob.glob(eximgpattern + '.gif')
for image in sorted(images):
_, image = os.path.split(image)
print('Found example image file', image)
output += '.. image:: ../resources/examples_images/%s\n\n' % image
output += f'.. image:: ../resources/examples_images/{image}\n\n'

with codecs.open(os.path.join(destdir, exname + '.rst'), 'w', 'utf-8') as f:
f.write(output)
Expand Down Expand Up @@ -198,4 +198,3 @@ def insert_category(category, mainpage_text):

if __name__=='__main__':
main('../../examples', '../../docs_sphinx/examples')

0 comments on commit 915fbc2

Please sign in to comment.