Skip to content

Commit e30210f

Browse files
committed
Merge branch 'main' into html-docs
2 parents 8982854 + c38eb34 commit e30210f

23 files changed

+868
-506
lines changed

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

.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: 12 additions & 5 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
@@ -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,15 +49,19 @@ 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

.pre-commit-config.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,13 @@ repos:
2727
args: [--markdown-linebreak-ext=md]
2828

2929
- repo: https://github.com/astral-sh/ruff-pre-commit
30-
rev: "0acff885bcb16381b67930fefb91e460202f172c" # frozen: v0.12.10
30+
rev: "f298305809c552671cc47e0fec0ba43e96c146a2" # frozen: v0.13.2
3131
hooks:
3232
- id: ruff-check
3333
args: ["--fix", "--show-fixes", "--exit-non-zero-on-fix"]
3434
- id: ruff-format
35+
36+
- repo: https://github.com/woodruffw/zizmor-pre-commit
37+
rev: 3c10df247c55cf21f75003105b879f145096bd4a # frozen: v1.14.2
38+
hooks:
39+
- id: zizmor

docs/command_line.md

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,25 +40,30 @@ Usage: docstub run [OPTIONS] PACKAGE_PATH
4040
annotations or to override them.
4141
4242
Options:
43-
-o, --out-dir PATH Set output directory explicitly. Stubs will be directly
44-
written into that directory while preserving the
45-
directory structure under `PACKAGE_PATH`. Otherwise,
46-
stubs are generated inplace.
47-
--config PATH Set one or more configuration file(s) explicitly.
48-
Otherwise, it will look for a `pyproject.toml` or
49-
`docstub.toml` in the current directory.
50-
--ignore GLOB Ignore files matching this glob-style pattern. Can be
51-
used multiple times.
52-
--group-errors Group identical errors together and list where they
53-
occurred. Will delay showing errors until all files have
54-
been processed. Otherwise, simply report errors as the
55-
occur.
56-
--allow-errors INT Allow this many or fewer errors. If docstub reports
57-
more, exit with error code '1'. This is useful to adopt
58-
docstub gradually. [default: 0; x>=0]
59-
--no-cache Ignore pre-existing cache and don't create a new one.
60-
-v, --verbose Print more details (repeatable).
61-
-h, --help Show this message and exit.
43+
-o, --out-dir PATH Set output directory explicitly. Stubs will be
44+
directly written into that directory while preserving
45+
the directory structure under `PACKAGE_PATH`.
46+
Otherwise, stubs are generated inplace.
47+
--config PATH Set one or more configuration file(s) explicitly.
48+
Otherwise, it will look for a `pyproject.toml` or
49+
`docstub.toml` in the current directory.
50+
--ignore GLOB Ignore files matching this glob-style pattern. Can be
51+
used multiple times.
52+
--group-errors Group identical errors together and list where they
53+
occurred. Will delay showing errors until all files
54+
have been processed. Otherwise, simply report errors
55+
as the occur.
56+
--allow-errors INT Allow this many or fewer errors. If docstub reports
57+
more, exit with error code '1'. This is useful to
58+
adopt docstub gradually. [default: 0; x>=0]
59+
-W, --fail-on-warning Return non-zero exit code when a warning is raised.
60+
Will add to '--allow-errors'.
61+
--no-cache Ignore pre-existing cache and don't create a new one.
62+
-v, --verbose Print more details. Use once to show information
63+
messages. Use '-vv' to print debug messages.
64+
-q, --quiet Print less details. Use once to hide warnings. Use
65+
'-qq' to completely silence output.
66+
-h, --help Show this message and exit.
6267
```
6368

6469
<!--- end cli-docstub-run --->
@@ -78,7 +83,10 @@ Usage: docstub clean [OPTIONS]
7883
one exists, remove it.
7984
8085
Options:
81-
-v, --verbose Print more details (repeatable).
86+
-v, --verbose Print more details. Use once to show information messages.
87+
Use '-vv' to print debug messages.
88+
-q, --quiet Print less details. Use once to hide warnings. Use '-qq' to
89+
completely silence output.
8290
-h, --help Show this message and exit.
8391
```
8492

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ classifiers = [
2727
"Programming Language :: Python :: 3 :: Only",
2828
"Programming Language :: Python :: 3.12",
2929
"Programming Language :: Python :: 3.13",
30+
"Programming Language :: Python :: 3.14",
3031
"Topic :: Software Development :: Code Generators",
3132
"Topic :: Scientific/Engineering",
3233
]

src/docstub/_analysis.py

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
from ._utils import accumulate_qualname, module_name_from_path, pyfile_checksum
1616

17-
logger = logging.getLogger(__name__)
17+
logger: logging.Logger = logging.getLogger(__name__)
1818

1919

2020
def _shared_leading_qualname(*qualnames):
@@ -104,6 +104,18 @@ def typeshed_Incomplete(cls):
104104
return import_
105105

106106
def format_import(self, relative_to=None):
107+
"""Format import as valid Python import statement.
108+
109+
Parameters
110+
----------
111+
relative_to : str, optional
112+
If a dot-delimited module name is given, format the import relative
113+
to it.
114+
115+
Returns
116+
-------
117+
formatted : str
118+
"""
107119
if self.implicit:
108120
msg = f"cannot import implicit object: {self.implicit!r}"
109121
raise RuntimeError(msg)
@@ -265,20 +277,6 @@ def common_known_types():
265277
return types
266278

267279

268-
@dataclass(slots=True, kw_only=True)
269-
class TypeCollectionResult:
270-
types: dict[str, PyImport]
271-
type_prefixes: dict[str, PyImport]
272-
273-
@classmethod
274-
def serialize(cls, result):
275-
pass
276-
277-
@classmethod
278-
def deserialize(cls, result):
279-
pass
280-
281-
282280
class TypeCollector(cst.CSTVisitor):
283281
"""Collect types from a given Python file.
284282
@@ -296,7 +294,13 @@ class TypeCollector(cst.CSTVisitor):
296294
"""
297295

298296
class ImportSerializer:
299-
"""Implements the `FuncSerializer` protocol to cache `TypeCollector.collect`."""
297+
"""Implements the `FuncSerializer` protocol to cache `TypeCollector.collect`.
298+
299+
Attributes
300+
----------
301+
suffix : ClassVar[str]
302+
encoding : ClassVar[str]
303+
"""
300304

301305
suffix = ".json"
302306
encoding = "utf-8"
@@ -524,7 +528,7 @@ def _resolve_nickname(self, name):
524528
resolved = name
525529
else:
526530
logger.warning(
527-
"reached limit while resolving nicknames for %r in %s, using %r",
531+
"Reached limit while resolving nicknames for %r in %s, using %r",
528532
original,
529533
self.current_file or "<file not known>",
530534
resolved,
@@ -572,7 +576,7 @@ def match(self, search):
572576
"%r (original %r) in %s matches multiple types %r, using %r",
573577
search,
574578
original_search,
575-
self.current_file or "<file not known>",
579+
self.current_file or "<file?>",
576580
matches.keys(),
577581
shortest_key,
578582
)

src/docstub/_cache.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22
from functools import cached_property
33
from typing import Any, Protocol
44

5-
logger = logging.getLogger(__name__)
5+
logger: logging.Logger = logging.getLogger(__name__)
66

77

8-
CACHE_DIR_NAME = ".docstub_cache"
8+
CACHE_DIR_NAME: str = ".docstub_cache"
99

1010

11-
CACHEDIR_TAG_CONTENT = """\
11+
CACHEDIR_TAG_CONTENT: str = """\
1212
Signature: 8a477f597d28d172789f06886806bc55
1313
# Mark this directory as a cache [1], created by docstub [2]
1414
# [1] https://bford.info/cachedir/
1515
# [2] https://github.com/scientific-python/docstub
1616
"""
1717

1818

19-
GITHUB_IGNORE_CONTENT = """\
19+
GITHUB_IGNORE_CONTENT: str = """\
2020
# Make git ignore this cache directory, created by docstub [1]
2121
# [1] https://github.com/scientific-python/docstub
2222
*
@@ -172,7 +172,7 @@ def cache_dir(self):
172172
create_cache(self._cache_dir)
173173

174174
if _directory_size(self._cache_dir) > 512 * 1024**2:
175-
logger.warning("cache size at %r exceeds 512 MiB", self._cache_dir)
175+
logger.warning("Cache size at %r exceeds 512 MiB", self._cache_dir)
176176

177177
return self._cache_dir
178178

0 commit comments

Comments
 (0)