Skip to content

Commit 23afd6b

Browse files
committed
Merge branch 'main' into refactoring
2 parents 38839e7 + 80a7ce4 commit 23afd6b

73 files changed

Lines changed: 3740 additions & 933 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/dependabot.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ updates:
55
directory: "/"
66
schedule:
77
interval: "quarterly"
8+
cooldown:
9+
default-days: 14
810
labels:
911
- "devops"
1012
- "bot"
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env bash
2+
3+
# Assert that there are no changes in a given directory compared to HEAD.
4+
# Expects a relative directory as the one and only argument.
5+
6+
set -e
7+
8+
CHECK_DIR=$1
9+
10+
# Find untracked files
11+
UNTRACKED=$(git ls-files --others --exclude-standard "$CHECK_DIR")
12+
13+
# Display diff of each untracked file by comparing with '/dev/null'
14+
# Hide exit code of `git diff` to avoid early exit due to `set -e`
15+
echo "$UNTRACKED" | xargs -I _ git --no-pager diff /dev/null _ || true
16+
17+
# Display changes in tracked files and capture non-zero exit code if so
18+
set +e
19+
git diff --exit-code HEAD "$CHECK_DIR"
20+
GIT_DIFF_HEAD_EXIT_CODE=$?
21+
set -e
22+
23+
# Display changes in tracked files and capture exit status
24+
if [ $GIT_DIFF_HEAD_EXIT_CODE -ne 0 ] || [ -n "$UNTRACKED" ]; then
25+
echo "::error::Uncommited changes in directory '$CHECK_DIR'"
26+
git status --porcelain
27+
exit 1
28+
else
29+
echo "::notice::No Uncommited changes, directory '$CHECK_DIR' is clean"
30+
fi
31+
32+
set +e

.github/workflows/cd.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ jobs:
2626
- uses: actions/checkout@v5
2727
with:
2828
fetch-depth: 0
29+
persist-credentials: false
2930

30-
- uses: actions/setup-python@v5
31+
- uses: actions/setup-python@v6
3132
with:
3233
python-version: "3.13"
3334

@@ -38,4 +39,4 @@ jobs:
3839
python -m build --sdist --wheel
3940
4041
- name: Publish to PyPI
41-
uses: pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc # v1.12.4
42+
uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # v1.13.0

.github/workflows/ci.yml

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ on:
77
branches:
88
- main
99

10+
permissions: {}
11+
1012
concurrency:
1113
group: ${{ github.workflow }}-${{ github.ref }}
1214
cancel-in-progress: true
@@ -15,7 +17,7 @@ env:
1517
# Many color libraries just need this to be set to any value, but at least
1618
# one distinguishes color depth, where "3" -> "256-bit color".
1719
FORCE_COLOR: 3
18-
MYPYPATH: ${{ github.workspace }}/stubs
20+
PIP_PROGRESS_BAR: "off"
1921

2022
defaults:
2123
run:
@@ -30,10 +32,11 @@ jobs:
3032
- uses: actions/checkout@v5
3133
with:
3234
fetch-depth: 0
33-
- uses: actions/setup-python@v5
35+
persist-credentials: false
36+
- uses: actions/setup-python@v6
3437
with:
3538
python-version: "3.x"
36-
- uses: pre-commit/action@v3.0.1
39+
- uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1
3740
with:
3841
extra_args: --hook-stage manual --all-files
3942

@@ -46,22 +49,26 @@ jobs:
4649
runs-on:
4750
- { short: linux, name: ubuntu-latest }
4851
- { short: win, name: windows-latest }
49-
- { short: macos, name: macos-14 }
50-
python-version: ["3.12", "3.13"]
52+
- { short: macos, name: macos-latest }
53+
python-version: ["3.12", "3.14"]
54+
include:
55+
- runs-on: { short: linux, name: ubuntu-latest }
56+
python-version: "3.13"
5157

5258
steps:
5359
- uses: actions/checkout@v5
5460
with:
5561
fetch-depth: 0
62+
persist-credentials: false
5663

57-
- uses: actions/setup-python@v5
64+
- uses: actions/setup-python@v6
5865
with:
5966
python-version: ${{ matrix.python-version }}
6067
allow-prereleases: true
6168

6269
- name: Install package
6370
run: |
64-
python -m pip install .[test]
71+
python -m pip install --group "test" .
6572
python -m docstub --version
6673
docstub --help
6774
@@ -71,17 +78,31 @@ jobs:
7178
7279
# TODO upload coverage statistics, and fail on decrease?
7380

74-
- name: Compare example stubs
81+
- name: Check example_pkg-stubs
82+
# Check that stubs for example_pkg are up-to-date by regenerating them
83+
# with docstub and looking for differences.
7584
run: |
85+
rm -rf examples/example_pkg-stubs
7686
python -m docstub run -v \
7787
--config=examples/docstub.toml \
7888
--out-dir=examples/example_pkg-stubs \
7989
examples/example_pkg
80-
git diff --exit-code examples/ && echo "Stubs for example_pkg did not change"
90+
.github/scripts/assert-unchanged.sh examples/
91+
92+
- name: Check docstub-stubs (single process)
93+
# Check that stubs for docstub are up-to-date by regenerating them
94+
# with docstub and looking for differences.
95+
run: |
96+
rm -rf src/docstub-stubs
97+
python -m docstub run -v src/docstub -o src/docstub-stubs
98+
.github/scripts/assert-unchanged.sh src/docstub-stubs/
8199
82-
- name: Generate stubs for docstub
100+
- name: Check docstub-stubs (multiprocess)
101+
# Repeat test with multiprocessing enabled
83102
run: |
84-
python -m docstub run -v src/docstub -o ${MYPYPATH}/docstub
103+
rm -rf src/docstub-stubs
104+
python -m docstub run -v src/docstub -o src/docstub-stubs --workers 2
105+
.github/scripts/assert-unchanged.sh src/docstub-stubs/
85106
86107
- name: Check with mypy.stubtest
87108
run: |

.pre-commit-config.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
exclude: |
44
(?x)^(
55
examples/.*-stubs/.*|
6+
src/docstub-stubs/.*|
67
)$
78
89
repos:
@@ -27,8 +28,13 @@ repos:
2728
args: [--markdown-linebreak-ext=md]
2829

2930
- repo: https://github.com/astral-sh/ruff-pre-commit
30-
rev: "0acff885bcb16381b67930fefb91e460202f172c" # frozen: v0.12.10
31+
rev: "f298305809c552671cc47e0fec0ba43e96c146a2" # frozen: v0.13.2
3132
hooks:
3233
- id: ruff-check
3334
args: ["--fix", "--show-fixes", "--exit-non-zero-on-fix"]
3435
- id: ruff-format
36+
37+
- repo: https://github.com/woodruffw/zizmor-pre-commit
38+
rev: 3c10df247c55cf21f75003105b879f145096bd4a # frozen: v1.14.2
39+
hooks:
40+
- id: zizmor

.readthedocs.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Read the Docs configuration file
2+
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
3+
4+
# Required
5+
version: 2
6+
7+
# Set the OS, Python version, and other tools you might need
8+
build:
9+
os: ubuntu-24.04
10+
tools:
11+
python: "3.13"
12+
commands:
13+
# https://docs.readthedocs.com/platform/stable/build-customization.html#install-dependencies-with-uv
14+
- asdf plugin add uv
15+
- asdf install uv latest
16+
- asdf global uv latest
17+
- uv run --group docs sphinx-build -T -b html -d docs/_build/doctrees -D language=en docs $READTHEDOCS_OUTPUT/html

README.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,20 @@
22

33
> [!NOTE]
44
> **In early development!**
5-
> Expect bugs, missing features, and incomplete documentation.
6-
> Docstub is still evaluating which features it needs to support as the community gives feedback.
7-
> Several features are experimental and included to make adoption of docstub easier.
8-
> Long-term, some of these might be discouraged or removed as docstub matures.
5+
> Docstub is not feature-complete or thoroughly tested yet.
6+
> Its behavior, configuration or command line interface may change significantly between releases.
97
10-
docstub is a command-line tool to generate [Python stub files](https://typing.python.org/en/latest/guides/writing_stubs.html) (i.e., PYI files) from type descriptions found in [numpydoc](https://numpydoc.readthedocs.io)-style docstrings.
8+
docstub is a command-line tool to generate [Python stub files](https://typing.python.org/en/latest/guides/writing_stubs.html).
9+
It extracts necessary type information from [NumPyDoc style](https://numpydoc.readthedocs.io) docstrings.
1110

1211
Many packages in the scientific Python ecosystem already describe expected parameter and return types in their docstrings.
1312
Docstub aims to take advantage of these and help with the adoption of type annotations.
14-
It does so by supporting widely used readable conventions such as `array of dtype` or `iterable of int(s)` which it translates into valid type annotations.
13+
It does so by supporting widely used readable conventions such as `array of dtype` or `iterable of int(s)` which are translated into valid type annotations.
1514

1615

1716
## Installation & getting started
1817

19-
Please refer to the [user guide](https://github.com/scientific-python/docstub/blob/main/docs/user_guide.md) 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.
2019

2120

2221
## Contributing

REMINDERS.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Reminders
2+
3+
## With Python >=3.13
4+
5+
Remove vendored `glob_translate` in `docstub._vendored.stdlib`.
6+
7+
8+
## With Python >=3.14
9+
10+
Remove vendored `ProcessPoolExecutor` in `docstub._vendored.stdlib`.

docs/command_line.md

Lines changed: 61 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
1-
# Command line reference
1+
# Command line
22

3-
## Command `docstub`
3+
The reference for docstub's command line interface.
4+
It uses [Click](https://click.palletsprojects.com/en/stable/), so [shell completion](https://click.palletsprojects.com/en/stable/shell-completion/) can be enabled.
5+
6+
Colored command line output can be disabled by [setting the environment variable `NO_COLOR=1`](https://no-color.org).
7+
8+
9+
## `docstub`
410

511
<!--- The following block is checked by the test suite --->
612
<!--- begin cli-docstub --->
713

8-
```plain
14+
```none
915
Usage: docstub [OPTIONS] COMMAND [ARGS]...
1016
1117
Generate Python stub files from docstrings.
1218
1319
Options:
14-
--version Show the version and exit.
15-
-h, --help Show this message and exit.
20+
--version
21+
Show the version and exit.
22+
-h, --help
23+
Show this message and exit.
1624
1725
Commands:
1826
clean Clean the cache.
@@ -22,51 +30,67 @@ Commands:
2230
<!--- end cli-docstub --->
2331

2432

25-
## Command `docstub run`
33+
## `docstub run`
2634

2735
<!--- The following block is checked by the test suite --->
2836
<!--- begin cli-docstub-run --->
2937

30-
```plain
38+
```none
3139
Usage: docstub run [OPTIONS] PACKAGE_PATH
3240
3341
Generate Python stub files.
3442
35-
Given a `PACKAGE_PATH` to a Python package, generate stub files for it. Type
43+
Given a PACKAGE_PATH to a Python package, generate stub files for it. Type
3644
descriptions in docstrings will be used to fill in missing inline type
3745
annotations or to override them.
3846
3947
Options:
40-
-o, --out-dir PATH Set output directory explicitly. Stubs will be directly
41-
written into that directory while preserving the
42-
directory structure under `PACKAGE_PATH`. Otherwise,
43-
stubs are generated inplace.
44-
--config PATH Set one or more configuration file(s) explicitly.
45-
Otherwise, it will look for a `pyproject.toml` or
46-
`docstub.toml` in the current directory.
47-
--ignore GLOB Ignore files matching this glob-style pattern. Can be
48-
used multiple times.
49-
--group-errors Group identical errors together and list where they
50-
occurred. Will delay showing errors until all files have
51-
been processed. Otherwise, simply report errors as the
52-
occur.
53-
--allow-errors INT Allow this many or fewer errors. If docstub reports
54-
more, exit with error code '1'. This is useful to adopt
55-
docstub gradually. [default: 0; x>=0]
56-
--no-cache Ignore pre-existing cache and don't create a new one.
57-
-v, --verbose Print more details (repeatable).
58-
-h, --help Show this message and exit.
48+
-o, --out-dir PATH
49+
Set output directory explicitly. Stubs will be directly written into
50+
that directory while preserving the directory structure under
51+
PACKAGE_PATH. Otherwise, stubs are generated inplace.
52+
--ignore GLOB
53+
Ignore files matching this glob-style pattern. Can be used multiple
54+
times.
55+
-g, --group-errors
56+
Group identical errors together and list where they occurred. Will
57+
delay showing errors until all files have been processed. Otherwise,
58+
simply report errors as the occur.
59+
--allow-errors INT
60+
Allow this many or fewer errors. If docstub reports more, exit with
61+
error code 1. This is useful to adopt docstub gradually. [default:
62+
0; x>=0]
63+
-W, --fail-on-warning
64+
Return non-zero exit code when a warning is raised. Will add to
65+
--allow-errors.
66+
--workers INT
67+
Experimental: Process files in parallel with the desired number of
68+
workers. By default, no multiprocessing is used. [default: 1]
69+
--no-cache
70+
Ignore pre-existing cache and don't create a new one.
71+
--config PATH
72+
Set one or more configuration file(s) explicitly. Otherwise, it will
73+
look for a `pyproject.toml` or `docstub.toml` in the current
74+
directory.
75+
-v, --verbose
76+
Print more details. Use once to show information messages. Use -vv to
77+
print debug messages.
78+
-q, --quiet
79+
Print less details. Use once to hide warnings. Use -qq to completely
80+
silence output.
81+
-h, --help
82+
Show this message and exit.
5983
```
6084

6185
<!--- end cli-docstub-run --->
6286

6387

64-
## Command `docstub clean`
88+
## `docstub clean`
6589

6690
<!--- The following block is checked by the test suite --->
6791
<!--- begin cli-docstub-clean --->
6892

69-
```plain
93+
```none
7094
Usage: docstub clean [OPTIONS]
7195
7296
Clean the cache.
@@ -75,8 +99,14 @@ Usage: docstub clean [OPTIONS]
7599
one exists, remove it.
76100
77101
Options:
78-
-v, --verbose Print more details (repeatable).
79-
-h, --help Show this message and exit.
102+
-v, --verbose
103+
Print more details. Use once to show information messages. Use -vv to
104+
print debug messages.
105+
-q, --quiet
106+
Print less details. Use once to hide warnings. Use -qq to completely
107+
silence output.
108+
-h, --help
109+
Show this message and exit.
80110
```
81111

82112
<!--- end cli-docstub-clean --->

0 commit comments

Comments
 (0)