Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider using sphinx-autoapi to generate docs without having to import rubicon.objc #188

Open
dgelessus opened this issue Sep 19, 2020 · 2 comments
Labels
enhancement New features, or improvements to existing features.

Comments

@dgelessus
Copy link
Collaborator

Many parts of our reference documentation are generated using the Sphinx autodoc extension, which includes contents of docstrings from our Python code into the documentation. To extract the docstrings, autodoc imports the modules in question and reads the __doc__ attributes at runtime.

Unfortunately, this causes some problems with Rubicon, because even just importing rubicon.objc requires a working Objective-C runtime (to look up Objective-C runtime functions and core classes like NSObject), which isn't available in documentation building environments like Read the Docs. We were able to work around this issue by writing a mock version of ctypes and using it during the documentation build in place of the real ctypes module. This mock ctypes implements just enough APIs to make rubicon.objc import successfully and allow Sphinx to extract the docstrings. (See #150 and #154 for details.)

In the PR discussion I said:

It would be really nice if Sphinx autodoc could extract docstrings by statically parsing the code instead of importing/executing it, then we wouldn't have this issue...

It turns out that something like this exists: sphinx-autoapi. I haven't looked into it in detail or tried it yet, but it looks promising. It would be great if we could change our doc build to use this extension instead of regular Sphinx autodoc - then we could get rid of our custom mock ctypes version and wouldn't have to worry about runtime import problems anymore.

@dgelessus dgelessus added enhancement New features, or improvements to existing features. up-for-grabs labels Sep 19, 2020
@samschott
Copy link
Member

samschott commented Apr 9, 2021

I've made some good experiences with sphinx-autoapi for such use cases. The only issues which I have found:

  1. The support for moving type hints to the doc string is a bit flaky at the moment.
  2. Some cross references may not work unless you use a fully qualified path.

Otherwise it is very reliable and supports similar rst syntax as autodoc for generating class and module docs.

@freakboy3742
Copy link
Member

I've take a quick look at this - there's an additional complication in that some of the type definitions (CGFloat is the first one that is discovered) can't be resolved because they require execution of the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New features, or improvements to existing features.
Projects
None yet
Development

No branches or pull requests

3 participants