Skip to content

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions doc/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# docstub user guide

**Version**:
Copy link
Member Author

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...

Copy link
Member Author

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...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now, we could hard-write it.

Copy link
Member

Choose a reason for hiding this comment

The 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.
Loading