jbms / sphinx-immaterial

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

file-specific groups in apigen #172

Closed quattro closed 1 year ago

quattro commented 1 year ago

Hi,

Thanks for developing such a fantastic documentation tool. I'm really liking it so far. I apologize for asking a question here, as I couldn't find a discussion board or email. Is it possible to use python_apigen_default_groups to define class and function groups per file within a module?

I'd like to keep a bit of structure without having to manually create groups, such that the nav bar would have something like

 API
     file1
     file2

where file1 (or similarly file2) could have its own rst with something like

Classes
-------

.. python-apigen-group:: File1 Classes

Public members
--------------

.. python-apigen-group:: File1 Public-members

I've tried with something like the following but with no luck

python_apigen_default_groups = [ 
    ("class:.file1.*", "File1 Classes"),
    ("class:.file2.*", "File2 Classes"),
]
2bndy5 commented 1 year ago

AFAIK, the python apigen ext isn't readily aware of specific modules/files during generation; it kinda just import * and parses what it finds. We have other issues that go a bit more in depth about the py.apigen's module awareness (#152 #153).

Sorry for the delayed response (and possibly disappointing answer).

mhostetter commented 1 year ago

@quattro I created an example that somewhat accomplishes your desire. It may not be the best use of python-apigen, but it kinda works. I think you just needed some modification to your python_apigen_default_groups regex.

Here is the full example foo-172.zip.

Below is snapshot of my solution...

python_apigen_modules = {
    "foo.bar": "api/foo.bar.",
    "foo.baz": "api/foo.baz.",
}
python_apigen_default_groups = [
    (r".*:foo.bar.*", "Bar Public-members"),
    (r"class:foo.bar.*", "Bar Classes"),
    (r".*:foo.baz.*", "Baz Public-members"),
    (r"class:foo.baz.*", "Baz Classes"),
]
python_apigen_default_order = [
    (r".*:foo.bar.*", -1),
    (r"class:foo.bar.*", -2),
    (r".*:foo.baz.*", -1),
    (r"class:foo.baz.*", -2),
]

image

image

quattro commented 1 year ago

Thank you both, @2bndy5 and @mhostetter. This is super helpful, I really appreciate you both taking time to respond. Cheers!

2bndy5 commented 1 year ago

Can we call this issue solved?