Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrap signatures onto several lines when function len is over a treshold and function has the focus #831

Open
wants to merge 46 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
dea121c
Introduce ParsedDocstring.with_linker()/.with_tag()/.combine(). The w…
tristanlatr Oct 25, 2024
95f8f3d
Colorize the signature ourself.
tristanlatr Oct 25, 2024
0b7c76e
Some more adjustments. Make the self param always inline. Try to opti…
tristanlatr Oct 25, 2024
188c410
Add comment
tristanlatr Oct 25, 2024
83d47f7
Fix usage of cache
tristanlatr Oct 25, 2024
ab1cdd1
Fix usages of cache
tristanlatr Oct 25, 2024
eca5ced
Simplify with_linker() and with_tag(). These do not create new parsed…
tristanlatr Oct 25, 2024
ff4269f
Revert "Simplify with_linker() and with_tag(). These do not create ne…
tristanlatr Oct 25, 2024
914e01c
Minor changes not to use lru_cache too much
tristanlatr Oct 25, 2024
cdef965
Try to optimize what I can
tristanlatr Oct 25, 2024
2033d65
Fix mypy
tristanlatr Oct 26, 2024
5396396
Merge branch 'master' into 801-signature-spans
tristanlatr Oct 26, 2024
282250b
Remove unused imports
tristanlatr Oct 26, 2024
6a4de9f
Better implementation of with_linker and with_tag inside a single sub…
tristanlatr Oct 29, 2024
c0f93dc
First attempt to implement relatively smart Expand/Collapse signature…
tristanlatr Oct 29, 2024
da89d7c
Simplify things: don't try to wrap overload signatures. Sphinx doesn'…
tristanlatr Nov 14, 2024
141b211
Get rid of the ParsedStanOnly by using parsed_text_with_css instead.
tristanlatr Nov 14, 2024
a46a3a3
Few simplifications here and there.
tristanlatr Nov 14, 2024
40ac0a6
Use the CSS class 'decorator' for all decorators.
tristanlatr Nov 14, 2024
4172485
Fix various bugs in the implementation.
tristanlatr Nov 14, 2024
7103ce5
Fix pyflakes
tristanlatr Nov 14, 2024
eae961a
Fix format_undocumented_summary returning a tuple of strings instead …
tristanlatr Nov 14, 2024
7c6c6eb
increase the threshold for a function to be rendered in several lines.
tristanlatr Nov 14, 2024
19400ff
Avoid an empty div for decorators when there are no decorators.
tristanlatr Nov 14, 2024
a3ebbdf
Use non breaking spaces in sugnature defs.
tristanlatr Nov 14, 2024
cd257eb
Improve a little bit the rendering of parameter tables that uses very…
tristanlatr Nov 15, 2024
907792a
Get rid of the AnnotationLinker - drop the verbose messages when an a…
tristanlatr Nov 16, 2024
977e5b5
Merge branch 'master' into 801-signature-spans
tristanlatr Nov 16, 2024
91edc51
Change comment
tristanlatr Nov 18, 2024
b504c21
Merge branch '801-signature-spans' of github.com:twisted/pydoctor int…
tristanlatr Nov 18, 2024
25b5e62
Add an environment to build temporalio docs
tristanlatr Nov 21, 2024
bd2de92
Add a bug overload in the google demo
tristanlatr Nov 21, 2024
cc82f10
Apply suggestions from code review
tristanlatr Dec 13, 2024
07fc41d
Merge branch 'master' into 801-signature-spans
tristanlatr Dec 13, 2024
668f4d0
Fix the NotFoundLinker
tristanlatr Dec 13, 2024
7fc2b10
Do not mark overloaded functions with css class .long-signature
tristanlatr Dec 13, 2024
80de043
Remove unused imports
tristanlatr Dec 13, 2024
a9c5bf2
Add readme entries
tristanlatr Dec 13, 2024
6784e4c
Upadate docs tests
tristanlatr Dec 13, 2024
78f73b9
Like back, consider a function long from 88 chars.
tristanlatr Dec 13, 2024
bf7045f
Adjust test again
tristanlatr Dec 13, 2024
a37b028
Update README.rst
tristanlatr Dec 13, 2024
8b24212
Merge branch 'master' into 801-signature-spans
tristanlatr Jan 14, 2025
56168f8
Fix typo
tristanlatr Feb 4, 2025
1f93800
Revert some CSS changes covered in #872
tristanlatr Feb 20, 2025
eecf39e
Remove comment
tristanlatr Feb 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Few simplifications here and there.
  • Loading branch information
tristanlatr committed Nov 14, 2024
commit a46a3a38df11914fa26e2635fd5664b0784dbc59
18 changes: 17 additions & 1 deletion pydoctor/epydoc/markup/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from __future__ import annotations
__docformat__ = 'epytext en'

import contextlib
from itertools import chain
from typing import Callable, ContextManager, Iterable, List, Optional, Sequence, Iterator, TYPE_CHECKING
import abc
Expand Down Expand Up @@ -209,7 +210,8 @@ def to_text(self) -> str:
Translate this docstring to a string.
The default implementation depends on L{to_node}.
"""
return ''.join(node2stan.gettext(self.to_node()))
doc = self.to_node()
return ''.join(node2stan.gettext(doc))

def with_linker(self, linker: DocstringLinker) -> ParsedDocstring:
"""
Expand Down Expand Up @@ -425,6 +427,20 @@ def switch_context(self, ob:Optional['Documentable']) -> ContextManager[None]:
in this case error will NOT be reported at all.
"""

class NotFoundLinker(DocstringLinker):
tristanlatr marked this conversation as resolved.
Show resolved Hide resolved
"""A DocstringLinker implementation that cannot find any links."""

def link_to(self, target: str, label: "Flattenable") -> Tag:
return tags.transparent(label)

def link_xref(self, target: str, label: "Flattenable", lineno: int) -> Tag:
return tags.code(label)

@contextlib.contextmanager
def switch_context(self, ob: Documentable | None) -> Iterator[None]:
yield


##################################################
## ParseError exceptions
##################################################
Expand Down
3 changes: 2 additions & 1 deletion pydoctor/epydoc/markup/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ def has_body(self) -> bool:

def to_node(self) -> nodes.document:
"""
Not implemented.
Not implemented at this time :/
"""
#TODO: Fix this soon
tristanlatr marked this conversation as resolved.
Show resolved Hide resolved
raise NotImplementedError()

def to_stan(self, docstring_linker: DocstringLinker) -> Tag:
Expand Down
2 changes: 1 addition & 1 deletion pydoctor/epydoc2stan.py
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,7 @@ def colorized_pyval_fallback(_: List[ParseError], doc:ParsedDocstring, __:model.
"""
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this docstring is wrong

This fallback function uses L{ParsedDocstring.to_node()}, so it must be used only with L{ParsedDocstring} subclasses that implements C{to_node()}.
"""
return Tag('code')(node2stan.gettext(doc.to_node()))
return tags.code(doc.to_text())

def _format_constant_value(obj: model.Attribute) -> Iterator["Flattenable"]:

Expand Down
3 changes: 1 addition & 2 deletions pydoctor/templatewriter/pages/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ def format_signature(func: Union[model.Function, model.FunctionOverload]) -> "Fl
parsed_sig,
ctx.docstring_linker,
ctx,
fallback=lambda _, doc, ___: tags.transparent(
node2stan.gettext(doc.to_node())),
fallback=lambda _, doc, ___: tags.transparent(doc.to_text()),
section='signature'
)

Expand Down
7 changes: 1 addition & 6 deletions pydoctor/templatewriter/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,7 @@ def format_docstring(self, ob: model.Documentable) -> Optional[str]:
source = epydoc2stan.ensure_parsed_docstring(ob)
if source is not None:
assert ob.parsed_docstring is not None
try:
doc = ' '.join(node2stan.gettext(ob.parsed_docstring.to_node()))
except NotImplementedError:
# some ParsedDocstring subclass raises NotImplementedError on calling to_node()
# Like ParsedPlaintextDocstring.
doc = source.docstring
doc = ob.parsed_docstring.to_text()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lovely to see an ugly too-broad try like this go away :)

return doc

def format_kind(self, ob:model.Documentable) -> str:
Expand Down
25 changes: 4 additions & 21 deletions pydoctor/test/__init__.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
"""PyDoctor's test suite."""

import contextlib
from logging import LogRecord
from typing import Iterable, TYPE_CHECKING, Iterator, Optional, Sequence
from typing import Iterable, TYPE_CHECKING, Sequence
import sys
import pytest
from pathlib import Path

from twisted.web.template import Tag, tags

from pydoctor import epydoc2stan, model
from pydoctor.templatewriter import IWriter, TemplateLookup
from pydoctor.epydoc.markup import DocstringLinker
from pydoctor.epydoc.markup import NotFoundLinker

if TYPE_CHECKING:
from twisted.web.template import Flattenable

__all__ = ['InMemoryWriter', 'NotFoundLinker', 'posonlyargs', 'typecomment', 'CapSys']

posonlyargs = pytest.mark.skipif(sys.version_info < (3, 8), reason="requires python 3.8")
typecomment = pytest.mark.skipif(sys.version_info < (3, 8), reason="requires python 3.8")
Expand Down Expand Up @@ -87,18 +85,3 @@ def _writeDocsFor(self, ob: model.Documentable) -> None:

for o in ob.contents.values():
self._writeDocsFor(o)


class NotFoundLinker(DocstringLinker):
"""A DocstringLinker implementation that cannot find any links."""

def link_to(self, target: str, label: "Flattenable") -> Tag:
return tags.transparent(label)

def link_xref(self, target: str, label: "Flattenable", lineno: int) -> Tag:
return tags.code(label)

@contextlib.contextmanager
def switch_context(self, ob: Optional[model.Documentable]) -> Iterator[None]:
yield

7 changes: 3 additions & 4 deletions pydoctor/test/epydoc/test_pyval_repr.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from pydoctor.epydoc.markup._pyval_repr import PyvalColorizer, colorize_inline_pyval
from pydoctor.test import NotFoundLinker
from pydoctor.stanutils import flatten, flatten_text, html2stan
from pydoctor.node2stan import gettext

def color(v: Any, linebreakok:bool=True, maxlines:int=5, linelen:int=40) -> str:
colorizer = PyvalColorizer(linelen=linelen, linebreakok=linebreakok, maxlines=maxlines)
Expand Down Expand Up @@ -1160,7 +1159,7 @@ def color_re(s: Union[bytes, str],
val = colorizer.colorize(extract_expr(ast.parse(f"re.compile({repr(s)})")))

if check_roundtrip:
raw_text = ''.join(gettext(val.to_node()))
raw_text = val.to_text()
re_begin = 13
raw_string = True

Expand Down Expand Up @@ -1428,7 +1427,7 @@ def color2(v: Any, linelen:int=50) -> str:
"""
colorizer = PyvalColorizer(linelen=linelen, maxlines=5)
colorized = colorizer.colorize(v)
text1 = ''.join(gettext(colorized.to_node()))
text1 = colorized.to_text()
text2 = flatten_text(html2stan(flatten(colorized.to_stan(NotFoundLinker()))))
assert text1 == text2
return text2
Expand Down Expand Up @@ -1473,7 +1472,7 @@ def test_summary() -> None:
"""
summarizer = PyvalColorizer(linelen=60, maxlines=1, linebreakok=False)
def summarize(v:Any) -> str:
return(''.join(gettext(summarizer.colorize(v).to_node())))
return summarizer.colorize(v).to_text()

assert summarize(list(range(100))) == "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16..."
assert summarize('hello\nworld') == r"'hello\nworld'"
Expand Down
2 changes: 1 addition & 1 deletion pydoctor/test/test_astbuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def signature2str(func: model.Function | model.FunctionOverload) -> str:
doc = get_parsed_signature(func)
assert doc
fromhtml = flatten_text(format_signature(func))
fromdocutils = ''.join(node2stan.gettext(doc.to_node()))
fromdocutils = doc.to_text()
assert fromhtml == fromdocutils
return fromhtml

Expand Down