Skip to content

Commit 9a9de1b

Browse files
committed
refactor: simplify now that distutils is gone
Signed-off-by: Mike Fiedler <[email protected]>
1 parent 8eb63da commit 9a9de1b

File tree

1 file changed

+3
-17
lines changed

1 file changed

+3
-17
lines changed

readme_renderer/rst.py

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from __future__ import absolute_import, division, print_function
1515

1616
import io
17-
from typing import Any, Dict, Optional, TextIO, Union, TYPE_CHECKING
17+
from typing import Any, Dict, IO, Optional, Union
1818

1919
from docutils.core import publish_parts
2020
from docutils.nodes import colspec, image
@@ -23,10 +23,6 @@
2323

2424
from .clean import clean
2525

26-
if TYPE_CHECKING:
27-
# Prevent a circular import
28-
from .integration.distutils import _WarningStream
29-
3026

3127
class ReadMeHTMLTranslator(HTMLTranslator): # type: ignore[misc] # docutils is incomplete, returns `Any` python/typeshed#7256 # noqa E501
3228

@@ -109,7 +105,7 @@ def emptytag(
109105

110106
def render(
111107
raw: str,
112-
stream: Optional[Union[io.StringIO, TextIO, "_WarningStream"]] = None,
108+
stream: Optional[IO[str]] = None,
113109
**kwargs: Any
114110
) -> Optional[str]:
115111
if stream is None:
@@ -134,16 +130,6 @@ def render(
134130
return clean(rendered)
135131
else:
136132
# If the warnings stream is empty, docutils had none, so add ours.
137-
138-
# We have to currently handle the legacy disutils integration check
139-
# command, as it implements its own warnings stream structure.
140-
# Once that code is removed, we can remove this conditional.
141-
if hasattr(stream, "output"):
142-
if not stream.output.getvalue(): # type: ignore[union-attr]
143-
stream.write("No content rendered from RST source.")
144-
elif isinstance(stream, io.StringIO) and not stream.getvalue():
145-
stream.write("No content rendered from RST source.")
146-
elif isinstance(stream, TextIO) and not stream.readlines():
147-
# This is `sys.stderr` from using readme_renderer CLI
133+
if not stream.tell():
148134
stream.write("No content rendered from RST source.")
149135
return None

0 commit comments

Comments
 (0)