File: 0003-Don-t-fail-if-not-in-git-repo.patch

package info (click to toggle)
rocm-docs-core 1.23.0-3
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 2,632 kB
  • sloc: python: 1,960; javascript: 152; sh: 133; cpp: 29; makefile: 27
file content (76 lines) | stat: -rw-r--r-- 3,183 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
From: Christian Bayle <bayle@debian.org>
Date: Wed, 4 Jun 2025 15:20:33 +0200
Subject: Don t fail if not in git repo

Forwarded: https://github.com/ROCm/rocm-docs-core/pull/1308
---
 src/rocm_docs/article_info.py | 28 ++++++++++++++++++++++++----
 1 file changed, 24 insertions(+), 4 deletions(-)

diff --git a/src/rocm_docs/article_info.py b/src/rocm_docs/article_info.py
index ca6b349..9274111 100644
--- a/src/rocm_docs/article_info.py
+++ b/src/rocm_docs/article_info.py
@@ -16,6 +16,9 @@ import git.repo
 from sphinx.application import Sphinx
 from sphinx.config import Config
 
+import sphinx.util.logging, datetime
+
+logger = sphinx.util.logging.getLogger(__name__)
 
 def set_article_info(app: Sphinx, _: Config) -> None:
     """Add article info headers to HTML pages."""
@@ -46,7 +49,11 @@ def _set_page_article_info(
 
     The pages can be set in "article_pages" of the Sphinx configuration.
     """
-    repo = git.repo.Repo(app.srcdir, search_parent_directories=True)
+    if "ROCM_DOCS_NO_GIT" in os.environ:
+        logger.warning("Disabling GIT query")
+    else:
+        repo = git.repo.Repo(app.srcdir, search_parent_directories=True)
+
     for page in app.config.article_pages:
         path_rel = app.project.doc2path(page["file"], False)
         path_html = Path(app.outdir, path_rel).with_suffix(".html")
@@ -77,7 +84,11 @@ def _set_page_article_info(
         if "date" in page:
             date_info = page["date"]
         else:
-            date_info = _get_time_last_modified(repo, path_source)
+            if "ROCM_DOCS_NO_GIT" in os.environ:
+                logger.debug("Disabling GIT query for date, use timestamp : %s", path_source)
+                date_info = datetime.datetime.fromtimestamp(os.path.getmtime(path_source)).strftime("%Y-%m-%d")
+            else:
+                date_info = _get_time_last_modified(repo, path_source)
 
         if date_info == "":
             soup = bs4.BeautifulSoup(modified_info, "html.parser")
@@ -118,7 +129,11 @@ def _set_all_article_info(
     Pages that have specific settings (configured by "article_pages") are
     skipped.
     """
-    repo = git.repo.Repo(app.srcdir, search_parent_directories=True)
+    if "ROCM_DOCS_NO_GIT" in os.environ:
+        logger.warning("Disabling GIT query")
+    else:
+        repo = git.repo.Repo(app.srcdir, search_parent_directories=True)
+
     for docname in app.project.docnames:
         # skip pages with specific settings
         if docname in specific_pages:
@@ -141,7 +156,12 @@ def _set_all_article_info(
         if os_list:
             article_os_info = f"Applies to {article_os_info}"
 
-        date_info = _get_time_last_modified(repo, Path(app.srcdir, page_rel))
+        if "ROCM_DOCS_NO_GIT" in os.environ:
+            logger.debug("Disabling GIT query for date, use timestamp : %s", Path(app.srcdir, page_rel))
+            date_info = datetime.datetime.fromtimestamp(os.path.getmtime(Path(app.srcdir, page_rel))).strftime("%Y-%m-%d")
+        else:
+            date_info = _get_time_last_modified(repo, Path(app.srcdir, page_rel))
+
         if not date_info:
             date_info = cast(str, app.config.all_article_info_date)