9
9
from loguru import logger as log
10
10
11
11
from sphinx_versioned .sphinx_ import EventHandlers
12
- from sphinx_versioned .lib import TempDir , ConfigInject
12
+ from sphinx_versioned .lib import TempDir , ConfigInject , mp_sphinx_compatibility
13
13
from sphinx_versioned .versions import GitVersions , BuiltVersions , PseudoBranch
14
14
15
15
@@ -55,6 +55,7 @@ def __init__(self, chdir: str, local_conf: str, output_dir: str, git_root: str,
55
55
56
56
# Read sphinx-conf.py variables
57
57
self .read_conf ()
58
+ self .configure_conf ()
58
59
59
60
self ._versions_to_pre_build = []
60
61
self ._versions_to_build = []
@@ -72,18 +73,6 @@ def __init__(self, chdir: str, local_conf: str, output_dir: str, git_root: str,
72
73
self .config ["main_branch" ] = self .versions .active_branch .name
73
74
else :
74
75
self .config ["main_branch" ] = "main"
75
-
76
- self .prebuild ()
77
-
78
- # Adds our extension to the sphinx-config
79
- application .Config = ConfigInject
80
-
81
- self .build ()
82
-
83
- # Adds a top-level `index.html` in `output_dir` which redirects to `output_dir`/`main-branch`/index.html
84
- self ._generate_top_level_index ()
85
-
86
- print (f"\n \033 [92m Successfully built { ', ' .join ([x .name for x in self ._built_version ])} \033 [0m" )
87
76
return
88
77
89
78
def read_conf (self ) -> bool :
@@ -112,13 +101,38 @@ def read_conf(self) -> bool:
112
101
continue
113
102
self .config [x ] = sv_conf_values .get (x )
114
103
104
+ log .debug (f"master config: { self .config } " )
105
+ return
106
+
107
+ def configure_conf (self ) -> None :
108
+ # Initialize GitVersions instance
109
+ self .versions = GitVersions (self .git_root , self .output_dir , self .config .get ("force_branches" ))
110
+
111
+ if self .config .get ("floating_badge" ):
112
+ EventHandlers .FLYOUT_FLOATING_BADGE = True
113
+
114
+ if self .config .get ("reset_intersphinx_mapping" ):
115
+ EventHandlers .RESET_INTERSPHINX_MAPPING = True
116
+ log .warning ("Forcing --no-prebuild" )
117
+ self .config ["prebuild" ] = False
118
+
119
+ if self .config .get ("sphinx_compatibility" ):
120
+ mp_sphinx_compatibility ()
121
+
115
122
# Set additional config for sphinx
116
123
self ._additional_args = ()
117
124
self ._additional_args += ("-Q" ,) if self .config .get ("quite" ) else ()
118
125
self ._additional_args += ("-vv" ,) if self .config .get ("verbose" ) else ()
126
+ return
119
127
120
- # Initialize GitVersions instance
121
- self .versions = GitVersions (self .git_root , self .output_dir , self .config .get ("force_branches" ))
128
+ def _select_exclude_branches (self ) -> list :
129
+ log .debug (f"Instructions to select: `{ self .config .get ('select_branch' )} `" )
130
+ log .debug (f"Instructions to exclude: `{ self .config .get ('exclude_branch' )} `" )
131
+ self ._versions_to_pre_build = []
132
+
133
+ self ._select_branch ()
134
+
135
+ log .info (f"selected branches: `{ [x .name for x in self ._versions_to_pre_build ]} `" )
122
136
return
123
137
124
138
def _select_branch (self ) -> None :
@@ -149,16 +163,6 @@ def _exclude_branch(self) -> None:
149
163
150
164
return
151
165
152
- def _select_exclude_branches (self ) -> list :
153
- log .debug (f"Instructions to select: `{ self .config .get ('select_branch' )} `" )
154
- log .debug (f"Instructions to exclude: `{ self .config .get ('exclude_branch' )} `" )
155
- self ._versions_to_pre_build = []
156
-
157
- self ._select_branch ()
158
-
159
- log .info (f"selected branches: `{ [x .name for x in self ._versions_to_pre_build ]} `" )
160
- return
161
-
162
166
def _generate_top_level_index (self ) -> None :
163
167
"""Generate a top-level ``index.html`` which redirects to the main-branch version specified
164
168
via ``main_branch``.
@@ -236,7 +240,7 @@ def prebuild(self) -> None:
236
240
The method carries out the transaction via the internal build method
237
241
:meth:`~sphinx_versioned.build.VersionedDocs._build`.
238
242
"""
239
- if not self .config .get ("prebuild_branches " ):
243
+ if not self .config .get ("prebuild " ):
240
244
log .info ("No pre-builing..." )
241
245
self ._versions_to_build = self ._versions_to_pre_build
242
246
return
@@ -260,7 +264,7 @@ def prebuild(self) -> None:
260
264
log .success (f"Prebuilding successful for { ', ' .join ([x .name for x in self ._versions_to_build ])} " )
261
265
return
262
266
263
- def build (self ) -> None :
267
+ def build (self ) -> bool :
264
268
"""Build workflow.
265
269
266
270
Method to build the branch in a temporary directory with the modified
@@ -282,11 +286,28 @@ def build(self) -> None:
282
286
self ._build (tag .name )
283
287
self ._built_version .append (tag )
284
288
except SphinxError :
285
- log .error (f"build failed for { tag } " )
286
- exit ( - 1 )
289
+ log .error (f"Build failed for { tag } " )
290
+ return False
287
291
finally :
288
292
# restore to active branch
289
293
self .versions .checkout (self ._active_branch )
294
+ return True
295
+
296
+ def run (self ) -> bool :
297
+ # Prebuild, but returns if `self.config["prebuild"]` is `False`
298
+ self .prebuild ()
299
+
300
+ # Adds our extension to the sphinx-config
301
+ application .Config = ConfigInject
302
+
303
+ if self .build ():
304
+ # Adds a top-level `index.html` in `output_dir` which redirects to `output_dir`/`main-branch`/index.html
305
+ self ._generate_top_level_index ()
306
+
307
+ print (f"\n \033 [92m Successfully built { ', ' .join ([x .name for x in self ._built_version ])} \033 [0m" )
308
+ return
309
+
310
+ log .critical (f"Build failed." )
290
311
return
291
312
292
313
pass
0 commit comments