Skip to content

Commit 5494abf

Browse files
pass 5
1 parent c59cbd0 commit 5494abf

File tree

4 files changed

+25
-6
lines changed

4 files changed

+25
-6
lines changed

doc/conf.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from urllib.request import urlopen
22

3+
34
_conf_url = \
45
"https://raw.githubusercontent.com/inducer/sphinxconfig/main/sphinxconfig.py"
56
with urlopen(_conf_url) as _inf:
@@ -41,3 +42,17 @@
4142
autodoc_type_aliases = {"GraphT": "pytools.graph.GraphT",
4243
"NodeT": "pytools.graph.NodeT",
4344
}
45+
46+
# Some modules need to import things just so that sphinx can resolve symbols in
47+
# type annotations. Often, we do not want these imports (e.g. of PyOpenCL) when
48+
# in normal use (because they would introduce unintended side effects or hard
49+
# dependencies). This flag exists so that these imports only occur during doc
50+
# build. Since sphinx appears to resolve type hints lexically (as it should),
51+
# this needs to be cross-module (since, e.g. an inherited pytools
52+
# docstring can be read by sphinx when building meshmode, a dependent package),
53+
# this needs a setting of the same name across all packages involved, that's
54+
# why this name is as global-sounding as it is.
55+
import sys
56+
57+
58+
sys._BUILDING_SPHINX_DOCS = True

pytools/__init__.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,17 @@
3636
from functools import reduce, wraps
3737
from sys import intern
3838
from typing import (
39-
Any, Callable, cast, ClassVar, Dict, Generic, Hashable, Iterable, List, Mapping,
40-
Optional, Set, Tuple, Type, TypeVar, Union, ValuesView, KeysView,
41-
ItemsView, Sequence, Generator, TYPE_CHECKING)
39+
TYPE_CHECKING, Any, Callable, ClassVar, Dict, Generator, Generic, Hashable,
40+
ItemsView, Iterable, KeysView, List, Mapping, Optional, Sequence, Set, Tuple,
41+
Type, TypeVar, Union, ValuesView, cast)
4242

4343

4444
if TYPE_CHECKING:
4545
import numpy as np
4646

47+
if getattr(sys, "_BUILDING_SPHINX_DOCS", False):
48+
import numpy as np # noqa: F811
49+
4750

4851
try:
4952
from typing import Concatenate
@@ -2475,11 +2478,11 @@ def find_git_revision(tree_root: str) \
24752478
return git_rev
24762479

24772480

2478-
def find_module_git_revision(module_file, n_levels_up):
2481+
def find_module_git_revision(module_file: str, n_levels_up: int) -> Optional[bytes]:
24792482
from os.path import dirname, join
24802483
tree_root = join(*([dirname(module_file)] + [".." * n_levels_up]))
24812484

2482-
return find_git_revision(tree_root) # type: ignore[no-untyped-call]
2485+
return find_git_revision(tree_root)
24832486

24842487
# }}}
24852488

run-mypy.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ set -ex
44

55
mypy --show-error-codes pytools
66

7-
mypy --strict pytools/datatable.py pytools/graph.py pytools/mpi.py
7+
mypy --strict pytools/datatable.py pytools/graph.py pytools/mpi.py pytools/__init__.py

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from setuptools import setup
44

5+
56
ver_dic = {}
67
version_file = open("pytools/version.py")
78
try:

0 commit comments

Comments
 (0)