intjelic / python-sfml

Official binding of SFML for Python
https://www.python-sfml.org
Other
177 stars 41 forks source link

Add docstrings to source and use sphinx.ext.autodoc #61

Open AphonicChaos opened 11 years ago

AphonicChaos commented 11 years ago

As it stands now, all documentation resides in a separate doc directory, which means that users that want to learn the API either have to build documentation from that directory, or visit the online documentation. It would be nice to have documentation within the code and use Sphinx's autodoc feature to generate the API documentation.

Pros:

Cons:

The first con is addressed by the use of folding features in your editor of choice. The second isn't a real concern, since you are able to specify which members to include or exclude.

intjelic commented 11 years ago

I'm late on this one because I just noticed this issue (it didn't show up in my Github notifications :/).

I like docstrings and I think we should add them but I'm afraid we won't be able to generate documentation from them since autodoc parses Python sources while we have Cython sources. As for the first con, my IDE (Geany) handles Cython sources so no problems, it will hide them :)

AphonicChaos commented 11 years ago

I have it working fine on my end with cython (v. 0.17.4). I've pushed the autodoc branch demonstrating the beginnings of this in the (incomplete) documentation of the system module. I should note a couple of things:

  1. I decided to use field lists [1] for attributes, as I thought it might make the documentation easier to navigate if there was a clear separation of these from methods. It's trivial to get output that looks like the current documentation by adding docstrings where applicable.
  2. I didn't convert the entire module, yet.

[1]http://sphinx-doc.org/latest/domains.html#info-field-lists

AphonicChaos commented 11 years ago

@Sonkun could you checkout my autodoc branch, build the docs, and tell me what you think. I'll need your feedback before I am able to continue. Once I know what style of attribute documentation to use, I'll need to wait until the new api is stable enough before continuing as well.

intjelic commented 11 years ago

Autodoc needs your version of pySFML (with docstrings) installed in order to generate the documentation and I have uncommited local changes. I prefer to avoid messing up my workspace before I'm done with those changes so, would you mind sending the result in my mail box ? That'd be helpful :)

By the way, two days ago, I was confused when I read the documentation, I thought I forgot to document save_GL_states(), pop_GL_states() because I expected to find them in sf.RenderWindow class but it was actually documented in sf.RenderTarget, which is fine since sf.RenderWindow inherits from sf.RenderTarget. Maintaining a copy in all inherited classes is unthinkable, so I was wondering if autodoc would solve this problem ?

AphonicChaos commented 11 years ago

Lazy ;-). You could just do:

git stash
git checkout autodoc
cd doc
make html
<webbrowser> build/html/api/system.html
git checkout sfml_latest
git stash pop

Which would store your local changes without committing them, checkout my branch build the documentation, view the documentation, checkout the working dev branch again, then restore your changes. :-)

That said, I'll have the results in your inbox in about a minute.

My solution to issue #51[1](either solution) solves your pop_GL issue.

[1] https://github.com/Sonkun/python-sfml/issues/51#issuecomment-12236787

AphonicChaos commented 11 years ago

Now that sfml_latest is merged, I should be able to work on this again, right?

intjelic commented 11 years ago

Yes :)

intjelic commented 9 years ago

Actually I'm completely in favor of this! Moving to in code documentation will also be a nice opportunity to update the whole documentation all along (I'm sure there are many mistakes, outdated info and inconsistencies). The goal will be to keep the doc in sync with SFML doc. As for the resulting output which might not fit the website theme, I'm sure we can work around that by pre/post processing it or writing an extension, or I don't know but let's not limit ourselves because of that.

However, I'm not familiar with docstrings, pydoc epydoc, autodocs, etc. If you have time, can you explain me shortly their relationship ? I planned to investigate further this feature if no one takes care of it.

PS: I laughed a lot when I reread myself and I told you I didn't want to try your branch because I had local changes xD Of course... git stash, the answer is so obvious now.

intjelic commented 9 years ago

Hmm, just ran across that : http://docs.cython.org/src/userguide/special_methods.html#docstrings

Currently, docstrings are not fully supported in some special methods of extension types. You can place a docstring in the source to serve as a comment, but it won’t show up in the corresponding doc attribute at run time. (This seems to be is a Python limitation – there’s nowhere in the PyTypeObject data structure to put such docstrings.)