Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3871b5c

Browse filesBrowse files
committed
ENH: copy any files in a regexp; take copy outside loop
1 parent 44c2d52 commit 3871b5c
Copy full SHA for 3871b5c

File tree

Expand file treeCollapse file tree

1 file changed

+8
-10
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+8
-10
lines changed

‎sphinx_gallery/gen_rst.py

Copy file name to clipboardExpand all lines: sphinx_gallery/gen_rst.py
+8-10Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -413,8 +413,8 @@ def generate_dir_rst(
413413
if not os.path.exists(target_dir):
414414
os.makedirs(target_dir)
415415
# get filenames
416-
listdir = [fname for fname in os.listdir(src_dir) if
417-
fname.endswith('.py')]
416+
listdir = [fname for fname in os.listdir(src_dir)
417+
if fname.endswith('.py')]
418418
# limit which to look at based on regex (similar to filename_pattern)
419419
listdir = [fname for fname in listdir
420420
if re.search(gallery_conf['ignore_pattern'],
@@ -432,26 +432,24 @@ def generate_dir_rst(
432432
costs = []
433433
subsection_toctree_filenames = []
434434
build_target_dir = os.path.relpath(target_dir, gallery_conf['src_dir'])
435-
436435
iterator = sphinx.util.status_iterator(
437436
sorted_listdir,
438437
'generating gallery for %s... ' % build_target_dir,
439438
length=len(sorted_listdir))
440439
for fname in iterator:
441-
src_file = os.path.normpath(os.path.join(src_dir, fname))
442-
# make the rst for the python file:
443440
intro, title, cost = generate_file_rst(
444441
fname, target_dir, src_dir, gallery_conf, seen_backrefs)
442+
src_file = os.path.normpath(os.path.join(src_dir, fname))
445443
costs.append((cost, src_file))
444+
gallery_item_filename = os.path.join(
445+
build_target_dir,
446+
fname[:-3]
447+
).replace(os.sep, '/')
446448
this_entry = _thumbnail_div(
447449
target_dir, gallery_conf['src_dir'], fname, intro, title
448450
)
449451
entries_text.append(this_entry)
450452

451-
gallery_item_filename = os.path.join(
452-
build_target_dir,
453-
fname[:-3]
454-
).replace(os.sep, '/')
455453
subsection_toctree_filenames.append("/" + gallery_item_filename)
456454

457455
for entry_text in entries_text:
@@ -497,7 +495,7 @@ def generate_dir_rst(
497495
copyregex = gallery_conf.get('copyfile_regex')
498496
if copyregex:
499497
listdir = [fname for fname in os.listdir(src_dir) if
500-
re.match(copyregex, fname)]
498+
re.match(copyregex, fname)]
501499
readme = _get_readme(src_dir, gallery_conf, raise_error=False)
502500
# don't copy over the readme
503501
if readme:

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.