Lines Matching +full:app +full:- +full:path
8 SPDX-License-Identifier: Apache-2.0
29 - ``gh_link_version``: GitHub version to use in the URL (e.g. "main")
30 - ``gh_link_base_url``: Base URL used as a prefix for generated URLs.
31 - ``gh_link_prefixes``: Mapping of pages (regex) <> GitHub prefix.
32 - ``gh_link_exclude``: List of pages (regex) that will not report a URL. Useful
33 for, e.g., auto-generated pages not in Git.
42 from pathlib import Path
50 sys.path.insert(0, str(Path(__file__).parents[3] / "scripts"))
54 ZEPHYR_BASE : Final[str] = Path(__file__).parents[3]
61 def get_page_prefix(app: Sphinx, pagename: str) -> str:
62 """Return the prefix that needs to be added to the page path to get its location in the
69 app: Sphinx instance.
70 pagename: Page name (path).
76 if not os.path.isfile(app.env.doc2path(pagename)):
79 for exclude in app.config.gh_link_exclude:
84 for pattern, prefix in app.config.gh_link_prefixes.items():
92 def gh_link_get_url(app: Sphinx, pagename: str, mode: str = "blob") -> str | None:
96 app: Sphinx instance.
98 pagename: Page name (path).
104 page_prefix = get_page_prefix(app, pagename)
110 app.config.gh_link_base_url,
112 app.config.gh_link_version,
114 str(app.env.doc2path(pagename, False)),
119 def gh_link_get_open_issue_url(app: Sphinx, pagename: str, sha1: str) -> str | None:
121 labels already pre-filled with useful information.
124 app: Sphinx instance.
125 pagename: Page name (path).
131 page_prefix = get_page_prefix(app, pagename)
135 rel_path = os.path.join(
136 os.path.relpath(ZEPHYR_BASE),
138 app.env.doc2path(pagename, False),
157 * Version: {app.config.gh_link_version}
158 * SHA-1: {sha1}
163 return f"{app.config.gh_link_base_url}/issues/new?title={title}&labels={labels}&body={body}"
166 def git_info_filter(app: Sphinx, pagename) -> tuple[str, str] | None:
170 app {Sphinx} -- Sphinx application object
171 pagename {str} -- Page name
174 Optional[Tuple[str, str]] -- Tuple with the date and SHA1 of the last commit made to the
179 page_prefix = get_page_prefix(app, pagename)
183 orig_path = os.path.join(
186 app.env.doc2path(pagename, False),
192 ["git", "ls-files", "--error-unmatch", orig_path],
204 "-1",
205 "--format=%ad %H",
206 "--date=unix",
211 .decode("utf-8")
216 last_update_fmt = app.config.html_last_updated_fmt
218 date = format_date(last_update_fmt, date=date_object, language=app.config.language)
224 def add_jinja_filter(app: Sphinx):
225 if app.builder.format != "html":
228 app.builder.templates.environment.filters["gh_link_get_blob_url"] = partial(
229 gh_link_get_url, app, mode="blob"
232 app.builder.templates.environment.filters["gh_link_get_edit_url"] = partial(
233 gh_link_get_url, app, mode="edit"
236 app.builder.templates.environment.filters["gh_link_get_open_issue_url"] = partial(
237 gh_link_get_open_issue_url, app
240 app.builder.templates.environment.filters["git_info"] = partial(git_info_filter, app)
243 def setup(app: Sphinx):
244 app.add_config_value("gh_link_version", "", "")
245 app.add_config_value("gh_link_base_url", "", "")
246 app.add_config_value("gh_link_prefixes", {}, "")
247 app.add_config_value("gh_link_exclude", [], "")
249 app.connect("builder-inited", add_jinja_filter)