Skip to content

Commit 6e3604e

Browse files
authored
Add dedicated installation guide (#97)
* Add dedicated installation guide to docs * Improve and tweak docs in a few places
1 parent 34e41f6 commit 6e3604e

File tree

6 files changed

+49
-33
lines changed

6 files changed

+49
-33
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ It does so by supporting widely used readable conventions such as `array of dtyp
1515

1616
## Installation & getting started
1717

18-
Please refer to the [introduction](https://docstub.readthedocs.io/en/latest/introduction.html) to get started with docstub.
18+
Please refer to the installation guide and introduction in our [official documentation](https://docstub.readthedocs.io/) or in [docs/](docs/) to get started.
1919

2020

2121
## Contributing

docs/glossary.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ doctype
1212
type name
1313
The name of a single (atomic) type.
1414
A type name can include a {term}`type prefix`.
15-
An {term}`annotation expression` can contain multiple typen names.
15+
An {term}`annotation expression` can contain multiple type names.
1616
For example, the annotation expression `collections.abc.Iterable[int or float]` consists of the three names `collections.abc.Iterable`, `int` and `float`.
1717

1818
type prefix

docs/index.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ It does so by supporting widely used readable conventions such as `array of dtyp
1717
---
1818

1919
:::{toctree}
20-
:caption: User guides
20+
:caption: Guides
2121
:maxdepth: 1
2222

23+
installation
2324
introduction
2425
:::
2526

docs/installation.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Installation
2+
3+
Docstub is available as a [package on PyPI](https://pypi.org/project/docstub/) and can be installed from there with your favorite package manager.
4+
For example:
5+
6+
```shell
7+
pip install docstub
8+
```
9+
10+
For static analysis, docstub does not need to be installed in the same Python environment as your project!
11+
You can use an isolated environment for docstub.
12+
So things like `pipx run docstub` or `uv tool run docstub` will work, too.
13+
14+
15+
## Development version
16+
17+
In case you want to check out an unreleased version you can install the latest version directly from the repository with:
18+
19+
```shell
20+
pip install 'docstub @ git+https://github.com/scientific-python/docstub'
21+
```
22+
23+
You can append `@COMMIT_SHA` to the repository URL above to intall a specific version other that the `main` branch.

docs/introduction.md

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,7 @@
11
# Introduction
22

3-
## Installation
4-
5-
Docstub is available as a [package on PyPI](https://pypi.org/project/docstub/) and can be installed from there with your favorite package manager. E.g.:
6-
7-
```shell
8-
pip install docstub
9-
```
10-
11-
In case you want to check out an unreleased version you can install directly from the repository with:
12-
13-
```shell
14-
pip install 'docstub @ git+https://github.com/scientific-python/docstub'
15-
```
16-
17-
To pin to a specific commit you can append `@COMMIT_SHA` to the repository URL above.
3+
This introduction will teach you how to use docstub and cover critical concepts.
4+
It assumes familiarity with Python and some familiarity with [static Typing](https://typing.python.org) and [packaging](https://packaging.python.org/en/latest/).
185

196

207
## First example
@@ -97,7 +84,7 @@ There are several interesting things to note here:
9784

9885
## Referencing types & nicknames
9986

100-
To translate a type from a docstring into a valid type annotation, docstub needs to know where names in that type are defined from where to import them.
87+
To translate a type from a docstring into a valid type annotation, docstub needs to know how to import these types.
10188
Out of the box, docstub will know about builtin types such as `int` or `bool` that don't need an import, and types in `typing`, `collections.abc` from Python's standard library.
10289
It will source these from the Python environment it is installed in.
10390
In addition to that, docstub will collect all types in the package directory you are running it on.

docs/typing_syntax.md

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
11
# Typing syntax in docstrings
22

3-
Docstub defines its own [grammar](../src/docstub/doctype.lark) to parse and transform type information in docstrings (doctypes) into valid Python type expressions.
3+
Docstub defines its own [grammar](../src/docstub/doctype.lark) to parse and transform type information in docstrings into valid Python type expressions.
44
This grammar fully supports [Python's conventional typing syntax](https://typing.python.org/en/latest/index.html).
5-
So any type expression that is valid in Python, can be used in a docstrings as is.
5+
So any {term}`annotation expression` that is valid in Python, can be used in a docstrings as is.
66
In addition, docstub extends this syntax with several "natural language" expressions that are commonly used in the scientific Python ecosystem.
77

8-
Docstrings should follow a form that is inspired by the NumPyDoc style:
8+
Docstrings should follow a form that is inspired by the [NumPyDoc style](https://numpydoc.readthedocs.io/en/latest/format.html):
99
```none
10-
Section name
10+
Section namew
1111
------------
1212
name : doctype, optional_info
1313
Description.
1414
```
1515

1616
- `name` might be the name of a parameter, attribute or similar.
17-
- `doctype` contains the actual type information that will be transformed into a Python type (see also {term}`doctype`).
17+
- `doctype` contains the actual type information that will be transformed into an {term}`annotation expression`.
18+
Here you can use the "natural language" expressions that are documented below.
1819
- `optional_info` is optional and captures anything after the first (top-level) comma.
1920
It is useful to provide additional information for readers.
20-
Its presence and content doesn't currently affect the generated {term}`annotation expression`.
21+
Its presence and content doesn't affect the generated {term}`annotation expression`.
22+
23+
Combining multiple names that share a doctype and description is supported.
24+
For example `a, b : int` is equivalent to defining both separately.
2125

2226

2327
## Unions
@@ -116,12 +120,13 @@ See [issue 47](https://github.com/scientific-python/docstub/issues/47) for more
116120

117121
## reStructuredText role
118122

119-
Since docstrings are also used to generate documentation with Sphinx, you may want to use [restructuredText roles](https://docutils.sourceforge.io/docs/ref/rst/roles.html) in your type annotations.
120-
Docstub allows for this anywhere where a qualified name can be used.
123+
Since docstrings are also used to generate documentation with Sphinx, you may want to use [restructuredText roles](https://docutils.sourceforge.io/docs/ref/rst/roles.html).
124+
This is supported anywhere in where a {term}`type name` is used in a {term}`doctype`.
121125

122-
| Docstring type | Python type annotation |
123-
|----------------------|------------------------|
124-
| `` `X` `` | `X` |
125-
| ``:ref:`X` `` | `X` |
126-
| ``:class:`Y.X` `` | `Y.X` |
127-
| ``:py:class:`Y.X` `` | `Y.X` |
126+
| Docstring type | Python type annotation |
127+
|-------------------------|------------------------|
128+
| `` `X` `` | `X` |
129+
| ``:ref:`X` `` | `X` |
130+
| ``:class:`X`[Y, ...] `` | `X[Y, ...]` |
131+
| ``:class:`Y.X` `` | `Y.X` |
132+
| ``:py:class:`Y.X` `` | `Y.X` |

0 commit comments

Comments
 (0)