Skip to content

Commit

Permalink
Refactor, improve organization and fix edit_this_page
Browse files Browse the repository at this point in the history
  • Loading branch information
pedro-psb committed Feb 2, 2024
1 parent a0bc538 commit e4bf0a4
Show file tree
Hide file tree
Showing 17 changed files with 297 additions and 602 deletions.
39 changes: 39 additions & 0 deletions src/pulp_docs/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
ADMIN_NAME = "admin"
USER_NAME = "user"

DISPLAY_NAMES = {
"guides": "How-to Guides",
"learn": "Learn More",
"tutorials": "Tutorials",
"reference": "Reference",
}
GUIDES = DISPLAY_NAMES["guides"]
LEARN = DISPLAY_NAMES["learn"]
TUTORIALS = DISPLAY_NAMES["tutorials"]


class Names:
"""Display Names"""

# content types
GUIDES = "How-to Guides"
LEARN = "Learn More"
TUTORIALS = "Tutorials"
REFERENCE = "Reference"

# repo-types
OTHER = "Extra"
CORE = "Pulpcore"
CONTENT = "Plugins"

# personas
USER = "User"
ADMIN = "Admin"
DEV = "Dev"

# other
PULPCORE_TUTORIAL = "Getting Started"

@staticmethod
def get(name: str):
return getattr(Names, name.upper())
File renamed without changes.
8 changes: 4 additions & 4 deletions src/pulp_docs/data/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ repo_name: pulp/pulpcore
docs_dir: docs
theme:
name: material
logo: pulp-docs/assets/logo.png
logo: pulp-docs/docs/assets/logo.png
features:
- content.code.annotate
- navigation.tabs
Expand Down Expand Up @@ -41,7 +41,7 @@ plugins:
- macros:
module_name: '../mkdocs_macros'
- tags:
tags_file: pulp-docs/tags.md
tags_file: pulp-docs/docs/tags.md
- mkdocstrings:
handlers:
python:
Expand All @@ -66,8 +66,8 @@ extra:
link: https://discourse.pulpproject.org/

extra_css:
- pulp-docs/css/extra.css
- pulp-docs/css/mkdocstrings.css
- pulp-docs/docs/css/extra.css
- pulp-docs/docs/css/mkdocstrings.css

markdown_extensions:
# Python Markdown
Expand Down
4 changes: 4 additions & 0 deletions src/pulp_docs/data/repolist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ repos:
owner: pulp
title: Pulp OCI Images
branch: latest
- name: pulp-docs
owner: pedro-psb
title: Docs Tool
branch: main
24 changes: 12 additions & 12 deletions src/pulp_docs/mkdocs_macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@
import logging
import shutil
import tempfile
import typing as t
import time
from pathlib import Path

import rich
from importlib_resources import as_file, files

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

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

end = time.perf_counter()
duration = end - start
log.info(f"{repo.name} completed in {duration:.2} sec")

# Copy template-files (from this plugin) to tmpdir
log.info("[pulp-docs] Moving pulp-docs /docs to final destination")
data_file_docs = files("pulp_docs").joinpath("data/docs")
with as_file(data_file_docs) as _docs:
shutil.copytree(_docs, repo_docs / "pulp-docs")
shutil.copy(
repo_sources / repos.core_repo.name / SRC_DOCS_DIRNAME / "index.md",
repo_docs / "index.md",
Expand Down Expand Up @@ -158,7 +160,7 @@ def print_user_repo(repos: Repos, config: Config):
record = {
"name": repo.name,
"download_source": repo.status.download_source,
"refs": repo.branch,
"refs": repo.branch_in_use,
}
if repo.status.use_local_checkout is True:
local_checkouts.append(record)
Expand All @@ -168,9 +170,9 @@ def print_user_repo(repos: Repos, config: Config):
downloaded_repos.append(record)

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

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

repo_obj = repos.get(repo)
repo_branch = "main"
if repo_obj:
repo_branch = repo_obj.status.original_refs
repo_branch = getattr(repo_obj, "branch", "main")
edit_url = f"https://github.com/pulp/{repo}/edit/{repo_branch}/{path}"
env.page.edit_url = edit_url

Expand Down
Loading

0 comments on commit e4bf0a4

Please sign in to comment.