Add `--ignore` CLI option and `ignore_files` config field by lagru · Pull Request #60 · scientific-python/docstub · GitHub
Skip to content
Merged
Show file tree
Hide file tree
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
30 changes: 0 additions & 30 deletions LICENSE

This file was deleted.

88 changes: 88 additions & 0 deletions LICENSE.txt
2 changes: 2 additions & 0 deletions docs/command_line.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ Options:
--config PATH Set one or more configuration file(s) explicitly.
Otherwise, it will look for a `pyproject.toml` or
`docstub.toml` in the current directory.
--ignore GLOB Ignore files matching this glob-style pattern. Can be
used multiple times.
--group-errors Group identical errors together and list where they
occurred. Will delay showing errors until all files have
been processed. Otherwise, simply report errors as the
Expand Down
95 changes: 95 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# Configuration reference

Docstub will automatically look for configuration in files named

- `pyproject.toml`, and
- `docstub.toml`

in the current working directory.
If config files are explicitly passed to the command line interface via the `--config` option, docstub won't look implicitly look for files in the current directory.
Multiple configuration files can be used, whose content will be merged.

Out of the box, docstub makes use of an internal configuration file [`numpy_config.toml`](../src/docstub/numpy_config.toml) which provides defaults to use NumPy types.


## Configuration fields in `[tool.docstub]`

All configuration must be declared inside a `[tool.docstub]` table.


### `ignore_files`

- [TOML type](https://toml.io/en/latest): array of string(s)

Ignore files and directories matching these [glob-style patterns](https://docs.python.org/3/library/glob.html#glob.translate).
Patterns that don't start with "/" are interpreted as relative to the
directory that contains the Python package for which stubs are generated.

Example:

```toml
[tool.docstub]
ignore_files = [
"**/tests",
]
```

- Will ignore any directory anywhere that is named `tests`.


### `types`

- [TOML type](https://toml.io/en/latest): table, mapping string to string

Types and their external modules to use in docstrings.
Docstub can't yet automatically discover where to import types from other packages from.
Instead, you can provide this information explicitly.
Any type on the left side will be associated with the given "module" on the right side.

Example:

```toml
[tool.docstub.types]
Path = "pathlib"
NDArray = "numpy.typing"
```

- Will allow using `Path` in docstrings and will use `from pathlib import Path` to import the type.
- Will allow using `NDarray` in docstrings and will use `from numpy.typing import NDArray` to import the type.


### `type_prefixes`

- [TOML type](https://toml.io/en/latest): table, mapping string to string

Prefixes for external modules to match types in docstrings.
Docstub can't yet automatically discover where to import types from other packages from.
Instead, you can provide this information explicitly.
Any type in a docstring whose prefix matches the name given on the left side, will be associated with the given "module" on the right side.

Example:

```toml
[tool.docstub.type_prefixes]
np = "numpy"
plt = "matplotlib.pyplot
```

- Will match `np.uint8` and `np.typing.NDarray` and use `import numpy as np`.
- Will match `plt.Figure` use `import matplotlib.pyplot as plt`.


### `type_nicknames`

- [TOML type](https://toml.io/en/latest): table, mapping string to string

Nicknames for types that can be used in docstrings to describe valid Python types or annotations.

Example:

```toml
[tool.docstub.type_nicknames]
func = "Callable"
```

- Will map `func` to the `Callable` type from the `typing` module.
8 changes: 6 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ maintainers = [
]
description = "Generate Python stub files from docstrings"
readme = "README.md"
license = "BSD-3-Clause"
license-files = ["LICENSE"]

# Need to include license of vendored code as well
license = "BSD-3-Clause AND PSF-2.0"
license-files = ["LICENSE.txt"]

requires-python = ">=3.12"
keywords = ["typing", "stub files", "docstings", "numpydoc"]
classifiers = [
Expand Down Expand Up @@ -120,6 +123,7 @@ run.source = ["docstub"]
Path = "pathlib"

[tool.docstub.type_prefixes]
re = "re"
cst = "libcst"
lark = "lark"
numpydoc = "numpydoc"
Expand Down
67 changes: 42 additions & 25 deletions src/docstub/_cli.py
Loading