MCPcopy
hub / github.com/sphinx-doc/sphinx / path2doc

Method path2doc

sphinx/project.py:94–112  ·  view source on GitHub ↗

Return the docname for the filename if the file is a document. *filename* should be absolute or relative to the source directory.

(self, filename: str | os.PathLike[str])

Source from the content-addressed store, hash-verified

92 return self.docnames
93
94 def path2doc(self, filename: str | os.PathLike[str]) -> str | None:
95 """Return the docname for the filename if the file is a document.
96
97 *filename* should be absolute or relative to the source directory.
98 """
99 path = Path(filename)
100 try:
101 return self._path_to_docname[path]
102 except KeyError:
103 if path.is_absolute():
104 with contextlib.suppress(ValueError):
105 path = path.relative_to(self.srcdir)
106
107 for suffix in self.source_suffix:
108 if path.name.endswith(suffix):
109 return path_stabilize(path).removesuffix(suffix)
110
111 # the file does not have a docname
112 return None
113
114 def doc2path(self, docname: str, absolute: bool) -> _StrPath:
115 """Return the filename for the document name.

Callers 2

discoverMethod · 0.95
test_project_path2docFunction · 0.95

Calls 1

path_stabilizeFunction · 0.90

Tested by 1

test_project_path2docFunction · 0.76