Skip to content

Commit e790c68

Browse files
guillaumedavidphdlarsoneramoebarossbarjarrodmillman
authored
Merge from numpy/numpydoc (#1)
* MAINT: Fix CIs for sphinx 6 (numpy#448) * BUG: PR06 logic to only fail when type is used standalone (numpy#447) Change PR06 logic to only fail when type is used standalone. This prevents failures for user-defined classes, e.g. Mystring Co-authored-by: Ross Barnowski <[email protected]> * Update pre-commit (numpy#449) * Update pre-commit * Run pre-commit on all files * Update blacken-docs repo in pre-commit conf after owner transfer. (numpy#451) * MAINT: Compatibility with pydata-sphinx-theme (numpy#453) Fix compatibility issues between latest pydata-sphinx-theme and sphinx 6. Increase granularity of CI to test across necessary sphinx & Python version combos. * MAINT: Refactoring `get_doc_object` (numpy#452) --------- Co-authored-by: Eric Larson <[email protected]> Co-authored-by: Bryce Mecum <[email protected]> Co-authored-by: Ross Barnowski <[email protected]> Co-authored-by: Jarrod Millman <[email protected]> Co-authored-by: Stefanie Molin <[email protected]> Co-authored-by: yuki <[email protected]>
1 parent 5d0175c commit e790c68

File tree

9 files changed

+96
-50
lines changed

9 files changed

+96
-50
lines changed

.github/workflows/test.yml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
name: numpydoc tests
22

3+
concurrency:
4+
group: ${{ github.workflow }}-${{ github.event.number }}-${{ github.event.ref }}
5+
cancel-in-progress: true
6+
37
on:
48
push:
59
branches: [main]
@@ -14,7 +18,21 @@ jobs:
1418
os: [Ubuntu]
1519
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11-dev"]
1620
sphinx-version:
17-
["sphinx==4.2", "sphinx==4.5", "sphinx==5.0", "sphinx>=5.0"]
21+
[
22+
"sphinx==4.2",
23+
"sphinx==4.5",
24+
"sphinx==5.0",
25+
"sphinx==5.3",
26+
"sphinx==6.0",
27+
"sphinx>6.0",
28+
]
29+
exclude:
30+
- os: Ubuntu
31+
python-version: "3.7"
32+
sphinx-version: "sphinx==6.0"
33+
- os: Ubuntu
34+
python-version: "3.7"
35+
sphinx-version: "sphinx>6.0"
1836
steps:
1937
- uses: actions/checkout@v3
2038

@@ -55,6 +73,7 @@ jobs:
5573
run: |
5674
sudo apt-get update
5775
sudo apt install texlive texlive-latex-extra latexmk dvipng
76+
pip install "sphinx<6"
5877
5978
- name: Build documentation
6079
run: |
@@ -106,6 +125,7 @@ jobs:
106125
run: |
107126
sudo apt-get update
108127
sudo apt install texlive texlive-latex-extra latexmk dvipng
128+
pip install "sphinx<6"
109129
110130
- name: Build documentation
111131
run: |

.pre-commit-config.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
repos:
55
- repo: https://github.com/pre-commit/pre-commit-hooks
6-
rev: v4.3.0
6+
rev: v4.4.0
77
hooks:
88
- id: trailing-whitespace
99
- id: end-of-file-fixer
@@ -17,7 +17,7 @@ repos:
1717
- id: check-added-large-files
1818

1919
- repo: https://github.com/psf/black
20-
rev: 22.8.0
20+
rev: 23.1.0
2121
hooks:
2222
- id: black
2323

@@ -28,13 +28,13 @@ repos:
2828
files: \.(html|md|yml|yaml)
2929
args: [--prose-wrap=preserve]
3030

31-
- repo: https://github.com/asottile/blacken-docs
32-
rev: v1.12.1
31+
- repo: https://github.com/adamchainz/blacken-docs
32+
rev: 1.13.0
3333
hooks:
3434
- id: blacken-docs
3535

3636
- repo: https://github.com/asottile/pyupgrade
37-
rev: v2.38.2
37+
rev: v3.3.1
3838
hooks:
3939
- id: pyupgrade
4040
args: [--py37-plus]

doc/conf.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -81,23 +81,17 @@
8181

8282
html_theme = "pydata_sphinx_theme"
8383
html_theme_options = {
84-
"github_url": "https://github.com/numpy/numpydoc",
8584
"show_prev_next": False,
86-
"navbar_end": ["search-field.html", "navbar-icon-links.html"],
85+
"navbar_end": ["theme-switcher", "search-field.html", "navbar-icon-links.html"],
86+
"icon_links": [
87+
{
88+
"name": "GitHub",
89+
"url": "https://github.com/numpy/numpydoc",
90+
"icon": "fab fa-github-square",
91+
"type": "fontawesome",
92+
},
93+
],
8794
}
88-
# NOTE: The following is required for supporting of older sphinx toolchains.
89-
# The "theme-switcher" templated should be added directly to navbar_end
90-
# above and the following lines removed when the minimum supported
91-
# version of pydata_sphinx_theme is 0.9.0
92-
# Add version switcher for versions of pydata_sphinx_theme that support it
93-
import packaging
94-
import pydata_sphinx_theme
95-
96-
if packaging.version.parse(pydata_sphinx_theme.__version__) >= packaging.version.parse(
97-
"0.9.0"
98-
):
99-
html_theme_options["navbar_end"].insert(0, "theme-switcher")
100-
10195

10296
html_sidebars = {
10397
"**": [],

numpydoc/docscrape.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ def _parse(self):
408408
msg = "Docstring contains a Receives section but not Yields."
409409
raise ValueError(msg)
410410

411-
for (section, content) in sections:
411+
for section, content in sections:
412412
if not section.startswith(".."):
413413
section = (s.capitalize() for s in section.split(" "))
414414
section = " ".join(section)
@@ -631,7 +631,6 @@ def __init__(self, obj, doc=None, config=None):
631631

632632

633633
class ClassDoc(NumpyDocString):
634-
635634
extra_public_methods = ["__call__"]
636635

637636
def __init__(self, cls, doc=None, modulename="", func_doc=FunctionDoc, config=None):
@@ -728,7 +727,15 @@ def _is_show_member(self, name):
728727
return True
729728

730729

731-
def get_doc_object(obj, what=None, doc=None, config=None):
730+
def get_doc_object(
731+
obj,
732+
what=None,
733+
doc=None,
734+
config=None,
735+
class_doc=ClassDoc,
736+
func_doc=FunctionDoc,
737+
obj_doc=ObjDoc,
738+
):
732739
if what is None:
733740
if inspect.isclass(obj):
734741
what = "class"
@@ -742,10 +749,10 @@ def get_doc_object(obj, what=None, doc=None, config=None):
742749
config = {}
743750

744751
if what == "class":
745-
return ClassDoc(obj, func_doc=FunctionDoc, doc=doc, config=config)
752+
return class_doc(obj, func_doc=func_doc, doc=doc, config=config)
746753
elif what in ("function", "method"):
747-
return FunctionDoc(obj, doc=doc, config=config)
754+
return func_doc(obj, doc=doc, config=config)
748755
else:
749756
if doc is None:
750757
doc = pydoc.getdoc(obj)
751-
return ObjDoc(obj, doc, config=config)
758+
return obj_doc(obj, doc, config=config)

numpydoc/docscrape_sphinx.py

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from sphinx.jinja2glue import BuiltinTemplateLoader
1212

1313
from .docscrape import NumpyDocString, FunctionDoc, ClassDoc, ObjDoc
14+
from .docscrape import get_doc_object as get_doc_object_orig
1415
from .xref import make_xref
1516

1617

@@ -407,20 +408,10 @@ def __init__(self, obj, doc=None, config=None):
407408
ObjDoc.__init__(self, obj, doc=doc, config=config)
408409

409410

410-
# TODO: refactor to use docscrape.get_doc_object
411411
def get_doc_object(obj, what=None, doc=None, config=None, builder=None):
412-
if what is None:
413-
if inspect.isclass(obj):
414-
what = "class"
415-
elif inspect.ismodule(obj):
416-
what = "module"
417-
elif isinstance(obj, Callable):
418-
what = "function"
419-
else:
420-
what = "object"
421-
422412
if config is None:
423413
config = {}
414+
424415
template_dirs = [os.path.join(os.path.dirname(__file__), "templates")]
425416
if builder is not None:
426417
template_loader = BuiltinTemplateLoader()
@@ -430,11 +421,12 @@ def get_doc_object(obj, what=None, doc=None, config=None, builder=None):
430421
template_env = SandboxedEnvironment(loader=template_loader)
431422
config["template"] = template_env.get_template("numpydoc_docstring.rst")
432423

433-
if what == "class":
434-
return SphinxClassDoc(obj, func_doc=SphinxFunctionDoc, doc=doc, config=config)
435-
elif what in ("function", "method"):
436-
return SphinxFunctionDoc(obj, doc=doc, config=config)
437-
else:
438-
if doc is None:
439-
doc = pydoc.getdoc(obj)
440-
return SphinxObjDoc(obj, doc, config=config)
424+
return get_doc_object_orig(
425+
obj,
426+
what=what,
427+
doc=doc,
428+
config=config,
429+
class_doc=SphinxClassDoc,
430+
func_doc=SphinxFunctionDoc,
431+
obj_doc=SphinxObjDoc,
432+
)

numpydoc/tests/test_docscrape.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1443,7 +1443,6 @@ def __set__(self, obj, value):
14431443
obj._set_axis(self.axis, value)
14441444

14451445
class Dummy:
1446-
14471446
attr = SpecialProperty(doc="test attribute")
14481447

14491448
doc = get_doc_object(Dummy)

numpydoc/tests/test_validate.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,12 +506,45 @@ def parameters_with_trailing_underscores(self, str_):
506506
"""
507507
pass
508508

509+
def parameter_with_wrong_types_as_substrings(self, a, b, c, d, e, f):
510+
r"""
511+
Ensure PR06 doesn't fail when non-preferable types are substrings.
512+
513+
While PR06 checks for parameter types which contain non-preferable type
514+
names like integer (int), string (str), and boolean (bool), PR06 should
515+
not fail if those types are used only as susbtrings in, for example,
516+
custom type names.
517+
518+
Parameters
519+
----------
520+
a : Myint
521+
Some text.
522+
b : intClass
523+
Some text.
524+
c : Mystring
525+
Some text.
526+
d : stringClass
527+
Some text.
528+
e : Mybool
529+
Some text.
530+
f : boolClass
531+
Some text.
532+
533+
See Also
534+
--------
535+
related : Something related.
536+
537+
Examples
538+
--------
539+
>>> result = 1 + 1
540+
"""
541+
pass
542+
509543

510544
class BadGenericDocStrings:
511545
"""Everything here has a bad docstring"""
512546

513547
def func(self):
514-
515548
"""Some function.
516549
517550
With several mistakes in the docstring.
@@ -1145,6 +1178,7 @@ def test_good_class(self, capsys):
11451178
"warnings",
11461179
"valid_options_in_parameter_description_sets",
11471180
"parameters_with_trailing_underscores",
1181+
"parameter_with_wrong_types_as_substrings",
11481182
],
11491183
)
11501184
def test_good_functions(self, capsys, func):

numpydoc/validate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ def validate(obj_name):
584584
("string", "str"),
585585
]
586586
for wrong_type, right_type in common_type_errors:
587-
if wrong_type in doc.parameter_type(param):
587+
if wrong_type in set(re.split(r"\W", doc.parameter_type(param))):
588588
errs.append(
589589
error(
590590
"PR06",

requirements/developer.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
pre-commit>=2.20
1+
pre-commit>=3.0

0 commit comments

Comments
 (0)