13
13
# Base paths
14
14
DOCS_DIR = os .path .dirname (os .path .abspath (__file__ ))
15
15
STATIC_THUMBS_DIR = os .path .join (DOCS_DIR , "_static" , "thumbnails" )
16
- BUILD_IMAGES_DIR = os .path .join (DOCS_DIR , "_build" , "html" , "_images" )
17
- GALLERY_HTML = os .path .join (DOCS_DIR , "_build" , "html" , "auto_examples" , "index.html" )
16
+
17
+ # Auto-detect build directory (Read the Docs vs local)
18
+ def find_build_dirs ():
19
+ """Find the actual build directory paths"""
20
+ possible_build_dirs = [
21
+ # Local build
22
+ os .path .join (DOCS_DIR , "_build" , "html" ),
23
+ # Read the Docs build (from docs dir)
24
+ os .path .join (DOCS_DIR , ".." , "_readthedocs" , "html" ),
25
+ # Read the Docs alternative paths
26
+ os .path .join (DOCS_DIR , ".." , ".." , "_readthedocs" , "html" ),
27
+ # Additional Read the Docs patterns based on error message
28
+ "/tmp/_readthedocs_build/html" ,
29
+ os .path .join (os .getcwd (), ".." , "_readthedocs" , "html" ),
30
+ os .path .join (os .getcwd (), "_readthedocs" , "html" ),
31
+ # Check if we're already in the output directory
32
+ os .path .join (os .getcwd (), "_images" , ".." ),
33
+ ]
34
+
35
+ # Also check environment variables that Read the Docs might set
36
+ rtd_output = os .environ .get ('READTHEDOCS_OUTPUT' , '' )
37
+ if rtd_output :
38
+ possible_build_dirs .insert (0 , rtd_output )
39
+
40
+ for build_dir in possible_build_dirs :
41
+ if build_dir and os .path .exists (build_dir ):
42
+ images_dir = os .path .join (build_dir , "_images" )
43
+ gallery_html = os .path .join (build_dir , "auto_examples" , "index.html" )
44
+ if os .path .exists (images_dir ) and os .path .exists (gallery_html ):
45
+ return images_dir , gallery_html
46
+
47
+ return None , None
48
+
49
+ BUILD_IMAGES_DIR , GALLERY_HTML = find_build_dirs ()
18
50
19
51
# Mapping of PNG to GIF thumbnails that should be replaced
20
52
GIF_REPLACEMENTS = {
@@ -30,8 +62,23 @@ def copy_gif_thumbnails():
30
62
"""Copy GIF thumbnails from _static/thumbnails to _build/html/_images"""
31
63
print ("Copying GIF thumbnails..." )
32
64
33
- if not os .path .exists (BUILD_IMAGES_DIR ):
34
- print (f"Error: Build images directory not found: { BUILD_IMAGES_DIR } " )
65
+ # Re-detect directories if needed
66
+ global BUILD_IMAGES_DIR , GALLERY_HTML
67
+ if not BUILD_IMAGES_DIR :
68
+ BUILD_IMAGES_DIR , GALLERY_HTML = find_build_dirs ()
69
+
70
+ if not BUILD_IMAGES_DIR or not os .path .exists (BUILD_IMAGES_DIR ):
71
+ print (f"Error: Build images directory not found." )
72
+ print (f"Searched paths:" )
73
+ possible_dirs = [
74
+ os .path .join (DOCS_DIR , "_build" , "html" , "_images" ),
75
+ os .path .join (DOCS_DIR , ".." , "_readthedocs" , "html" , "_images" ),
76
+ os .path .join (DOCS_DIR , ".." , ".." , "_readthedocs" , "html" , "_images" ),
77
+ ]
78
+ for d in possible_dirs :
79
+ print (f" { d } - { 'EXISTS' if os .path .exists (d ) else 'NOT FOUND' } " )
80
+ print (f"Current working directory: { os .getcwd ()} " )
81
+ print (f"DOCS_DIR: { DOCS_DIR } " )
35
82
return False
36
83
37
84
if not os .path .exists (STATIC_THUMBS_DIR ):
@@ -55,8 +102,13 @@ def update_html_references():
55
102
"""Update HTML gallery to reference GIF files instead of PNG"""
56
103
print ("Updating HTML references..." )
57
104
58
- if not os .path .exists (GALLERY_HTML ):
59
- print (f"Error: Gallery HTML not found: { GALLERY_HTML } " )
105
+ # Re-detect directories if needed
106
+ global BUILD_IMAGES_DIR , GALLERY_HTML
107
+ if not GALLERY_HTML :
108
+ BUILD_IMAGES_DIR , GALLERY_HTML = find_build_dirs ()
109
+
110
+ if not GALLERY_HTML or not os .path .exists (GALLERY_HTML ):
111
+ print (f"Error: Gallery HTML not found: { GALLERY_HTML if GALLERY_HTML else 'None' } " )
60
112
return False
61
113
62
114
# Read the HTML file
0 commit comments