Skip to content

Commit 6700ffc

Browse files
committed
Refactor, improve organization and fix edit_this_page
1 parent a0bc538 commit 6700ffc

File tree

17 files changed

+300
-602
lines changed

17 files changed

+300
-602
lines changed

src/pulp_docs/constants.py

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
ADMIN_NAME = "admin"
2+
USER_NAME = "user"
3+
4+
DISPLAY_NAMES = {
5+
"guides": "How-to Guides",
6+
"learn": "Learn More",
7+
"tutorials": "Tutorials",
8+
"reference": "Reference",
9+
}
10+
GUIDES = DISPLAY_NAMES["guides"]
11+
LEARN = DISPLAY_NAMES["learn"]
12+
TUTORIALS = DISPLAY_NAMES["tutorials"]
13+
14+
15+
class Names:
16+
"""Display Names"""
17+
18+
# content types
19+
GUIDES = "How-to Guides"
20+
LEARN = "Learn More"
21+
TUTORIALS = "Tutorials"
22+
REFERENCE = "Reference"
23+
24+
# repo-types
25+
OTHER = "Extra"
26+
CORE = "Pulpcore"
27+
CONTENT = "Plugins"
28+
29+
# personas
30+
USER = "User"
31+
ADMIN = "Admin"
32+
DEV = "Dev"
33+
34+
# other
35+
PULPCORE_TUTORIAL = "Getting Started"
36+
37+
@staticmethod
38+
def get(name: str):
39+
return getattr(Names, name.upper())

src/pulp_docs/data/mkdocs.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ repo_name: pulp/pulpcore
66
docs_dir: docs
77
theme:
88
name: material
9-
logo: pulp-docs/assets/logo.png
9+
logo: pulp-docs/docs/assets/logo.png
1010
features:
1111
- content.code.annotate
1212
- navigation.tabs
@@ -41,7 +41,7 @@ plugins:
4141
- macros:
4242
module_name: '../mkdocs_macros'
4343
- tags:
44-
tags_file: pulp-docs/tags.md
44+
tags_file: pulp-docs/docs/tags.md
4545
- mkdocstrings:
4646
handlers:
4747
python:
@@ -66,8 +66,8 @@ extra:
6666
link: https://discourse.pulpproject.org/
6767

6868
extra_css:
69-
- pulp-docs/css/extra.css
70-
- pulp-docs/css/mkdocstrings.css
69+
- pulp-docs/docs/css/extra.css
70+
- pulp-docs/docs/css/mkdocstrings.css
7171

7272
markdown_extensions:
7373
# Python Markdown

src/pulp_docs/data/repolist.yml

+4
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,7 @@ repos:
2222
owner: pulp
2323
title: Pulp OCI Images
2424
branch: latest
25+
- name: pulp-docs
26+
owner: pedro-psb
27+
title: Docs Tool
28+
branch: main

src/pulp_docs/mkdocs_macros.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@
1818
import logging
1919
import shutil
2020
import tempfile
21-
import typing as t
21+
import time
2222
from pathlib import Path
2323

2424
import rich
25-
from importlib_resources import as_file, files
2625

2726
from pulp_docs.cli import Config
2827
from pulp_docs.navigation import get_navigation
@@ -91,6 +90,9 @@ def prepare_repositories(TMPDIR: Path, repos: Repos, config: Config):
9190
shutil.rmtree(repo_docs, ignore_errors=True)
9291

9392
for repo in repos.all:
93+
start = time.perf_counter()
94+
# if repo.name == "pulp-docs":
95+
# breakpoint()
9496
# 1. Download repo (copy locally or fetch from GH)
9597
this_src_dir = repo_sources / repo.name
9698
repo.download(dest_dir=this_src_dir, clear_cache=config.clear_cache)
@@ -125,11 +127,11 @@ def prepare_repositories(TMPDIR: Path, repos: Repos, config: Config):
125127
md_body = f"[{repo.rest_api_link}]({repo.rest_api_link})"
126128
rest_api_page.write_text(f"{md_title}\n\n{md_body}")
127129

130+
end = time.perf_counter()
131+
duration = end - start
132+
log.info(f"{repo.name} completed in {duration:.2} sec")
133+
128134
# Copy template-files (from this plugin) to tmpdir
129-
log.info("[pulp-docs] Moving pulp-docs /docs to final destination")
130-
data_file_docs = files("pulp_docs").joinpath("data/docs")
131-
with as_file(data_file_docs) as _docs:
132-
shutil.copytree(_docs, repo_docs / "pulp-docs")
133135
shutil.copy(
134136
repo_sources / repos.core_repo.name / SRC_DOCS_DIRNAME / "index.md",
135137
repo_docs / "index.md",
@@ -158,7 +160,7 @@ def print_user_repo(repos: Repos, config: Config):
158160
record = {
159161
"name": repo.name,
160162
"download_source": repo.status.download_source,
161-
"refs": repo.branch,
163+
"refs": repo.branch_in_use,
162164
}
163165
if repo.status.use_local_checkout is True:
164166
local_checkouts.append(record)
@@ -168,9 +170,9 @@ def print_user_repo(repos: Repos, config: Config):
168170
downloaded_repos.append(record)
169171

170172
# TODO: improve this refspec comparision heuristics
171-
if repo.status.original_refs and (repo.status.original_refs not in repo.branch):
173+
if repo.branch not in repo.branch_in_use:
172174
warn_msgs.append(
173-
f"[pulp-docs] Original {repo.name!r} ref is {repo.status.original_refs!r}, but local one is '{repo.branch}'."
175+
f"[pulp-docs] Original {repo.name!r} ref is {repo.branch!r}, but local one is '{repo.branch_in_use}'."
174176
)
175177

176178
if len(local_checkouts) == 0:
@@ -249,9 +251,7 @@ def on_pre_page_macros(env):
249251
path = f"{SRC_DOCS_DIRNAME}/index.md"
250252

251253
repo_obj = repos.get(repo)
252-
repo_branch = "main"
253-
if repo_obj:
254-
repo_branch = repo_obj.status.original_refs
254+
repo_branch = getattr(repo_obj, "branch", "main")
255255
edit_url = f"https://github.com/pulp/{repo}/edit/{repo_branch}/{path}"
256256
env.page.edit_url = edit_url
257257

0 commit comments

Comments
 (0)