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

Pretty print function signatures #78

Merged

Conversation

lgeiger
Copy link

@lgeiger lgeiger commented Mar 23, 2019

This PR auto-formats function signatures. This is makes very long function signatures a lot more readable.

Before

SeparableConv2D(filters, kernel_size, strides=(1, 1), padding='valid', data_format=None, dilation_rate=(1, 1), depth_multiplier=1, activation=None, use_bias=True, depthwise_initializer='glorot_uniform', pointwise_initializer='glorot_uniform', bias_initializer='zeros', depthwise_regularizer=None, pointwise_regularizer=None, bias_regularizer=None, activity_regularizer=None, depthwise_constraint=None, pointwise_constraint=None, bias_constraint=None, **kwargs)

After

SeparableConv2D(
    filters,
    kernel_size,
    strides=(1, 1),
    padding='valid',
    data_format=None,
    dilation_rate=(1, 1),
    depth_multiplier=1,
    activation=None,
    use_bias=True,
    depthwise_initializer='glorot_uniform',
    pointwise_initializer='glorot_uniform',
    bias_initializer='zeros',
    depthwise_regularizer=None,
    pointwise_regularizer=None,
    bias_regularizer=None,
    activity_regularizer=None,
    depthwise_constraint=None,
    pointwise_constraint=None,
    bias_constraint=None,
    **kwargs)

Why using yapf?

@NiklasRosenstein NiklasRosenstein merged commit 36c887b into NiklasRosenstein:master Apr 2, 2019
@NiklasRosenstein
Copy link
Owner

Thanks, looks cool! :-)

@lgeiger lgeiger deleted the pretty-print-signature branch April 2, 2019 19:17
@florimondmanca
Copy link

Hi, I just ran into failing builds, apparently caused by yapf not supporting type annotations:

$ pydocmd generate
/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/pydocmd/__main__.py:47: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.
  config = yaml.load(fp)
Started copying source files...
Generating temporary MkDocs config...
Building index...
Started generating documentation...

Traceback (most recent call last):
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/yapf/yapflib/pytree_utils.py", line 115, in ParseCodeToTree
    tree = parser_driver.parse_string(code, debug=False)
  File "/opt/python/3.6.3/lib/python3.6/lib2to3/pgen2/driver.py", line 106, in parse_string
    return self.parse_tokens(tokens, debug)
  File "/opt/python/3.6.3/lib/python3.6/lib2to3/pgen2/driver.py", line 71, in parse_tokens
    if p.addtoken(type, value, (prefix, start)):
  File "/opt/python/3.6.3/lib/python3.6/lib2to3/pgen2/parse.py", line 159, in addtoken
    raise ParseError("bad input", type, value, context)
lib2to3.pgen2.parse.ParseError: bad input: type=11, value=':', context=('', (1, 16))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/yapf/yapflib/pytree_utils.py", line 121, in ParseCodeToTree
    tree = parser_driver.parse_string(code, debug=False)
  File "/opt/python/3.6.3/lib/python3.6/lib2to3/pgen2/driver.py", line 106, in parse_string
    return self.parse_tokens(tokens, debug)
  File "/opt/python/3.6.3/lib/python3.6/lib2to3/pgen2/driver.py", line 71, in parse_tokens
    if p.addtoken(type, value, (prefix, start)):
  File "/opt/python/3.6.3/lib/python3.6/lib2to3/pgen2/parse.py", line 159, in addtoken
    raise ParseError("bad input", type, value, context)
lib2to3.pgen2.parse.ParseError: bad input: type=11, value=':', context=('', (1, 16))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/travis/virtualenv/python3.6.3/bin/pydocmd", line 11, in <module>
    load_entry_point('pydoc-markdown==2.0.5', 'console_scripts', 'pydocmd')()
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/pydocmd/__main__.py", line 252, in main
    loader.load_section(section)
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/pydocmd/loader.py", line 92, in load_section
    sig, _ = FormatCode(sig, style_config='pep8')
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/yapf/yapflib/yapf_api.py", line 129, in FormatCode
    tree = pytree_utils.ParseCodeToTree(unformatted_source)
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/yapf/yapflib/pytree_utils.py", line 127, in ParseCodeToTree
    raise e
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/yapf/yapflib/pytree_utils.py", line 125, in ParseCodeToTree
    ast.parse(code)
  File "/opt/python/3.6.3/lib/python3.6/ast.py", line 35, in parse
    return compile(source, filename, mode, PyCF_ONLY_AST)
  File "<unknown>", line 1
    App.mount(prefix:str, app:Union[_ForwardRef('App'), bocadillo.app_types.ASGIApp, Callable[[dict, Callable[[str, List[str]], NoneType]], List[bytes]]])
                    ^
SyntaxError: invalid syntax
The command "pydocmd generate" exited with 1.

I had to pin to <2.0.5 to have my builds run again. :-)

Full failing build traceback: https://travis-ci.org/bocadilloproject/bocadillo/builds/515720068

NiklasRosenstein added a commit that referenced this pull request Feb 27, 2022
…s with YAPF. (Tagging @lgeiger as the author because he was the original author of the feature in a previous version of Pydoc-Markdown, see #78)

closes #244
NiklasRosenstein added a commit that referenced this pull request Feb 28, 2022
* mypy and adjust to docspec-2.0.0 alpha

* mypy with untyped defs

* add more type hints

* update project and ci

* update workflow

* update workflow

* fix project config

* bump dependency on 2.0.0a1

* update type hint

* depend on tomli and tomli_w

* fix hwo the markdown renderer identifies the header level (broke due to docspec upgrade)

* hygiene: remove `MarkdownRenderer.classdef_render_init_signature_if_needed` option because it never worked to begin with

* breaking change: remove `MarkdownRenderer.render_to_stream()` from public api

* add missing types-* dependencies

* add jinja dep

* clean some deps

* use is_relative_to from nr.util.fs for 3.8 and 3.7 compatibility

* bump

* start updating docs to build them with Novella

* remove .readthedocs.yml

* add to docs/requirements.txt

* update docs

* need novella==0.1.5 at least

* convert changelogs

* add PR links

* install pydoc-markdown in docs build

* first implementation of `@pydoc` tag

* move novella dep to "novella" extra, add "docs" extra

* update ci

* enable pushing to gh pages

* fix syntax in pyproject.toml

* fix mypy

* need to exclude pydoc_markdown.novella for now because we cant verify it in 3.7-3.9 python versions

* add using-novella.md

* spell

* automatically detect source linker config for github.com, gitlab.com and gitea.com

* remove unused import

* feature: add `pydoc_markdown.interfaces.SingleObjectRenderer` and use it in Novella `@pydoc` tag processor

* features

* mypy

* move accidentally ill-located changelogs for 4.4.0 to correct file

* implement `@pylink` tag

* feature: bring back formatting function, class and variable signatures with YAPF. (Tagging @lgeiger as the author because he was the original author of the feature in a previous version of Pydoc-Markdown, see #78)

closes #244

* add yapf dependency

* ignore types for yapf

* fix: fix forwarding of `PluginBase.init()` calls to sub-plugins in unittests and `DocusaurusRenderer`

* update function signature style (no trailing colon)

* update docs

* git fetch before building docs

* update pr numbers from ci

* fix update-pr-numbers

* Update changelog PR references

* Update .changelog/_unreleased.toml

* update git describe in index.md

* remove pydoc-markdown.yml, disable render_module_header by default for MarkdownRenderer in @pydoc tag, fetch tags as well

* use fetch-depth: 0 to make git describe --tag work

* use GITHUB_HEAD_REF is available

* fix links to source code (hopefully)

* fix ci

* improvement: do not render link to source for modules in `MarkdownRenderer`

* Update changelog PR references

* cache loaded modules in Pydoc preprocessor, use new `MarkdownPreprocessorAction.repeat()` on generated Markdown code

* bump novella dep

* <3.10 syntax

Co-authored-by: GitHub Action <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants