|
35 | 35 | import glob
|
36 | 36 | import shutil
|
37 | 37 | from custom_directives import IncludeDirective, GalleryItemDirective, CustomGalleryItemDirective, CustomCalloutItemDirective, CustomCardItemDirective
|
| 38 | +import distutils.file_util |
| 39 | +import re |
38 | 40 |
|
39 | 41 |
|
40 | 42 | try:
|
|
63 | 65 | 'examples_dirs': ['beginner_source', 'intermediate_source',
|
64 | 66 | 'advanced_source', 'recipes_source'],
|
65 | 67 | 'gallery_dirs': ['beginner', 'intermediate', 'advanced', 'recipes'],
|
66 |
| - 'filename_pattern': os.environ.get('GALLERY_PATTERN', r'tutorial.py'), |
67 | 68 | 'backreferences_dir': False
|
68 | 69 | }
|
69 | 70 |
|
| 71 | +if os.getenv('GALLERY_PATTERN'): |
| 72 | + # GALLERY_PATTERN is to be used when you want to work on a single |
| 73 | + # tutorial. Previously this was fed into filename_pattern, but |
| 74 | + # if you do that, you still end up parsing all of the other Python |
| 75 | + # files which takes a few seconds. This strategy is better, as |
| 76 | + # ignore_pattern also skips parsing. |
| 77 | + # See https://github.com/sphinx-gallery/sphinx-gallery/issues/721 |
| 78 | + # for a more detailed description of the issue. |
| 79 | + sphinx_gallery_conf['ignore_pattern'] = r'/(?!' + re.escape(os.getenv('GALLERY_PATTERN')) + r')[^/]+$' |
| 80 | + |
70 | 81 | for i in range(len(sphinx_gallery_conf['examples_dirs'])):
|
71 | 82 | gallery_dir = sphinx_gallery_conf['gallery_dirs'][i]
|
72 | 83 | source_dir = sphinx_gallery_conf['examples_dirs'][i]
|
|
78 | 89 |
|
79 | 90 | # Copy rst files from source dir to gallery dir
|
80 | 91 | for f in glob.glob(os.path.join(source_dir, '*.rst')):
|
81 |
| - shutil.copy(f, gallery_dir) |
| 92 | + distutils.file_util.copy_file(f, gallery_dir, update=True) |
82 | 93 |
|
83 | 94 |
|
84 | 95 | # Add any paths that contain templates here, relative to this directory.
|
|
0 commit comments