-
Notifications
You must be signed in to change notification settings - Fork 3
Start writing docs. #24
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
base: main
Are you sure you want to change the base?
Changes from all commits
ecdd733
60eead1
50758a7
bd09212
699c509
f3a3494
8c3a470
06c0341
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,71 @@ | ||
# docstub user guide | ||
|
||
**Version**: | ||
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 don't know how to insert a variable in here... 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. For now, we could hard-write it. 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. Honestly, I think we can skip this for now. It should be pretty clear that the user guide reflects the current version of the repo. Longterm this should end up in a website with a version switcher anyway. :) |
||
|
||
## What is docstub? | ||
|
||
[docstub]{.title-ref} is a command-line tool to generate | ||
[Python](https://www.python.org) stub files (i.e., PYI files) from type | ||
descriptions found in [numpydoc](https://numpydoc.readthedocs.io)-style | ||
docstrings. | ||
|
||
[numpy](https://numpy.org), [scipy](https://docs.scipy.org), | ||
[scikit-image](https://scikit-image.org/), and others | ||
follow a common convention for docstrings that provides for | ||
consistency, while also allowing toolchains such as | ||
[numpydoc](https://numpydoc.readthedocs.io) to produce well-formatted | ||
reference guides. | ||
|
||
Our project follows the [SciPy code of | ||
conduct](https://github.com/scipy/scipy/blob/master/doc/source/dev/conduct/code_of_conduct.rst). | ||
|
||
## Installation | ||
|
||
To install docstub, you need Python 3.10, 3.11, or 3.12. | ||
We recommend that you install docstub with `pip`: | ||
|
||
pip install 'docstub [optional] @ git+https://github.com/scientific-python/docstub' | ||
|
||
## Fundamentals and usage | ||
|
||
Consider a function written as follows: | ||
|
||
```py | ||
def example_metric(image0, image1, sigma=1.0, method='standard'): | ||
"""Pretend to calculate a local metric between two images. | ||
|
||
Parameters | ||
---------- | ||
image0 : array-like | ||
First image. | ||
image1 : array_like | ||
Second image. | ||
sigma : float | ||
Sigma parameter. | ||
method : {'standard', 'modified'}, optional, default = 'standard' | ||
The method to use for calculating the metric. | ||
|
||
Returns | ||
------- | ||
met : ndarray of dtype float | ||
""" | ||
pass | ||
``` | ||
|
||
Feeding this input to docstub results in the following output: | ||
|
||
```py | ||
def example_metric( | ||
image0: ArrayLike, | ||
image1: ArrayLike, | ||
sigma: float = ..., | ||
method: Literal["standard", "modified"] = ..., | ||
) -> NDArray[float] | ||
``` | ||
|
||
As you can see, it is a typed function signature, where types are read from | ||
the (well-enough) written docstring. | ||
|
||
In practice, you run the docstub command on a .py file and get a corresponding | ||
.pyi file containing the same imports, the same variables, with classes and | ||
functions replaced with their respective typed signatures. |
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.
I don't know how to insert a variable in here...