Skip to content

Commit

Permalink
Use template_config.yml to determine correct app_label
Browse files Browse the repository at this point in the history
  • Loading branch information
pedro-psb committed Sep 10, 2024
1 parent b94853d commit 91943ed
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
6 changes: 2 additions & 4 deletions src/pulp_docs/mkdocs_macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
from pulp_docs.constants import SECTION_REPO
from pulp_docs.navigation import get_navigation
from pulp_docs.repository import Repo, Repos, SubPackage
from pulp_docs.utils.general import get_label

# the name of the docs in the source repositories
SRC_DOCS_DIRNAME = "staging_docs"
Expand Down Expand Up @@ -122,7 +121,7 @@ def prepare_repositories(TMPDIR: Path, repos: Repos, config: Config):

# restapi
if has_restapi(repo_or_pkg):
_download_api_json(api_src_dir, repo_or_pkg.name)
_download_api_json(api_src_dir, repo_or_pkg.name, repo_or_pkg.app_label)
_generate_rest_api_page(this_src_dir, repo_or_pkg.name, repo_or_pkg.title)

# install and post-process
Expand All @@ -145,14 +144,13 @@ def prepare_repositories(TMPDIR: Path, repos: Repos, config: Config):
return (repo_docs, repo_sources)


def _download_api_json(api_dir: Path, repo_name: str):
def _download_api_json(api_dir: Path, repo_name: str, app_label: str):
api_json_path = api_dir / f"{repo_name}/api.json"
if api_json_path.exists():
log.info(f"{repo_name} api.json already downloaded.")
return

log.info(f"Downloading api.json for {repo_name}")
app_label = get_label(repo_name)
api_url = f"https://raw.githubusercontent.com/pulp/pulp-docs/docs-data/data/openapi_json/{app_label}-api.json"
response = httpx.get(api_url)
if response.is_error:
Expand Down
16 changes: 16 additions & 0 deletions src/pulp_docs/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ class Repo:
type: t.Optional[str] = None
dev_only: bool = False
version: t.Optional[str] = None
template_config: t.Optional[dict] = None
app_label: t.Optional[str] = None

def __post_init__(self):
self.branch_in_use = self.branch_in_use or self.branch
Expand Down Expand Up @@ -158,6 +160,19 @@ def download(
.get("current_version")
)

# update app_label for app plugins
template_config_file = src_copy_path / "template_config.yml"
if template_config_file.exists():
self.template_config = yaml.load(
template_config_file.read_bytes(), Loader=yaml.SafeLoader
)
app_label_map = {
p["name"]: p["app_label"] for p in self.template_config["plugins"]
}
subpackages = self.subpackages or []
for plugin in (self, *subpackages):
plugin.app_label = app_label_map.get(plugin.name, None)

self.status.download_source = str(download_from)
return self.status.download_source

Expand Down Expand Up @@ -231,6 +246,7 @@ class SubPackage:
owner = ""
dev_only: bool = False
version: t.Optional[str] = None
app_label: t.Optional[str] = None


@dataclass
Expand Down
11 changes: 0 additions & 11 deletions src/pulp_docs/utils/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,6 @@
from pathlib import Path


def get_label(repo_name: str):
"""Get app_label from repo_name.
E.g: 'pulp_ostree' -> 'ostree'.
"""
if repo_name == "pulpcore":
return "core"
# E.g: "pulp-ostree" -> "pulp_ostree" -> ("", "pulp_", "ostree")
return repo_name.replace("-", "_").rpartition("pulp_")[2]


def get_git_ignored_files(repo_path: Path) -> t.List[str]:
"""Get list of ignored files as defined in the repo .gitignore"""
repo_gitignore = Path(repo_path / ".gitignore")
Expand Down

0 comments on commit 91943ed

Please sign in to comment.