Skip to content

Commit ffcddf6

Browse files
committed
Merge branch 'main' into refactoring
2 parents a2ffae6 + 84232b1 commit ffcddf6

38 files changed

Lines changed: 2443 additions & 707 deletions

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!--
2+
- Reference relevant issues or related pull requests with their URL / #<number>.
3+
- Use `pre-commit` to check and format code.
4+
-->
5+
6+
7+
## Release note
8+
9+
For maintainers and optionally contributors, please refer to [changelist's README](https://github.com/scientific-python/changelist) on how to document this PR for the release notes.
10+
11+
```release-note
12+
...
13+
```

.github/dependabot.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
version: 2
2+
updates:
3+
# Maintain dependencies for GitHub Actions
4+
- package-ecosystem: "github-actions"
5+
directory: "/"
6+
schedule:
7+
interval: "quarterly"
8+
labels:
9+
- "devops"
10+
- "bot"
11+
groups:
12+
actions:
13+
patterns:
14+
- "*"

.github/workflows/cd.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
permissions:
2424
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
2525
steps:
26-
- uses: actions/checkout@v4
26+
- uses: actions/checkout@v5
2727
with:
2828
fetch-depth: 0
2929

.github/workflows/ci.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
name: pre-commit
2828
runs-on: ubuntu-latest
2929
steps:
30-
- uses: actions/checkout@v4
30+
- uses: actions/checkout@v5
3131
with:
3232
fetch-depth: 0
3333
- uses: actions/setup-python@v5
@@ -50,7 +50,7 @@ jobs:
5050
python-version: ["3.12", "3.13"]
5151

5252
steps:
53-
- uses: actions/checkout@v4
53+
- uses: actions/checkout@v5
5454
with:
5555
fetch-depth: 0
5656

@@ -73,7 +73,10 @@ jobs:
7373

7474
- name: Compare example stubs
7575
run: |
76-
python -m docstub run -v --config=examples/docstub.toml examples/example_pkg
76+
python -m docstub run -v \
77+
--config=examples/docstub.toml \
78+
--out-dir=examples/example_pkg-stubs \
79+
examples/example_pkg
7780
git diff --exit-code examples/ && echo "Stubs for example_pkg did not change"
7881
7982
- name: Generate stubs for docstub

.pre-commit-config.yaml

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,28 @@ exclude: |
77
88
repos:
99
- repo: https://github.com/pre-commit/pre-commit-hooks
10-
rev: "cef0300fd0fc4d2a87a85fa2093c6b283ea36f4b" # frozen: v5.0.0
10+
rev: "3e8a8703264a2f4a69428a0aa4dcb512790b2c8c" # frozen: v6.0.0
1111
hooks:
1212
- id: check-added-large-files
1313
- id: check-ast
14-
- id: check-builtin-literals
1514
- id: check-case-conflict
1615
- id: check-merge-conflict
1716
- id: check-symlinks
18-
- id: check-yaml
19-
args: [--allow-multiple-documents]
2017
- id: check-json
2118
- id: check-toml
19+
- id: check-yaml
20+
args: [--allow-multiple-documents]
2221
- id: debug-statements
23-
- id: end-of-file-fixer
22+
- id: detect-private-key
2423
- id: mixed-line-ending
2524
- id: name-tests-test
2625
args: ["--pytest-test-first"]
27-
- id: requirements-txt-fixer
2826
- id: trailing-whitespace
29-
30-
- repo: https://github.com/psf/black
31-
rev: "1b2427a2b785cc4aac97c19bb4b9a0de063f9547" # frozen: 24.10.0
32-
hooks:
33-
- id: black
27+
args: [--markdown-linebreak-ext=md]
3428

3529
- repo: https://github.com/astral-sh/ruff-pre-commit
36-
rev: "75b98813cfb7e663870a28c74366a1e99d7bfe79" # frozen: v0.6.9
30+
rev: "0acff885bcb16381b67930fefb91e460202f172c" # frozen: v0.12.10
3731
hooks:
38-
- id: ruff
32+
- id: ruff-check
3933
args: ["--fix", "--show-fixes", "--exit-non-zero-on-fix"]
34+
- id: ruff-format

LICENSE

Lines changed: 0 additions & 30 deletions
This file was deleted.

LICENSE.txt

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
2+
Source: https://github.com/scientific-python/docstub
3+
4+
Files: *
5+
Copyright: 2025, Scientific Python Developers
6+
2024, Lars Grüter
7+
License: BSD 3-Clause
8+
9+
Files: src/docstub/_vendored/stdlib.py
10+
Copyright: 2001-2025, Python Software Foundation
11+
License: PSF-2.0
12+
13+
License: BSD-3-Clause
14+
All rights reserved.
15+
.
16+
Redistribution and use in source and binary forms, with or without
17+
modification, are permitted provided that the following conditions are met:
18+
.
19+
* Redistributions of source code must retain the above copyright notice, this
20+
list of conditions and the following disclaimer.
21+
.
22+
* Redistributions in binary form must reproduce the above copyright notice,
23+
this list of conditions and the following disclaimer in the documentation
24+
and/or other materials provided with the distribution.
25+
.
26+
* Neither the name of the vector package developers nor the names of its
27+
contributors may be used to endorse or promote products derived from
28+
this software without specific prior written permission.
29+
.
30+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
31+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
32+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
33+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
34+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
35+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
36+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
37+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
38+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40+
41+
42+
License: PSF-2.0
43+
PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
44+
--------------------------------------------
45+
.
46+
1. This LICENSE AGREEMENT is between the Python Software Foundation
47+
("PSF"), and the Individual or Organization ("Licensee") accessing and
48+
otherwise using this software ("Python") in source or binary form and
49+
its associated documentation.
50+
.
51+
2. Subject to the terms and conditions of this License Agreement, PSF hereby
52+
grants Licensee a nonexclusive, royalty-free, world-wide license to reproduce,
53+
analyze, test, perform and/or display publicly, prepare derivative works,
54+
distribute, and otherwise use Python alone or in any derivative version,
55+
provided, however, that PSF's License Agreement and PSF's notice of copyright,
56+
i.e., "Copyright (c) 2001 Python Software Foundation; All Rights Reserved"
57+
are retained in Python alone or in any derivative version prepared by Licensee.
58+
.
59+
3. In the event Licensee prepares a derivative work that is based on
60+
or incorporates Python or any part thereof, and wants to make
61+
the derivative work available to others as provided herein, then
62+
Licensee hereby agrees to include in any such work a brief summary of
63+
the changes made to Python.
64+
.
65+
4. PSF is making Python available to Licensee on an "AS IS"
66+
basis. PSF MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
67+
IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, PSF MAKES NO AND
68+
DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS
69+
FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON WILL NOT
70+
INFRINGE ANY THIRD PARTY RIGHTS.
71+
.
72+
5. PSF SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON
73+
FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS
74+
A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON,
75+
OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.
76+
.
77+
6. This License Agreement will automatically terminate upon a material
78+
breach of its terms and conditions.
79+
.
80+
7. Nothing in this License Agreement shall be deemed to create any
81+
relationship of agency, partnership, or joint venture between PSF and
82+
Licensee. This License Agreement does not grant permission to use PSF
83+
trademarks or trade name in a trademark sense to endorse or promote
84+
products or services of Licensee, or any third party.
85+
.
86+
8. By copying, installing or otherwise using Python, Licensee
87+
agrees to be bound by the terms and conditions of this License
88+
Agreement.

docs/command_line.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ Options:
1515
-h, --help Show this message and exit.
1616
1717
Commands:
18-
run Generate Python stub files.
18+
clean Clean the cache.
19+
run Generate Python stub files.
1920
```
2021

2122
<!--- end cli-docstub --->
@@ -43,15 +44,39 @@ Options:
4344
--config PATH Set one or more configuration file(s) explicitly.
4445
Otherwise, it will look for a `pyproject.toml` or
4546
`docstub.toml` in the current directory.
47+
--ignore GLOB Ignore files matching this glob-style pattern. Can be
48+
used multiple times.
4649
--group-errors Group identical errors together and list where they
4750
occurred. Will delay showing errors until all files have
4851
been processed. Otherwise, simply report errors as the
4952
occur.
5053
--allow-errors INT Allow this many or fewer errors. If docstub reports
5154
more, exit with error code '1'. This is useful to adopt
5255
docstub gradually. [default: 0; x>=0]
56+
--no-cache Ignore pre-existing cache and don't create a new one.
5357
-v, --verbose Print more details (repeatable).
5458
-h, --help Show this message and exit.
5559
```
5660

5761
<!--- end cli-docstub-run --->
62+
63+
64+
## Command `docstub clean`
65+
66+
<!--- The following block is checked by the test suite --->
67+
<!--- begin cli-docstub-clean --->
68+
69+
```plain
70+
Usage: docstub clean [OPTIONS]
71+
72+
Clean the cache.
73+
74+
Looks for a cache directory relative to the current working directory. If
75+
one exists, remove it.
76+
77+
Options:
78+
-v, --verbose Print more details (repeatable).
79+
-h, --help Show this message and exit.
80+
```
81+
82+
<!--- end cli-docstub-clean --->

docs/configuration.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# Configuration reference
2+
3+
Docstub will automatically look for configuration in files named
4+
5+
- `pyproject.toml`, and
6+
- `docstub.toml`
7+
8+
in the current working directory.
9+
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.
10+
Multiple configuration files can be used, whose content will be merged.
11+
12+
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.
13+
14+
15+
## Configuration fields in `[tool.docstub]`
16+
17+
All configuration must be declared inside a `[tool.docstub]` table.
18+
19+
20+
### `ignore_files`
21+
22+
- [TOML type](https://toml.io/en/latest): array of string(s)
23+
24+
Ignore files and directories matching these [glob-style patterns](https://docs.python.org/3/library/glob.html#glob.translate).
25+
Patterns that don't start with "/" are interpreted as relative to the
26+
directory that contains the Python package for which stubs are generated.
27+
28+
Example:
29+
30+
```toml
31+
[tool.docstub]
32+
ignore_files = [
33+
"**/tests",
34+
]
35+
```
36+
37+
- Will ignore any directory anywhere that is named `tests`.
38+
39+
40+
### `types`
41+
42+
- [TOML type](https://toml.io/en/latest): table, mapping string to string
43+
44+
Types and their external modules to use in docstrings.
45+
Docstub can't yet automatically discover where to import types from other packages from.
46+
Instead, you can provide this information explicitly.
47+
Any type on the left side will be associated with the given "module" on the right side.
48+
49+
Example:
50+
51+
```toml
52+
[tool.docstub.types]
53+
Path = "pathlib"
54+
NDArray = "numpy.typing"
55+
```
56+
57+
- Will allow using `Path` in docstrings and will use `from pathlib import Path` to import the type.
58+
- Will allow using `NDarray` in docstrings and will use `from numpy.typing import NDArray` to import the type.
59+
60+
61+
### `type_prefixes`
62+
63+
- [TOML type](https://toml.io/en/latest): table, mapping string to string
64+
65+
Prefixes for external modules to match types in docstrings.
66+
Docstub can't yet automatically discover where to import types from other packages from.
67+
Instead, you can provide this information explicitly.
68+
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.
69+
70+
Example:
71+
72+
```toml
73+
[tool.docstub.type_prefixes]
74+
np = "numpy"
75+
plt = "matplotlib.pyplot
76+
```
77+
78+
- Will match `np.uint8` and `np.typing.NDarray` and use `import numpy as np`.
79+
- Will match `plt.Figure` use `import matplotlib.pyplot as plt`.
80+
81+
82+
### `type_nicknames`
83+
84+
- [TOML type](https://toml.io/en/latest): table, mapping string to string
85+
86+
Nicknames for types that can be used in docstrings to describe valid Python types or annotations.
87+
88+
Example:
89+
90+
```toml
91+
[tool.docstub.type_nicknames]
92+
func = "Callable"
93+
```
94+
95+
- Will map `func` to the `Callable` type from the `typing` module.

0 commit comments

Comments
 (0)