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])
| 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. |