27
27
28
28
29
29
@config_options .SubConfig
30
- class RepositoryOption (Config ):
30
+ class ComponentOption (Config ):
31
31
title = config_options .Type (str )
32
32
path = config_options .Type (str )
33
33
kind = config_options .Type (str )
@@ -36,20 +36,20 @@ class RepositoryOption(Config):
36
36
37
37
38
38
class PulpDocsPluginConfig (Config ):
39
- repositories = config_options .ListOfItems (RepositoryOption , default = [])
39
+ components = config_options .ListOfItems (ComponentOption , default = [])
40
40
41
41
42
- class RepositoryNav :
43
- def __init__ (self , config : MkDocsConfig , repository_slug : Path ):
42
+ class ComponentNav :
43
+ def __init__ (self , config : MkDocsConfig , component_slug : Path ):
44
44
self ._nav_file_name : str = config .plugins ["literate-nav" ].config .nav_file
45
- self ._repository_slug = repository_slug
45
+ self ._component_slug = component_slug
46
46
47
- self ._user_index_uri : Path = repository_slug / "index.md"
47
+ self ._user_index_uri : Path = component_slug / "index.md"
48
48
self ._user_index_found : bool = False
49
49
self ._user_uris : list [Path ] = []
50
50
self ._admin_uris : list [Path ] = []
51
51
52
- self ._dev_index_uri : Path = repository_slug / "docs" / "dev" / "index.md"
52
+ self ._dev_index_uri : Path = component_slug / "docs" / "dev" / "index.md"
53
53
self ._dev_index_found : bool = False
54
54
self ._dev_uris : list [Path ] = []
55
55
@@ -79,7 +79,7 @@ def _add_to_taxonomy_nav(
79
79
taxonomy_nav [k1 ][k2 ].append (obj )
80
80
81
81
def add (self , src_uri : Path ) -> None :
82
- assert src_uri .parts [0 ] == str (self ._repository_slug )
82
+ assert src_uri .parts [0 ] == str (self ._component_slug )
83
83
if src_uri .suffix == ".md" :
84
84
if src_uri == self ._user_index_uri :
85
85
self ._user_index_found = True
@@ -174,36 +174,36 @@ def _render_sitemap_item(nav_item: Page | Section) -> str:
174
174
# jinja2 macros and helpers
175
175
176
176
177
- def repository_data (
178
- repository : RepositoryOption ,
179
- repository_dir : Path ,
177
+ def component_data (
178
+ component : ComponentOption ,
179
+ component_dir : Path ,
180
180
) -> dict [str , str | list [str ]]:
181
181
"""Generate data for rendering md templates."""
182
- path = repository_dir .name
182
+ path = component_dir .name
183
183
184
184
version = "unknown"
185
185
try :
186
- pyproject = repository_dir / "pyproject.toml"
186
+ pyproject = component_dir / "pyproject.toml"
187
187
version = tomllib .loads (pyproject .read_text ())["project" ]["version" ]
188
188
except Exception :
189
189
pass
190
190
github_org = "pulp"
191
191
try :
192
- template_config = repository_dir / "template_config.yml"
192
+ template_config = component_dir / "template_config.yml"
193
193
github_org = yaml .safe_load (template_config .read_text ())["github_org" ]
194
194
except Exception :
195
195
pass
196
196
197
197
links = []
198
- if repository .rest_api :
198
+ if component .rest_api :
199
199
links .append (f"[REST API](site:{ path } /restapi/)" )
200
200
links .append (f"[Repository](https://github.com/{ github_org } /{ path } )" )
201
- if (repository_dir / "CHANGES.md" ).exists ():
201
+ if (component_dir / "CHANGES.md" ).exists ():
202
202
links .append (f"[Changelog](site:{ path } /changes/)" )
203
203
204
204
return {
205
- "title" : f"[{ repository .title } ](site:{ path } /)" ,
206
- "kind" : repository .kind ,
205
+ "title" : f"[{ component .title } ](site:{ path } /)" ,
206
+ "kind" : component .kind ,
207
207
"version" : version ,
208
208
"links" : links ,
209
209
}
@@ -236,27 +236,27 @@ def on_config(self, config: MkDocsConfig) -> MkDocsConfig | None:
236
236
self .repositories_dir = self .pulp_docs_dir .parent
237
237
238
238
mkdocstrings_config = config .plugins ["mkdocstrings" ].config
239
- repositories_var = []
240
- new_repositories = []
241
- for repository in self .config .repositories :
242
- repository_dir = self .repositories_dir / repository .path
243
- if repository_dir .exists ():
244
- repositories_var .append (repository_data ( repository , repository_dir ))
245
- config .watch .append (str (repository_dir / "docs" ))
239
+ components_var = []
240
+ new_components = []
241
+ for component in self .config .components :
242
+ component_dir = self .repositories_dir / component .path
243
+ if component_dir .exists ():
244
+ components_var .append (component_data ( component , component_dir ))
245
+ config .watch .append (str (component_dir / "docs" ))
246
246
mkdocstrings_config .handlers ["python" ]["paths" ].append (
247
- str (repository_dir )
247
+ str (component_dir )
248
248
)
249
- new_repositories .append (repository )
249
+ new_components .append (component )
250
250
else :
251
251
if self .draft :
252
- log .warning (f"Skip missing repository '{ repository .title } '." )
252
+ log .warning (f"Skip missing component '{ component .title } '." )
253
253
else :
254
- raise PluginError (f"Repository '{ repository .title } ' missing." )
255
- self .config .repositories = new_repositories
254
+ raise PluginError (f"Component '{ component .title } ' missing." )
255
+ self .config .components = new_components
256
256
257
257
macros_plugin = config .plugins ["macros" ]
258
258
macros_plugin .register_macros ({"rss_items" : rss_items })
259
- macros_plugin .register_variables ({"repositories " : repositories_var })
259
+ macros_plugin .register_variables ({"components " : components_var })
260
260
261
261
blog_plugin = config .plugins ["material/blog" ]
262
262
blog_plugin .config ["enabled" ] = self .blog
@@ -267,109 +267,107 @@ def on_config(self, config: MkDocsConfig) -> MkDocsConfig | None:
267
267
return config
268
268
269
269
def on_files (self , files : Files , / , * , config : MkDocsConfig ) -> Files | None :
270
- log .info (f"Loading Pulp repositories : { self .config .repositories } " )
270
+ log .info (f"Loading Pulp components : { self .config .components } " )
271
271
272
- pulp_docs_git_repository = Repo (self .pulp_docs_dir )
272
+ pulp_docs_git = Repo (self .pulp_docs_dir )
273
273
user_nav : dict [str , t .Any ] = {}
274
274
dev_nav : dict [str , t .Any ] = {}
275
- for repository in self .config .repositories :
276
- repository_dir = self .repositories_dir / repository .path
275
+ for component in self .config .components :
276
+ component_dir = self .repositories_dir / component .path
277
277
278
- log .info (f"Fetching docs from '{ repository .title } '." )
279
- git_repository_dir = self .repositories_dir / Path (repository .path ).parts [0 ]
278
+ log .info (f"Fetching docs from '{ component .title } '." )
279
+ git_repository_dir = self .repositories_dir / Path (component .path ).parts [0 ]
280
280
try :
281
281
git_branch = Repo (git_repository_dir ).active_branch .name
282
282
except TypeError :
283
283
git_branch = None
284
- repository_parent_dir = repository_dir .parent
285
- repository_docs_dir = repository_dir / "staging_docs"
286
- if repository_docs_dir .exists ():
284
+ component_parent_dir = component_dir .parent
285
+ component_docs_dir = component_dir / "staging_docs"
286
+ if component_docs_dir .exists ():
287
287
log .warning (
288
- f"Found deprecated 'staging_docs' directory in { repository .path } ."
288
+ f"Found deprecated 'staging_docs' directory in { component .path } ."
289
289
)
290
290
else :
291
- repository_docs_dir = repository_dir / "docs"
292
- repository_slug = Path (repository_dir .name )
293
- assert repository_docs_dir .exists ()
291
+ component_docs_dir = component_dir / "docs"
292
+ component_slug = Path (component_dir .name )
293
+ assert component_docs_dir .exists ()
294
294
295
- repository_nav = RepositoryNav (config , repository_slug )
295
+ component_nav = ComponentNav (config , component_slug )
296
296
297
- for dirpath , dirnames , filenames in repository_docs_dir .walk (
297
+ for dirpath , dirnames , filenames in component_docs_dir .walk (
298
298
follow_symlinks = True
299
299
):
300
300
for filename in filenames :
301
301
abs_src_path = dirpath / filename
302
302
pulp_meta : dict [str , t .Any ] = {}
303
- if abs_src_path == repository_docs_dir / "index.md" :
304
- src_uri = repository_slug / "index.md"
303
+ if abs_src_path == component_docs_dir / "index.md" :
304
+ src_uri = component_slug / "index.md"
305
305
pulp_meta ["index" ] = True
306
- elif abs_src_path == repository_docs_dir / "dev" / "index.md" :
307
- src_uri = repository_slug / "docs" / "dev" / "index.md"
306
+ elif abs_src_path == component_docs_dir / "dev" / "index.md" :
307
+ src_uri = component_slug / "docs" / "dev" / "index.md"
308
308
pulp_meta ["index" ] = True
309
309
else :
310
- src_uri = abs_src_path .relative_to (repository_parent_dir )
310
+ src_uri = abs_src_path .relative_to (component_parent_dir )
311
311
log .debug (f"Adding { abs_src_path } as { src_uri } ." )
312
- if repository .git_url and git_branch :
312
+ if component .git_url and git_branch :
313
313
git_relpath = abs_src_path .relative_to (git_repository_dir )
314
314
pulp_meta ["edit_url" ] = (
315
- f"{ repository .git_url } /edit/{ git_branch } /{ git_relpath } "
315
+ f"{ component .git_url } /edit/{ git_branch } /{ git_relpath } "
316
316
)
317
317
new_file = File .generated (
318
318
config , src_uri , abs_src_path = abs_src_path
319
319
)
320
320
new_file .pulp_meta = pulp_meta
321
321
files .append (new_file )
322
- repository_nav .add (src_uri )
322
+ component_nav .add (src_uri )
323
323
324
- for src_uri in repository_nav .missing_indices ():
324
+ for src_uri in component_nav .missing_indices ():
325
325
new_file = File .generated (
326
326
config ,
327
327
src_uri ,
328
- content = f"# Welcome to { repository .title } \n \n This is a generated page. "
328
+ content = f"# Welcome to { component .title } \n \n This is a generated page. "
329
329
"See how to add a custom overview page for your plugin "
330
330
"[here](site:pulp-docs/docs/dev/guides/create-plugin-overviews/)." ,
331
331
)
332
332
new_file .pulp_meta = {"index" : True }
333
333
files .append (new_file )
334
334
335
- if repository .rest_api :
336
- src_uri = repository_slug / "restapi.md"
335
+ if component .rest_api :
336
+ src_uri = component_slug / "restapi.md"
337
337
files .append (
338
338
File .generated (
339
339
config ,
340
340
src_uri ,
341
341
content = REST_API_MD ,
342
342
)
343
343
)
344
- repository_nav .add (src_uri )
344
+ component_nav .add (src_uri )
345
345
try :
346
- api_json = pulp_docs_git_repository .git .show (
347
- f"docs-data:data/openapi_json/{ repository .rest_api } -api.json"
346
+ api_json = pulp_docs_git .git .show (
347
+ f"docs-data:data/openapi_json/{ component .rest_api } -api.json"
348
348
)
349
349
except GitCommandError :
350
350
# Try again on the first remote.
351
- remote = pulp_docs_git_repository .remotes [0 ]
352
- api_json = pulp_docs_git_repository .git .show (
353
- f"{ remote } /docs-data:data/openapi_json/{ repository .rest_api } -api.json"
351
+ remote = pulp_docs_git .remotes [0 ]
352
+ api_json = pulp_docs_git .git .show (
353
+ f"{ remote } /docs-data:data/openapi_json/{ component .rest_api } -api.json"
354
354
)
355
- src_uri = (repository_dir / "api.json" ).relative_to (
356
- repository_parent_dir
357
- )
355
+ src_uri = (component_dir / "api.json" ).relative_to (component_parent_dir )
358
356
files .append (File .generated (config , src_uri , content = api_json ))
359
357
360
- repository_changes = repository_dir / "CHANGES.md"
361
- if repository_changes .exists ():
362
- src_uri = repository_slug / "changes.md"
358
+ component_changes = component_dir / "CHANGES.md"
359
+ if component_changes .exists ():
360
+ src_uri = component_slug / "changes.md"
363
361
files .append (
364
- File .generated (config , src_uri , abs_src_path = repository_changes )
362
+ File .generated (config , src_uri , abs_src_path = component_changes )
365
363
)
366
- repository_nav .add (src_uri )
364
+ component_nav .add (src_uri )
367
365
368
- user_nav .setdefault (repository .kind , []).append (
369
- {repository .title : repository_nav .user_nav ()}
366
+ user_nav .setdefault (component .kind , []).append (
367
+ {component .title : component_nav .user_nav ()}
370
368
)
371
- dev_nav .setdefault (repository .kind , []).append (
372
- {repository .title : repository_nav .dev_nav ()}
369
+ dev_nav .setdefault (component .kind , []).append (
370
+ {component .title : component_nav .dev_nav ()}
373
371
)
374
372
375
373
config .nav [1 ]["User Manual" ].extend (
0 commit comments