Skip to content

Commit af84d77

Browse files
committed
merge: Merge branch 'main' into ConstructorChecking_ASTValidator, ensure --pre flag remains in pre-release test workflow.
2 parents b62c21f + 8044135 commit af84d77

File tree

15 files changed

+55
-101
lines changed

15 files changed

+55
-101
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
python3 -m venv venv
2121
source venv/bin/activate
2222
python -m pip install --upgrade pip wheel setuptools
23-
python -m pip install --upgrade -r requirements/doc.txt
23+
python -m pip install --upgrade --group doc
2424
python -m pip list
2525
- save_cache:
2626
key: pip-cache

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ jobs:
55
name: Run CircleCI artifacts redirector
66
steps:
77
- name: GitHub Action step
8-
uses: scientific-python/circleci-artifacts-redirector-action@4e13a10d89177f4bfc8007a7064bdbeda848d8d1 # v1.0.0
8+
uses: scientific-python/circleci-artifacts-redirector-action@7eafdb60666f57706a5525a2f5eb76224dc8779b # v1.1.0
99
with:
1010
repo-token: ${{ secrets.GITHUB_TOKEN }}
1111
api-token: ${{ secrets.CIRCLECI_ARTIFACT_REDIRECTOR_TOKEN }}

.github/workflows/test.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ jobs:
3838
run: |
3939
python -m pip install --upgrade pip wheel setuptools
4040
python -m pip install codecov
41-
python -m pip install ${{ matrix.sphinx-version }}
41+
python -m pip install "${{ matrix.sphinx-version }}"
4242
python -m pip list
4343
4444
- name: Install
4545
run: |
46-
python -m pip install .[test,doc]
46+
python -m pip install . --group test --group doc
4747
pip list
4848
4949
- name: Run test suite
@@ -96,7 +96,7 @@ jobs:
9696
9797
- name: Install
9898
run: |
99-
python -m pip install --pre .[test,doc]
99+
python -m pip install . --pre --group test --group doc
100100
pip list
101101
102102
- name: Run test suite

.pre-commit-config.yaml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,6 @@ repos:
3131
args: ["--fix", "--show-fixes", "--exit-non-zero-on-fix"]
3232
- id: ruff-format
3333

34-
- repo: local
35-
hooks:
36-
- id: generate_requirements.py
37-
name: generate_requirements.py
38-
language: system
39-
entry: python tools/generate_requirements.py
40-
files: "pyproject.toml|requirements/.*\\.txt|tools/generate_requirements.py"
41-
4234
ci:
4335
autofix_prs: false
4436
autofix_commit_msg: |

.readthedocs.yaml

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,15 @@ build:
1313
# nodejs: "19"
1414
# rust: "1.64"
1515
# golang: "1.19"
16+
jobs:
17+
install:
18+
- python -m pip install --upgrade pip wheel setuptools
19+
- python -m pip install . --group doc
1620

1721
# Build documentation in the "doc/" directory with Sphinx
1822
sphinx:
1923
configuration: doc/conf.py
20-
2124
# Optionally build your docs in additional formats such as PDF and ePub
2225
# formats:
2326
# - pdf
2427
# - epub
25-
26-
# Optional but recommended, declare the Python requirements required
27-
# to build your documentation
28-
# See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
29-
python:
30-
install:
31-
- method: pip
32-
path: .
33-
extra_requirements:
34-
- doc

MANIFEST.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ include MANIFEST.in
22
include *.txt
33
include *.rst
44
recursive-include doc *
5-
recursive-include requirements *
65
recursive-include numpydoc *
76

87
# Exclude what we don't want to include

doc/format.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -769,9 +769,9 @@ leads to the following style recommendations:
769769
enclosed within ````double backticks````.
770770

771771
A more extensive example of reST markup can be found in `this example
772-
document <http://docutils.sourceforge.net/docs/user/rst/demo.txt>`_;
772+
document <https://docutils.sourceforge.net/docs/user/rst/demo.rst>`_;
773773
the `quick reference
774-
<http://docutils.sourceforge.net/docs/user/rst/quickref.html>`_ is
774+
<https://docutils.sourceforge.net/docs/user/rst/quickref.html>`_ is
775775
useful while editing.
776776

777777
Line spacing and indentation are significant and should be carefully

numpydoc/hooks/validate_docstrings.py

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@ class AstValidator(validate.Validator):
3333
"""
3434

3535
def __init__(
36-
self, *, ast_node: ast.AST, filename: os.PathLike, obj_name: str
36+
self,
37+
*,
38+
ast_node: ast.AST,
39+
filename: os.PathLike,
40+
obj_name: str,
41+
ancestry: list[ast.AST],
3742
) -> None:
3843
self.node: ast.AST = ast_node
3944
self.raw_doc: str = ast.get_docstring(self.node, clean=False) or ""
@@ -46,6 +51,8 @@ def __init__(
4651
self.is_class: bool = isinstance(ast_node, ast.ClassDef)
4752
self.is_module: bool = isinstance(ast_node, ast.Module)
4853

54+
self.ancestry: list[ast.AST] = ancestry
55+
4956
@staticmethod
5057
def _load_obj(name):
5158
raise NotImplementedError("AstValidator does not support this method.")
@@ -91,7 +98,7 @@ def source_file_def_line(self) -> int:
9198

9299
@property
93100
def signature_parameters(self) -> Tuple[str]:
94-
def extract_signature(node):
101+
def extract_signature(node, parent):
95102
args_node = node.args
96103
params = []
97104
for arg_type in ["posonlyargs", "args", "vararg", "kwonlyargs", "kwarg"]:
@@ -104,17 +111,21 @@ def extract_signature(node):
104111
else:
105112
params.extend([arg.arg for arg in entries])
106113
params = tuple(params)
107-
if params and params[0] in {"self", "cls"}:
114+
if (
115+
params
116+
and params[0] in {"self", "cls"}
117+
and isinstance(parent, ast.ClassDef)
118+
):
108119
return params[1:]
109120
return params
110121

111122
params = tuple()
112123
if self.is_function_or_method:
113-
params = extract_signature(self.node)
124+
params = extract_signature(self.node, self.ancestry[-1])
114125
elif self.is_class:
115126
for child in self.node.body:
116127
if isinstance(child, ast.FunctionDef) and child.name == "__init__":
117-
params = extract_signature(child)
128+
params = extract_signature(child, self.node)
118129
return params
119130

120131
@property
@@ -144,9 +155,23 @@ def __init__(
144155
self.config: dict = config
145156
self.filepath: str = filepath
146157
self.module_name: str = Path(self.filepath).stem
147-
self.stack: list[str] = []
158+
self.stack: list[ast.AST] = []
148159
self.findings: list = []
149160

161+
@property
162+
def node_name(self) -> str:
163+
"""
164+
Get the full name of the current node in the stack.
165+
166+
Returns
167+
-------
168+
str
169+
The full name of the current node in the stack.
170+
"""
171+
return ".".join(
172+
[getattr(node, "name", self.module_name) for node in self.stack]
173+
)
174+
150175
def _ignore_issue(self, node: ast.AST, check: str) -> bool:
151176
"""
152177
Check whether the issue should be ignored.
@@ -185,9 +210,13 @@ def _get_numpydoc_issues(self, node: ast.AST) -> None:
185210
node : ast.AST
186211
The node under inspection.
187212
"""
188-
name = ".".join(self.stack)
213+
name = self.node_name
189214
report = validate.validate(
190-
name, AstValidator, ast_node=node, filename=self.filepath
215+
name,
216+
AstValidator,
217+
ast_node=node,
218+
filename=self.filepath,
219+
ancestry=self.stack[:-1],
191220
)
192221
self.findings.extend(
193222
[
@@ -209,13 +238,11 @@ def visit(self, node: ast.AST) -> None:
209238
if isinstance(
210239
node, (ast.Module, ast.ClassDef, ast.FunctionDef, ast.AsyncFunctionDef)
211240
):
212-
self.stack.append(
213-
self.module_name if isinstance(node, ast.Module) else node.name
214-
)
241+
self.stack.append(node)
215242

216243
if not (
217244
self.config["exclude"]
218-
and re.search(self.config["exclude"], ".".join(self.stack))
245+
and re.search(self.config["exclude"], self.node_name)
219246
):
220247
self._get_numpydoc_issues(node)
221248

numpydoc/numpydoc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ def setup(app, get_doc_object_=get_doc_object):
296296
app.add_config_value("numpydoc_attributes_as_param_list", True, True)
297297
app.add_config_value("numpydoc_xref_param_type", False, True)
298298
app.add_config_value("numpydoc_xref_aliases", dict(), True)
299-
app.add_config_value("numpydoc_xref_ignore", set(), True)
299+
app.add_config_value("numpydoc_xref_ignore", set(), True, types=[set, str])
300300
app.add_config_value("numpydoc_validation_checks", set(), True)
301301
app.add_config_value("numpydoc_validation_exclude", set(), False)
302302
app.add_config_value("numpydoc_validation_overrides", dict(), False)

pyproject.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,12 @@ file = 'LICENSE.txt'
4343
Homepage = 'https://numpydoc.readthedocs.io'
4444
Source = 'https://github.com/numpy/numpydoc/'
4545

46-
[project.optional-dependencies]
47-
developer = [
46+
[dependency-groups]
47+
dev = [
4848
'pre-commit>=3.3',
4949
"tomli; python_version < '3.11'",
50+
{ include-group = "doc" },
51+
{ include-group = "test" }
5052
]
5153
doc = [
5254
'numpy>=1.22',

0 commit comments

Comments
 (0)