-
Notifications
You must be signed in to change notification settings - Fork 9
Docs #35
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
Docs #35
Changes from all commits
96b781b
e643035
b14bd96
438b8bd
1c7c7b8
e1e41c3
b4023e3
e7de2e7
dc97218
4fd95f1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| """ | ||
| Utilities to produce simple reference docs (in Markdown) from the source code. | ||
| """ | ||
|
|
||
| import inspect | ||
| import dash_slicer | ||
|
|
||
|
|
||
| def dedent(text): | ||
| """Dedent a docstring, removing leading whitespace.""" | ||
| lines = text.lstrip().splitlines() | ||
| min_indent = 9999 | ||
| for i in range(1, len(lines)): | ||
| line1 = lines[i] | ||
| line2 = line1.lstrip() | ||
| if line2: | ||
| indent = len(lines[i]) - len(lines[i].lstrip()) | ||
| min_indent = min(min_indent, indent) | ||
| if min_indent > 16: | ||
| min_indent = 0 | ||
| for i in range(1, len(lines)): | ||
| lines[i] = lines[i][min_indent:] | ||
| return "\n".join(lines) | ||
|
|
||
|
|
||
| def get_reference_docs(): | ||
| """Create reference documentation from the source code. | ||
| A bit like Sphinx autodoc, but using Markdown, and more basic. | ||
| Returns a str in Markdown format. | ||
|
|
||
| Note that this function is used to build the Dash Slicer chapter | ||
| in the Dash docs. | ||
| """ | ||
|
Comment on lines
+26
to
+33
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not really sure whether to put his here or in dash-docs. The only real advantage is that we can also add our reference docs to the readme, but perhaps we should just provide a link to
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thoughts welcome :)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's a good idea to have it here if in dash-docs you can just call this function. |
||
|
|
||
| methods = [] | ||
| props = [] | ||
|
|
||
| sig = str(inspect.signature(dash_slicer.VolumeSlicer.__init__)).replace( | ||
| "self, ", "" | ||
| ) | ||
| doc = f"**class `VolumeSlicer{sig}`**" | ||
| doc += "\n\n" + dedent(dash_slicer.VolumeSlicer.__doc__).rstrip() | ||
| methods.append(doc) | ||
|
|
||
| for name in dir(dash_slicer.VolumeSlicer): | ||
| val = getattr(dash_slicer.VolumeSlicer, name) | ||
|
|
||
| if name.startswith("_") or not hasattr(val, "__doc__"): | ||
| pass | ||
| elif callable(val): | ||
| # Method | ||
| sig = str(inspect.signature(val)).replace("self, ", "") | ||
| doc = f"**method `VolumeSlicer.{name}{sig}`**" | ||
| doc += "\n\n" + dedent(val.__doc__).rstrip() | ||
| methods.append(doc) | ||
| else: | ||
| # Property | ||
| doc = f"**property `VolumeSlicer.{name}`**" | ||
| try: | ||
| typ = val.fget.__annotations__["return"].__name__ | ||
| doc += f" (`{typ}`)" | ||
| except (AttributeError, KeyError): | ||
| pass | ||
| doc += ": " + dedent(val.__doc__).rstrip() | ||
| props.append(doc) | ||
|
|
||
| parts = [] | ||
| parts.append("### The VolumeSlicer class") | ||
| parts += methods | ||
| parts += props | ||
| parts.append(dash_slicer.slicer.__doc__) | ||
| return "\n\n".join(parts) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately it is not optional, because we have it as input and output to our callbacks.