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

Add Python docstrings #1240

Merged
merged 55 commits into from
Jul 3, 2020
Merged

Add Python docstrings #1240

merged 55 commits into from
Jul 3, 2020

Conversation

RobinD42
Copy link
Contributor

@RobinD42 RobinD42 commented Jun 5, 2020

Fixes #1236

First pass implementation of a tool to pull docstrings in markdown format from the Python code, and add them to the main documentation tree.

TODOs:

  • Finish copying existing class docs into docstrings
  • Prettify the docstrings so they're more readable in the code
  • Reorder methods so __init__ always comes first
  • Indent class members in the output (perhaps by adding a new CSS style)
  • Finish support for top-level function docstrings, add their docstrings
  • Add __repr__ methods for classes that are used as default parameter values
  • Find way to auto-exclude SWIG and other lower-level or non-public things.
  • Handle auto documenting other types of items, such as properties??
  • Update intra-doc links to accomodate new document and anchor names
  • Remove the current Python Interface doc. (And rename the new one?)

Not part of this PR, but IMO "{Language} User Interface" name is very misleading, "{Language} User API" would be better.

python/geom.py Outdated Show resolved Hide resolved
@stevengj
Copy link
Collaborator

stevengj commented Jun 6, 2020

I like where this is heading!

One possibility would be to emulate the Documenter.jl package for Julia, which inserts Julia docstrings into Markdown documentation. Essentially, we would take our current Python API markdown document, and replace the documentation for e.g. Medium with

```@docs
Medium
```

and then the postprocessing tool would insert the docstring for Medium there.

The advantages of this, rather than generating the Python API docs wholesale, are:

  1. We manually decide which things go in the manual, and in what order. No need to filter out SWIG-generated code or undocumented features, for example.

  2. We can still surround the docstring code with additional explanations, tutorials, etcetera.

@RobinD42
Copy link
Contributor Author

RobinD42 commented Jun 6, 2020

Yes, that's a good idea. I was thinking about adding some boolean class-level attribute to indicate if something should be added to the documentation, (defaulting to False if it wasn't present) but using a tag to indicate where to insert the doc is much cleaner, and would also allow to use a non-alphabetic ordering like what is in the original document.

@RobinD42 RobinD42 marked this pull request as draft June 17, 2020 19:14
@stevengj
Copy link
Collaborator

Is the generated Python_User_Interface.md supposed to be checked in too?

@RobinD42
Copy link
Contributor Author

I wasn't sure what the preference/policy on that would be. Since it's now generated some projects would just remove it from git. Others would keep it in and developers would need to ensure it is rebuilt and checked in when any changes are made that affect it. What makes the most sense to you?

@stevengj
Copy link
Collaborator

It would be nicer to not check it in, and build it automatically on commits. make dist should certainly build it into the tarballs.

Unfortunately, since it requires Meep to be compiled, it may be too complicated for the mkdocs script. One option would be to build it as part of Travis, and store it with Travis build artifacts for later use during documentation generation. That probably requires some digging through the Travis docs to understand the artifacts system.

Makefile.am Outdated Show resolved Hide resolved
Makefile.am Outdated Show resolved Hide resolved
configure.ac Outdated Show resolved Hide resolved
@stevengj stevengj merged commit 6910843 into NanoComp:master Jul 3, 2020
@RobinD42 RobinD42 deleted the python-docstrings branch July 3, 2020 19:10
bencbartlett pushed a commit to bencbartlett/meep that referenced this pull request Sep 9, 2021
* First pass on tool to extract docstrings and add them to the main documentation.

* Add templates used for building the Python API docs

* Update docs README with new info

* Add link to new API docs. The old is still there for now.

* First pass on adding docstrings to the python code.

* Clarify the note in the README about when to rebuild

* Fix typo

* Refactor doc generator tool to pull items into the master doc by name, rather than as a collection of all classes found by the scan

* Fix typo

* Use spaces inside the tag markers. It's more readable.

* Reorder methods to ensure that __init__ comes first

* Look only at items that are in the class, not all inherited members.
This prevents a lot of noise in the documentation.

* Move remaining class and method docs to docstrings

* Fix typo in Simulation tag

* Regenerate document

* Copy recent changes from the non-template version of the document

* Only load the template files once, and other light refactoring

* Add doc generation support for functions

* Continue moving documentation to doctrings

* Add and export a GDSII_prisms function, for consistency with the other GDSII functions.

* Fix some copy/paste mistakes

* Expose the DtfFOO classes so their docstrings can be linked to

* Move and link dostrings for GDSII, Run and Step, and Output sections

* Move remaining documentation snippets to docstrings in the source.

* Revert Python_User_Interface.md to avoid merge conflicts later.

* Word-wrap and other formatting tweaks to help the docstrings be more readable in the code.

* More docstring formatting

* Typo fix

* Add coding declaration to the top of the Python files.

Python2 defaults to decoding source files to ASCII, so with non-ASCII characters in docstrings or other strings will result in a SyntaxError.

* Add a .css file for custom configuration of styles without touching the existing theme files

* Insert some <div class="..."> tags in the templates

* Add styles

* Ignore doc/site and an additional item in tests

* Backslashes in docstrings need to be escaped

* More template and style tweaks.

* Remove the now generated Python_User_Interface.md file

* Add support for building the documentation via the Makefile

* rewrap paragraph

* Set PYTHONPATH and use $(PYTHON)

* Convert README to Markdown

* `make dist` now depends on building the docs, and the docs are included in the dist archive

* More info and clarification in the doc/README.md file

* Include generate_py_api.py in the distribution

* Fix building docs when configured in a separate build folder

* Install the docs-related packages on Travis

* Python 2.7 mkdocs has broken dependencies, skip building the docs on Python 2.7 builds

* Python2 does not have f-strings

* Use Python2-style super()

* Also skip running the generator on Python2, for now.

* Move generate_py_api script to the doc folder,
enable it to be run from anywhere and still find the templates, etc.

* Restore the generated API doc

* cleanup

* Revert including the docs build in the `make dist` and clean up the doc targets

* Minor tweaks in doc/README.md

Co-authored-by: Robin Dunn <>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Python docstrings and docsystem integration
3 participants