Skip to content

Commit 62fec67

Browse files
committed
Add support for subpackages (like pulp_file)
1 parent 19e935b commit 62fec67

File tree

3 files changed

+51
-20
lines changed

3 files changed

+51
-20
lines changed

README.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ Python Package to help aggregating Pulp's multirepo ecosystem into a unified doc
1212

1313
This packages is:
1414

15-
- A `mkdocs-macros-plugin` [pluget](https://mkdocs-macros-plugin.readthedocs.io/en/latest/pluglets/). [relevant-code]()
16-
- A repository for common doc website asset. [relevant-code](https://github.com/pedro-psb/pulp-docs/tree/main/src/pulp_docs/docs)
15+
- A `mkdocs-macros-plugin` [pluget](https://mkdocs-macros-plugin.readthedocs.io/en/latest/pluglets/).
16+
- A repository for common doc website asset.
1717
- A centralized entrypoint for installing doc-related packages/tooling. (via its own requirements)
18-
- A CLI for doc-related tasks, like serving and building. [relevant-code](https://github.com/pedro-psb/pulp-docs/blob/main/src/pulp_docs/cli.py)
18+
- A CLI for doc-related tasks, like serving and building.
1919

2020
The idea is that each repository should install `pulp-docs` and imediatelly be able run the unified website server.
2121
Also, this should be used for the production build.
@@ -24,7 +24,7 @@ Also, this should be used for the production build.
2424

2525
Through a `mkdocs-macro-plugin` hook (called in early stages of mkdocs processing), we inject the following steps:
2626

27-
1. Read `repolist.yml` packaged with `pulp-docs` to know which repos/urls to use
27+
1. Read [`repolist.yml`](https://github.com/pedro-psb/pulp-docs/blob/main/src/pulp_docs/data/repolist.yml) packaged with `pulp-docs` to know which repos/urls to use
2828
1. Download/Move all source code required to dir under `tempfile.gettempdir()`
2929
- Uses `../{repo}` if available OR
3030
- Uses existing cached `{tmpdir}/{repo}` if available OR
@@ -39,13 +39,13 @@ And thats it, the magic is done.
3939
Recommended way for daily usage:
4040

4141
```bash
42-
$ pipx install git+https://github.com/pedro-psb/pulp-docs --include-deps
43-
$ pulp-docs serve
42+
pipx install git+https://github.com/pedro-psb/pulp-docs --include-deps
43+
pulp-docs serve
4444
```
4545

4646
For development, use your prefered method!
4747

48-
## How to share inter-repo "unofficial" work
48+
## How to override `repolist.yml`
4949

5050
If you want to share work you are doing in muliple forks, you can share a custom `repolist.yml` which points to your forks.
5151

src/pulp_docs/data/repolist.yml

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
meta:
2+
version: 1
23
rest_api_template: https://docs.pulpproject.org/{}/restapi.html
34

45
repos:
@@ -24,10 +25,6 @@ repos:
2425
owner: pulp
2526
title: Ansible
2627
branch: main
27-
- name: pulp-certguard
28-
owner: pulp
29-
title: Certguard
30-
branch: main
3128
- name: pulp_container
3229
owner: pulp
3330
title: Container
@@ -44,10 +41,13 @@ repos:
4441
owner: pulp
4542
title: RPM
4643
branch: main
47-
# - name: pulp_file
48-
# nested_under: pulp/pulpcore/pulp_file
49-
# title: File
50-
# branch: main
44+
# subpackages
45+
- name: pulp_certguard
46+
title: Certguard
47+
subpackage_of: pulpcore
48+
- name: pulp_file
49+
title: File
50+
subpackage_of: pulpcore
5151
other:
5252
- name: pulp-oci-images
5353
owner: pulp

src/pulp_docs/repository.py

+36-5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import tarfile
1313
import tempfile
1414
import typing as t
15+
from collections import ChainMap, defaultdict
1516
from dataclasses import dataclass, field
1617
from io import BytesIO
1718
from pathlib import Path
@@ -61,6 +62,7 @@ class Repo:
6162
branch: str = "main"
6263
branch_in_use: t.Optional[str] = None
6364
local_basepath: t.Optional[Path] = None
65+
subpackages: t.Optional[t.List] = None
6466
status: RepoStatus = field(default_factory=lambda: RepoStatus())
6567
type: t.Optional[str] = None
6668

@@ -190,6 +192,15 @@ def download_from_gh_latest(dest_dir: Path, owner: str, name: str):
190192
return latest_release_tar_url
191193

192194

195+
@dataclass
196+
class SubPackage:
197+
"""A package that lives under another Repo."""
198+
199+
name: str
200+
title: str
201+
type: t.Optional[str] = None
202+
203+
193204
@dataclass
194205
class Repos:
195206
"""A collection of Repos"""
@@ -242,14 +253,34 @@ def from_yaml(cls, path: str):
242253
raise ValueError("File does not exist:", file)
243254
log.info(f"repofile={str(file.absolute())}")
244255

256+
# Create Repo objects from yaml data
257+
repos: t.Dict[str, t.List] = {}
258+
nested_packages: t.Dict[str, t.List[SubPackage]] = {}
245259
with open(file, "r") as f:
246260
data = yaml.load(f, Loader=yaml.SafeLoader)
247-
repos = data["repos"]
248-
core_repo = Repo(**repos["core"][0], type="core")
249-
content_repos = [Repo(**repo, type="content") for repo in repos["content"]]
250-
other_repos = [Repo(**repo, type="other") for repo in repos["other"]]
261+
for repo_type in ("core", "content", "other"):
262+
repos[repo_type] = []
263+
for repo in data["repos"][repo_type]:
264+
# Collect nested packages
265+
if parent_package := repo.pop("subpackage_of", None):
266+
nested_packages.setdefault(parent_package, []).append(
267+
SubPackage(**repo, type=repo_type)
268+
)
269+
continue
270+
# Create regular packages
271+
repos[repo_type].append(Repo(**repo, type=repo_type))
272+
273+
# Update Repo objects that contain subpackages
274+
for parent_repo_name, subpackages_list in nested_packages.items():
275+
flat_repos = repos["core"] + repos["content"] + repos["other"]
276+
for repo in flat_repos:
277+
if repo.name == parent_repo_name:
278+
repo.subpackages = subpackages_list
279+
251280
return Repos(
252-
core_repo=core_repo, content_repos=content_repos, other_repos=other_repos
281+
core_repo=repos["core"][0],
282+
content_repos=repos["content"],
283+
other_repos=repos["other"],
253284
)
254285

255286
@classmethod

0 commit comments

Comments
 (0)