jbms / sphinx-immaterial

Adaptation of the popular mkdocs-material material design theme to the sphinx documentation system
https://jbms.github.io/sphinx-immaterial/
Other
196 stars 29 forks source link

Incorrect object names for inherited members from undocumented classes #147

Closed mhostetter closed 2 years ago

mhostetter commented 2 years ago

I noticed that documenting undocumented parent methods has an issue with the object name and cross-linking. Here is a self-contained reproducer foo-147.zip.

AbstractBase is not documented / is not a public class in the foo package.

# foo/__init__.py
from ._bar import B

# foo/_bar.py
class AbstractBase:
    @property
    def something(self) -> str:
        """
        The base docstring that is applicable to all children.

        This is the second paragraph.
        """
        pass

class B(AbstractBase):
    pass

Notice something is white and unlinked.

image

Notice the URL is correct as api/foo.B.something/, however the object name is foo._bar.foo.B.something not foo.B.something.

image

mhostetter commented 2 years ago

The build output is below. I'm guessing the warnings are relevant.

$ rm -rf docs/build && rm -rf docs/api && sphinx-build -b dirhtml -v docs/ docs/build/
Running Sphinx v5.0.0
/usr/lib/python3/dist-packages/requests/__init__.py:89: RequestsDependencyWarning: urllib3 (1.26.11) or chardet (3.0.4) doesn't match a supported version!
  warnings.warn("urllib3 ({}) or chardet ({}) doesn't match a supported "
making output directory... done
locale_dir /mnt/c/Users/matth/repos/foo-147/docs/locales/en/LC_MESSAGES does not exists
loading intersphinx inventory from https://docs.python.org/3/objects.inv...
loading intersphinx inventory from https://numpy.org/doc/stable/objects.inv...
locale_dir /mnt/c/Users/matth/repos/foo-147/docs/locales/en/LC_MESSAGES does not exists
building [mo]: targets for 0 po files that are out of date
building [dirhtml]: targets for 2 source files that are out of date
updating environment: locale_dir /mnt/c/Users/matth/repos/foo-147/docs/locales/en/LC_MESSAGES does not exists
[new config] 4 added, 0 changed, 0 removed
reading sources... [ 25%] api
reading sources... [ 50%] api/foo.B
reading sources... [ 75%] api/foo.B.something
reading sources... [100%] index

/mnt/c/Users/matth/repos/foo-147/docs/api.rst.rst:12: WARNING: No top-level Python API group named: 'public-members', valid groups are: ['classes']
/mnt/c/Users/matth/repos/foo-147/docs/foo.B.something.rst:1: WARNING: object-id 'foo.B.something' for 'B.something' does not start with module name 'foo._bar.'
/mnt/c/Users/matth/repos/foo-147/docs/foo.B.something.rst:1: WARNING: object-id 'foo.B.something' for 'foo.B.something' does not start with module name 'foo._bar.'
looking for now-outdated files... none found
pickling environment... done
checking consistency... done
preparing documents... WARNING: unsupported theme option 'social' given
done
writing output... [ 25%] api
writing output... [ 50%] api/foo.B
writing output... [ 75%] api/foo.B.something
writing output... [100%] index

foo.B.something:1: WARNING: py:obj reference target not found: foo.B.something
generating indices... genindex done
writing additional pages... done
copying static files... done
copying extra files... done
dumping search index in English (code: en)... done
dumping object inventory... done
Generating sitemap for 5 pages in /mnt/c/Users/matth/repos/foo-147/docs/build/sitemap.xml
build succeeded, 5 warnings.

The HTML pages are in docs/build.
mhostetter commented 2 years ago

I have another example that may elucidate the phenomena that's happening. I discovered that this "foo._bar.foo.B.something not foo.B.something" phenomenon is import order dependent.

Here's a new example. foo-147-v2.zip

`foo/_alpha.py` ```python from ._bravo import Bravo class Alpha(Bravo): """ Class Alpha docstring. """ def my_method_Alpha(self) -> int: """ This is my_method_Alpha. This is paragraph two. """ pass @property def my_property_Alpha(self) -> str: """ This is my_property_Alpha. This is paragraph two. """ pass ```
`foo/_bravo.py` ```python class Bravo: """ Class Bravo docstring. """ def my_method_Bravo(self) -> int: """ This is my_method_Bravo. This is paragraph two. """ pass @property def my_property_Bravo(self) -> str: """ This is my_property_Bravo. This is paragraph two. """ pass ```
`foo/_charlie.py` ```python from ._bravo import Bravo class Charlie(Bravo): """ Class Charlie docstring. """ def my_method_Charlie(self) -> int: """ This is my_method_Charlie. This is paragraph two. """ pass @property def my_property_Charlie(self) -> str: """ This is my_property_Charlie. This is paragraph two. """ pass ```

This works

# foo/__init__.py
from ._bravo import Bravo
from ._charlie import Charlie
Build output ``` $ rm -rf docs/build && rm -rf docs/api && sphinx-build -b dirhtml -v docs/ docs/build/ Running Sphinx v5.0.0 /usr/lib/python3/dist-packages/requests/__init__.py:89: RequestsDependencyWarning: urllib3 (1.26.11) or chardet (3.0.4) doesn't match a supported version! warnings.warn("urllib3 ({}) or chardet ({}) doesn't match a supported " making output directory... done locale_dir /mnt/c/Users/matth/repos/foo-149/docs/locales/en/LC_MESSAGES does not exists loading intersphinx inventory from https://docs.python.org/3/objects.inv... loading intersphinx inventory from https://numpy.org/doc/stable/objects.inv... locale_dir /mnt/c/Users/matth/repos/foo-149/docs/locales/en/LC_MESSAGES does not exists building [mo]: targets for 0 po files that are out of date building [dirhtml]: targets for 2 source files that are out of date updating environment: locale_dir /mnt/c/Users/matth/repos/foo-149/docs/locales/en/LC_MESSAGES does not exists [new config] 8 added, 0 changed, 0 removed reading sources... [ 12%] api reading sources... [ 25%] api/foo.Bravo reading sources... [ 37%] api/foo.Bravo.my_method_Bravo reading sources... [ 50%] api/foo.Bravo.my_property_Bravo reading sources... [ 62%] api/foo.Charlie reading sources... [ 75%] api/foo.Charlie.my_method_Charlie reading sources... [ 87%] api/foo.Charlie.my_property_Charlie reading sources... [100%] index /mnt/c/Users/matth/repos/foo-149/docs/api.rst.rst:7: WARNING: No top-level Python API group named: 'fec', valid groups are: ['classes'] /mnt/c/Users/matth/repos/foo-149/docs/api.rst.rst:17: WARNING: No top-level Python API group named: 'public-members', valid groups are: ['classes'] looking for now-outdated files... none found pickling environment... done checking consistency... done preparing documents... WARNING: unsupported theme option 'social' given done writing output... [ 12%] api writing output... [ 25%] api/foo.Bravo writing output... [ 37%] api/foo.Bravo.my_method_Bravo writing output... [ 50%] api/foo.Bravo.my_property_Bravo writing output... [ 62%] api/foo.Charlie writing output... [ 75%] api/foo.Charlie.my_method_Charlie writing output... [ 87%] api/foo.Charlie.my_property_Charlie writing output... [100%] index generating indices... genindex done writing additional pages... done copying static files... done copying extra files... done dumping search index in English (code: en)... done dumping object inventory... done Generating sitemap for 9 pages in /mnt/c/Users/matth/repos/foo-149/docs/build/sitemap.xml build succeeded, 3 warnings. The HTML pages are in docs/build. ```

image

This doesn't work

# foo/__init__.py
from ._alpha import Alpha
from ._bravo import Bravo
Build output ``` $ rm -rf docs/build && rm -rf docs/api && sphinx-build -b dirhtml -v docs/ docs/build/ Running Sphinx v5.0.0 /usr/lib/python3/dist-packages/requests/__init__.py:89: RequestsDependencyWarning: urllib3 (1.26.11) or chardet (3.0.4) doesn't match a supported version! warnings.warn("urllib3 ({}) or chardet ({}) doesn't match a supported " making output directory... done locale_dir /mnt/c/Users/matth/repos/foo-149/docs/locales/en/LC_MESSAGES does not exists loading intersphinx inventory from https://docs.python.org/3/objects.inv... loading intersphinx inventory from https://numpy.org/doc/stable/objects.inv... locale_dir /mnt/c/Users/matth/repos/foo-149/docs/locales/en/LC_MESSAGES does not exists building [mo]: targets for 0 po files that are out of date building [dirhtml]: targets for 2 source files that are out of date updating environment: locale_dir /mnt/c/Users/matth/repos/foo-149/docs/locales/en/LC_MESSAGES does not exists [new config] 8 added, 0 changed, 0 removed reading sources... [ 12%] api reading sources... [ 25%] api/foo.Alpha reading sources... [ 37%] api/foo.Alpha.my_method_Alpha reading sources... [ 50%] api/foo.Alpha.my_property_Alpha reading sources... [ 62%] api/foo.Bravo reading sources... [ 75%] api/foo.Bravo.my_method_Bravo reading sources... [ 87%] api/foo.Bravo.my_property_Bravo reading sources... [100%] index /mnt/c/Users/matth/repos/foo-149/docs/api.rst.rst:7: WARNING: No top-level Python API group named: 'fec', valid groups are: ['classes'] /mnt/c/Users/matth/repos/foo-149/docs/api.rst.rst:17: WARNING: No top-level Python API group named: 'public-members', valid groups are: ['classes'] /mnt/c/Users/matth/repos/foo-149/docs/foo.Bravo.my_method_Bravo.rst:1: WARNING: object-id 'foo.Bravo.my_method_Bravo' for 'Alpha.my_method_Bravo' does not start with module name 'foo._bravo.' /mnt/c/Users/matth/repos/foo-149/docs/foo.Bravo.my_property_Bravo.rst:1: WARNING: object-id 'foo.Bravo.my_property_Bravo' for 'Alpha.my_property_Bravo' does not start with module name 'foo._bravo.' /mnt/c/Users/matth/repos/foo-149/docs/foo.Bravo.my_method_Bravo.rst:1: WARNING: object-id 'foo.Bravo.my_method_Bravo' for 'Bravo.my_method_Bravo' does not start with module name 'foo._bravo.' /mnt/c/Users/matth/repos/foo-149/docs/foo.Bravo.my_property_Bravo.rst:1: WARNING: object-id 'foo.Bravo.my_property_Bravo' for 'Bravo.my_property_Bravo' does not start with module name 'foo._bravo.' /mnt/c/Users/matth/repos/foo-149/docs/foo.Bravo.my_method_Bravo.rst:1: WARNING: object-id 'foo.Bravo.my_method_Bravo' for 'foo.Bravo.my_method_Bravo' does not start with module name 'foo._bravo.' /mnt/c/Users/matth/repos/foo-149/docs/foo.Bravo.my_property_Bravo.rst:1: WARNING: object-id 'foo.Bravo.my_property_Bravo' for 'foo.Bravo.my_property_Bravo' does not start with module name 'foo._bravo.' looking for now-outdated files... none found pickling environment... done checking consistency... done preparing documents... WARNING: unsupported theme option 'social' given done writing output... [ 12%] api writing output... [ 25%] api/foo.Alpha writing output... [ 37%] api/foo.Alpha.my_method_Alpha writing output... [ 50%] api/foo.Alpha.my_property_Alpha writing output... [ 62%] api/foo.Bravo writing output... [ 75%] api/foo.Bravo.my_method_Bravo writing output... [ 87%] api/foo.Bravo.my_property_Bravo writing output... [100%] index foo.Bravo.my_method_Bravo:1: WARNING: py:obj reference target not found: foo.Bravo.my_method_Bravo foo.Bravo.my_property_Bravo:1: WARNING: py:obj reference target not found: foo.Bravo.my_property_Bravo foo.Bravo.my_method_Bravo:1: WARNING: py:obj reference target not found: foo.Bravo.my_method_Bravo foo.Bravo.my_property_Bravo:1: WARNING: py:obj reference target not found: foo.Bravo.my_property_Bravo generating indices... genindex done writing additional pages... done copying static files... done copying extra files... done dumping search index in English (code: en)... done dumping object inventory... done Generating sitemap for 9 pages in /mnt/c/Users/matth/repos/foo-149/docs/build/sitemap.xml build succeeded, 13 warnings. The HTML pages are in docs/build. ```

Notice the methods inherited from Bravo are white and not linked.

image

A page does exist but it has the wrong name -- the same issue as in the original example.

image

Since from ._alpha import Alpha is done first and inside _alpha.py Bravo is imported, it seems that Bravo definition conflicts with the Bravo that is imported later in __init__.py.

2bndy5 commented 2 years ago

fixed in v0.9.0