Skip to content

Commit 9b7a15d

Browse files
committed
Successfully build docs on Windows on CPython 3.13
1 parent b1865a8 commit 9b7a15d

File tree

5 files changed

+43
-11
lines changed

5 files changed

+43
-11
lines changed

src/trio/_core/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
from ._unbounded_queue import UnboundedQueue, UnboundedQueueStatistics
7474

7575
# Windows imports
76-
if sys.platform == "win32":
76+
if sys.platform == "win32" or "sphinx.ext.autodoc" in sys.modules:
7777
from ._run import (
7878
current_iocp,
7979
monitor_completion_key,
@@ -83,7 +83,9 @@
8383
write_overlapped,
8484
)
8585
# Kqueue imports
86-
elif sys.platform != "linux" and sys.platform != "win32":
86+
if (
87+
sys.platform != "linux" and sys.platform != "win32"
88+
) or "sphinx.ext.autodoc" in sys.modules:
8789
from ._run import current_kqueue, monitor_kevent, wait_kevent
8890

8991
del sys # It would be better to import sys as _sys, but mypy does not understand it

src/trio/_core/_run.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2960,6 +2960,12 @@ def in_trio_task() -> bool:
29602960
return hasattr(GLOBAL_RUN_CONTEXT, "task")
29612961

29622962

2963+
# export everything for the documentation
2964+
if "sphinx.ext.autodoc" in sys.modules:
2965+
from ._generated_io_epoll import *
2966+
from ._generated_io_kqueue import *
2967+
from ._generated_io_windows import *
2968+
29632969
if sys.platform == "win32":
29642970
from ._generated_io_windows import *
29652971
from ._io_windows import (
@@ -2985,7 +2991,7 @@ def in_trio_task() -> bool:
29852991
_patchers = sorted({"eventlet", "gevent"}.intersection(sys.modules))
29862992
if _patchers:
29872993
raise NotImplementedError(
2988-
"unsupported platform or primitives trio depends on are monkey-patched out by "
2994+
"unsupported platform or primitives Trio depends on are monkey-patched out by "
29892995
+ ", ".join(_patchers),
29902996
)
29912997

src/trio/_highlevel_socket.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,18 @@
1414
if TYPE_CHECKING:
1515
from collections.abc import Generator
1616

17-
from typing_extensions import Buffer
18-
1917
from ._socket import SocketType
2018

19+
import sys
20+
21+
if sys.version_info >= (3, 12):
22+
# NOTE: this isn't in the `TYPE_CHECKING` since for some reason
23+
# sphinx doesn't autoreload this module for SocketStream
24+
# (hypothesis: it's our module renaming magic)
25+
from collections.abc import Buffer
26+
elif TYPE_CHECKING:
27+
from typing_extensions import Buffer
28+
2129
# XX TODO: this number was picked arbitrarily. We should do experiments to
2230
# tune it. (Or make it dynamic -- one idea is to start small and increase it
2331
# if we observe single reads filling up the whole buffer, at least within some
@@ -152,6 +160,7 @@ def setsockopt(self, level: int, option: int, value: int | Buffer) -> None: ...
152160
@overload
153161
def setsockopt(self, level: int, option: int, value: None, length: int) -> None: ...
154162

163+
# TODO: rename `length` to `optlen`
155164
def setsockopt(
156165
self,
157166
level: int,

src/trio/_path.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,18 @@ async def wrapper(*args: P.args, **kwargs: P.kwargs) -> T:
3939

4040
update_wrapper(wrapper, wrapped)
4141
if wrapped.__doc__:
42+
module = wrapped.__module__
43+
# these are exported specially from CPython's intersphinx inventory
44+
module = module.replace("pathlib._local", "pathlib")
45+
module = module.replace("pathlib._abc", "pathlib")
46+
47+
name = wrapped.__qualname__
48+
name = name.replace(
49+
"PathBase", "Path"
50+
) # I'm not sure why this is necessary
51+
4252
wrapper.__doc__ = (
43-
f"Like :meth:`~{wrapped.__module__}.{wrapped.__qualname__}`, but async.\n"
53+
f"Like :meth:`~{module}.{name}`, but async.\n"
4454
f"\n"
4555
f"{cleandoc(wrapped.__doc__)}\n"
4656
)
@@ -245,6 +255,9 @@ def __repr__(self) -> str:
245255
full_match = _wrap_method(pathlib.Path.full_match)
246256

247257

258+
Path.relative_to.__doc__ = Path.relative_to.__doc__.replace(" `..` ", " ``..`` ")
259+
260+
248261
@final
249262
class PosixPath(Path, pathlib.PurePosixPath):
250263
"""An async :class:`pathlib.PosixPath` that executes blocking methods in :meth:`trio.to_thread.run_sync`."""

src/trio/lowlevel.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
# Uses `from x import y as y` for compatibility with `pyright --verifytypes` (#2625)
6363

6464

65-
if sys.platform == "win32":
65+
if sys.platform == "win32" or "sphinx.ext.autodoc" in sys.modules:
6666
# Windows symbols
6767
from ._core import (
6868
current_iocp as current_iocp,
@@ -73,13 +73,15 @@
7373
write_overlapped as write_overlapped,
7474
)
7575
from ._wait_for_object import WaitForSingleObject as WaitForSingleObject
76-
else:
76+
77+
if sys.platform != "win32" or "sphinx.ext.autodoc" in sys.modules:
7778
# Unix symbols
78-
if _os.name == "posix":
79-
from ._unix_pipes import FdStream as FdStream
79+
from ._unix_pipes import FdStream as FdStream
8080

8181
# Kqueue-specific symbols
82-
if sys.platform != "linux" and (_t.TYPE_CHECKING or not hasattr(_select, "epoll")):
82+
if (
83+
sys.platform != "linux" and (_t.TYPE_CHECKING or not hasattr(_select, "epoll"))
84+
) or "sphinx.ext.autodoc" in sys.modules:
8385
from ._core import (
8486
current_kqueue as current_kqueue,
8587
monitor_kevent as monitor_kevent,

0 commit comments

Comments
 (0)