77import shutil
88import subprocess
99import tempfile
10- from importlib .resources import files
1110from pathlib import Path
1211from typing import NamedTuple , Optional
1312
14- from pulp_docs . repository import Repos
13+ from mkdocs . config import load_config
1514
1615BASE_TMPDIR_NAME = "pulpdocs_tmp"
16+ CURRENT_DIR = Path (__file__ ).parent .absolute ()
1717
1818
1919def main (output_dir : Path , plugins_filter : Optional [list [str ]] = None , dry_run : bool = False ):
2020 """Creates openapi json files for all or selected plugins in output dir."""
21- repolist = str (files ("pulp_docs" ).joinpath ("data/repolist.yml" ))
22- repos = Repos .from_yaml (repolist ).get_repos (["content" ])
23- if plugins_filter :
24- repos = [p for p in repos if p .name in plugins_filter ]
21+
22+ def get_plugin_name (path : str ) -> str :
23+ return path .rpartition ("/" )[- 1 ]
24+
25+ def is_subpackage (path : str ) -> bool :
26+ return "/" in path
27+
28+ def filter_plugin (path : str ) -> bool :
29+ if not plugins_filter :
30+ return True
31+ return get_plugin_name (path ) in plugins_filter or path == "pulpcore"
32+
33+ def get_plugins ():
34+ mkdocs_yml = str (CURRENT_DIR .parent .parent / "mkdocs.yml" )
35+ pulpdocs_plugin = load_config (mkdocs_yml ).plugins ["PulpDocs" ]
36+ all_components = pulpdocs_plugin .config .components
37+ return [c for c in all_components if c .rest_api ]
38+
39+ all_plugins = get_plugins ()
40+ all_plugins = [p for p in all_plugins if filter_plugin (p .path )]
2541
2642 pulp_plugins = []
27- for repo in repos :
28- name = repo .name
29- label = name .split ("_" )[- 1 ]
30- is_subpackage = bool (getattr (repo , "subpackage_of" , False ))
31- pulp_plugins .append (PulpPlugin (name , label , is_subpackage ))
43+ for plugin in all_plugins :
44+ plugin = PulpPlugin (
45+ name = get_plugin_name (plugin .path ),
46+ label = plugin .rest_api ,
47+ is_subpackage = is_subpackage (plugin .path ),
48+ git_url = plugin .git_url ,
49+ )
50+ pulp_plugins .append (plugin )
3251
3352 openapi = OpenAPIGenerator (plugins = pulp_plugins , dry_run = dry_run )
3453 openapi .generate (target_dir = output_dir )
@@ -47,10 +66,10 @@ class PulpPlugin(NamedTuple):
4766 name : str
4867 label : str
4968 is_subpackage : bool
50- remote_template : str = "https://github.com/pulp/{name}"
69+ git_url : str
5170
5271 def get_remote_url (self ):
53- return self .remote_template . format ( name = self . name )
72+ return self .git_url
5473
5574
5675class OpenAPIGenerator :
@@ -64,7 +83,7 @@ class OpenAPIGenerator:
6483 """
6584
6685 def __init__ (self , plugins : list [PulpPlugin ], dry_run = False ):
67- self .pulpcore = PulpPlugin ( "pulpcore" , "core" , False )
86+ self .pulpcore = next ( filter ( lambda p : p . name == "pulpcore" , plugins ) )
6887 self .plugins = plugins + [self .pulpcore ]
6988 self .dry_run = dry_run
7089
0 commit comments