3
3
import json
4
4
import tomllib
5
5
import yaml
6
+ import glob
6
7
7
8
import httpx
8
9
from git import Repo , GitCommandError
9
10
from mkdocs .config import Config , config_options
10
11
from mkdocs .config .defaults import MkDocsConfig
11
12
from mkdocs .exceptions import PluginError
12
- from mkdocs .plugins import event_priority , get_plugin_logger , BasePlugin
13
+ from mkdocs .plugins import get_plugin_logger , BasePlugin
13
14
from mkdocs .structure .files import File , Files
14
15
from mkdocs .structure .nav import Navigation , Section , Link
15
16
from mkdocs .structure .pages import Page
16
17
from mkdocs .utils .templates import TemplateContext
17
18
18
- from pulp_docs .context import ctx_blog , ctx_docstrings , ctx_draft
19
+ from pulp_docs .context import ctx_blog , ctx_docstrings , ctx_draft , ctx_paths
19
20
20
21
log = get_plugin_logger (__name__ )
21
22
@@ -34,6 +35,33 @@ class ComponentOption(Config):
34
35
git_url = config_options .Type (str , default = "" )
35
36
rest_api = config_options .Type (str , default = "" )
36
37
38
+ _repository_dir = None
39
+
40
+ @property
41
+ def repository_dir (self ):
42
+ if not self ._repository_dir :
43
+ raise RuntimeError (
44
+ "Can't get repository/component path before resolving the dir in the filesystem."
45
+ )
46
+ return self ._repository_dir
47
+
48
+ @property
49
+ def component_dir (self ):
50
+ return self .repository_dir .parent / self .path
51
+
52
+ def resolve_location (self , find_paths : list [str ]):
53
+ repository_name = self .path .split ("/" )[0 ]
54
+ expanded_paths = []
55
+ for dir in find_paths :
56
+ expanded_paths .extend (glob .glob (dir ))
57
+ for dir in expanded_paths :
58
+ dir = Path (dir )
59
+ component_dir = dir .parent / self .path
60
+ if repository_name == dir .name and component_dir .exists ():
61
+ self ._repository_dir = dir
62
+ return self ._repository_dir
63
+ return None
64
+
37
65
38
66
class PulpDocsPluginConfig (Config ):
39
67
components = config_options .ListOfItems (ComponentOption , default = [])
@@ -234,13 +262,15 @@ def on_config(self, config: MkDocsConfig) -> MkDocsConfig | None:
234
262
235
263
self .pulp_docs_dir = Path (config .docs_dir ).parent
236
264
self .repositories_dir = self .pulp_docs_dir .parent
265
+ self .find_paths = ctx_paths .get () or [f"{ self .repositories_dir } /*" ]
237
266
238
267
mkdocstrings_config = config .plugins ["mkdocstrings" ].config
239
268
components_var = []
240
269
new_components = []
241
270
for component in self .config .components :
242
- component_dir = self .repositories_dir / component .path
243
- if component_dir .exists ():
271
+ found_location = component .resolve_location (self .find_paths )
272
+ if found_location :
273
+ component_dir = component .component_dir
244
274
components_var .append (component_data (component , component_dir ))
245
275
config .watch .append (str (component_dir / "docs" ))
246
276
mkdocstrings_config .handlers ["python" ]["paths" ].append (
@@ -253,6 +283,7 @@ def on_config(self, config: MkDocsConfig) -> MkDocsConfig | None:
253
283
else :
254
284
raise PluginError (f"Component '{ component .title } ' missing." )
255
285
self .config .components = new_components
286
+ log .info (f"Using components={ [str (c .component_dir ) for c in new_components ]} " )
256
287
257
288
macros_plugin = config .plugins ["macros" ]
258
289
macros_plugin .register_macros ({"rss_items" : rss_items })
@@ -273,10 +304,10 @@ def on_files(self, files: Files, /, *, config: MkDocsConfig) -> Files | None:
273
304
user_nav : dict [str , t .Any ] = {}
274
305
dev_nav : dict [str , t .Any ] = {}
275
306
for component in self .config .components :
276
- component_dir = self . repositories_dir / component .path
307
+ component_dir = component .component_dir
277
308
278
309
log .info (f"Fetching docs from '{ component .title } '." )
279
- git_repository_dir = self . repositories_dir / Path ( component .path ). parts [ 0 ]
310
+ git_repository_dir = component .repository_dir
280
311
try :
281
312
git_branch = Repo (git_repository_dir ).active_branch .name
282
313
except TypeError :
@@ -290,7 +321,7 @@ def on_files(self, files: Files, /, *, config: MkDocsConfig) -> Files | None:
290
321
else :
291
322
component_docs_dir = component_dir / "docs"
292
323
component_slug = Path (component_dir .name )
293
- assert component_docs_dir .exists ()
324
+ assert component_docs_dir .exists (), component_docs_dir
294
325
295
326
component_nav = ComponentNav (config , component_slug )
296
327
0 commit comments