@@ -45,6 +45,7 @@ class Component:
45
45
git_url : str
46
46
rest_api : str
47
47
48
+ version : str
48
49
repository_dir : Path
49
50
component_dir : Path
50
51
@@ -58,11 +59,19 @@ def build(cls, find_path: list[str], component_opt: ComponentOption):
58
59
for dir in expanded_path :
59
60
dir = Path (dir )
60
61
component_dir = dir .parent / component_opt .path
61
- if repository_name == dir .name and component_dir .exists ():
62
+ found_dir = repository_name == dir .name and component_dir .exists ()
63
+ if found_dir :
64
+ version = "unknown"
65
+ try :
66
+ pyproject = component_dir / "pyproject.toml"
67
+ version = tomllib .loads (pyproject .read_text ())["project" ]["version" ]
68
+ except Exception :
69
+ pass
70
+ body ["version" ] = version
62
71
body ["repository_dir" ] = dir
63
72
body ["component_dir" ] = component_dir
64
73
return cls (** body )
65
- raise None
74
+ return None
66
75
67
76
68
77
class PulpDocsPluginConfig (Config ):
@@ -211,12 +220,6 @@ def component_data(
211
220
component_dir = component .component_dir
212
221
path = component_dir .name
213
222
214
- version = "unknown"
215
- try :
216
- pyproject = component_dir / "pyproject.toml"
217
- version = tomllib .loads (pyproject .read_text ())["project" ]["version" ]
218
- except Exception :
219
- pass
220
223
github_org = "pulp"
221
224
try :
222
225
template_config = component_dir / "template_config.yml"
@@ -234,7 +237,7 @@ def component_data(
234
237
return {
235
238
"title" : f"[{ component .title } ](site:{ path } /)" ,
236
239
"kind" : component .kind ,
237
- "version" : version ,
240
+ "version" : component . version ,
238
241
"links" : links ,
239
242
}
240
243
@@ -255,35 +258,49 @@ def rss_items() -> list:
255
258
return rss_feed ["items" ][:20 ]
256
259
257
260
261
+ def load_components (find_path : list [str ], config : MkDocsConfig , draft : bool ):
262
+ loaded_components = []
263
+ for component_opt in config .components :
264
+ component = Component .build (find_path , component_opt )
265
+ if component :
266
+ loaded_components .append (component )
267
+ all_components = {o .path for o in config .components }
268
+ not_loaded_components = all_components .difference (
269
+ {o .path for o in loaded_components }
270
+ )
271
+ if not_loaded_components :
272
+ if draft :
273
+ log .warning (f"Skip missing components { not_loaded_components } ." )
274
+ else :
275
+ raise PluginError (f"Components missing: { not_loaded_components } ." )
276
+ return loaded_components
277
+
278
+
258
279
class PulpDocsPlugin (BasePlugin [PulpDocsPluginConfig ]):
259
280
def on_config (self , config : MkDocsConfig ) -> MkDocsConfig | None :
260
- # Two directories up from docs is where we expect all the other repositories.
261
281
self .blog = ctx_blog .get ()
262
282
self .docstrings = ctx_docstrings .get ()
263
283
self .draft = ctx_draft .get ()
264
284
265
285
self .pulp_docs_dir = Path (config .docs_dir ).parent
286
+ # Two directories up from docs is where we expect all the other repositories by default.
266
287
self .find_path = ctx_path .get () or [f"{ self .pulp_docs_dir .parent } /*" ]
267
288
289
+ loaded_components = load_components (self .find_path , self .config , self .draft )
290
+ self .config .components = loaded_components
291
+
292
+ log .info (
293
+ f"Using components={ [str (c .component_dir ) for c in loaded_components ]} "
294
+ )
295
+
268
296
mkdocstrings_config = config .plugins ["mkdocstrings" ].config
269
297
components_var = []
270
- new_components = []
271
- for component_opt in self .config .components :
272
- component = Component .build (self .find_path , component_opt )
273
- if component :
274
- components_var .append (component_data (component ))
275
- config .watch .append (str (component .component_dir / "docs" ))
276
- mkdocstrings_config .handlers ["python" ]["paths" ].append (
277
- str (component .component_dir )
278
- )
279
- new_components .append (component )
280
- else :
281
- if self .draft :
282
- log .warning (f"Skip missing component '{ component .title } '." )
283
- else :
284
- raise PluginError (f"Component '{ component .title } ' missing." )
285
- self .config .components = new_components
286
- log .info (f"Using components={ [str (c .component_dir ) for c in new_components ]} " )
298
+ for component in self .config .components :
299
+ components_var .append (component_data (component ))
300
+ config .watch .append (str (component .component_dir / "docs" ))
301
+ mkdocstrings_config .handlers ["python" ]["paths" ].append (
302
+ str (component .component_dir )
303
+ )
287
304
288
305
macros_plugin = config .plugins ["macros" ]
289
306
macros_plugin .register_macros ({"rss_items" : rss_items })
0 commit comments