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

BUG: Fix autosummary of members with a trailing underscore #3585

Merged
merged 1 commit into from Mar 29, 2017

Conversation

eric-wieser
Copy link
Contributor

@eric-wieser eric-wieser commented Mar 25, 2017

Follows on from #3581. It turns out that lots of different code generates rst files.

This PR includes a test that previously failed, and is causing problems in numpy/numpy#6769

@@ -194,7 +194,8 @@ The following variables available in the templates:

.. data:: underline

A string containing ``len(full_name) * '='``.
A string containing ``len(full_name) * '='``. Use the ``underline`` filter
instead.
Copy link
Contributor Author

@eric-wieser eric-wieser Mar 25, 2017

Choose a reason for hiding this comment

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

This has to stay here for backwards-compatibility, but it's useless when using | escape

@@ -1,5 +1,4 @@
{{ fullname }}
{{ underline }}
Copy link
Contributor Author

@eric-wieser eric-wieser Mar 25, 2017

Choose a reason for hiding this comment

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

The takeaway here is that all user code that overrides these templates will need to make this change too in order to actually fix the bug. But that's unavoidable.

Either way, this PR will not change how old code behaves.


title = etree_parse(docpage).find('section/title')

assert str_content(title) == 'underscore_module_'
Copy link
Contributor Author

@eric-wieser eric-wieser Mar 25, 2017

Choose a reason for hiding this comment

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

Before this patch, this would lose the trailing underscore.

Copy link
Member

@tk0miya tk0miya left a comment

LGTM with nits

def _underline(title, line='='):
if '\n' in title:
raise ValueError('Can only underline single lines')
return title + '\n' + line*len(title)
Copy link
Member

@tk0miya tk0miya Mar 26, 2017

Choose a reason for hiding this comment

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

Could you use docutils.utils.column_width() instead of len()?
It supports east asian width. They can use character having multiple widths for module name. So it's important for asian users.

Copy link
Contributor Author

@eric-wieser eric-wieser Mar 26, 2017

Choose a reason for hiding this comment

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

But we don't use that in apidoc either. Fixing it there, here, and elsewhere sounds like something for a separate PR, that also adds tests for these things.

Note that we already just use len in the underscore variable, so doing the same here isn't a regression.

Copy link
Contributor Author

@eric-wieser eric-wieser Mar 26, 2017

Choose a reason for hiding this comment

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

Can python modules have names containing these characters, or is that forbidden? If so, someone who knows more about using asian characters should patch this and apidoc, and add a test

Copy link
Member

@tk0miya tk0miya Mar 29, 2017

Choose a reason for hiding this comment

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

Yes, you can use east asian characters for python modules.

# main.py
import テスト

テスト.関数('Sphinx')
# テスト.py
def 関数(名前):
    print('Hello ' + 名前)

Okay, I will do it in another ticket.


# replace the builtin html filters
template_env.filters['escape'] = rst_escape
template_env.filters['e'] = rst_escape
Copy link
Member

@tk0miya tk0miya Mar 26, 2017

Choose a reason for hiding this comment

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

It seems this is secret (undocumented) feature now. So please remove this or add document.

Copy link
Contributor Author

@eric-wieser eric-wieser Mar 26, 2017

Choose a reason for hiding this comment

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

You mean the {{ | e}} filter? That's native to Jinja, and is documented there as an alias of {{ | escape}}.

Copy link
Contributor Author

@eric-wieser eric-wieser Mar 26, 2017

Choose a reason for hiding this comment

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

I've added a link to the jinja docs

Copy link
Member

@tk0miya tk0miya Mar 29, 2017

Choose a reason for hiding this comment

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

Thanks

@tk0miya tk0miya added this to the 1.5.4 milestone Mar 26, 2017
@tk0miya
Copy link
Member

@tk0miya tk0miya commented Mar 26, 2017

It seems Mr. flake8 warns to us. Could you check them please?

./sphinx/ext/autosummary/generate.py:83:1: E302 expected 2 blank lines, found 1
./sphinx/ext/autosummary/generate.py:86:31: E226 missing whitespace around arithmetic operator

@eric-wieser
Copy link
Contributor Author

@eric-wieser eric-wieser commented Mar 26, 2017

flake8 fixed, despite not really agree with the E266 warning there

@eric-wieser
Copy link
Contributor Author

@eric-wieser eric-wieser commented Mar 27, 2017

@tk0miya: Does this need anything else?

@tk0miya tk0miya merged commit 592b808 into sphinx-doc:stable Mar 29, 2017
1 check passed
@tk0miya
Copy link
Member

@tk0miya tk0miya commented Mar 29, 2017

Thanks!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants