Skip to content

add (possibly slightly off) source lines to mangled docstrings. - #61

Merged
stefanv merged 1 commit into
numpy:masterfrom
amueller:add_source_lines
Oct 4, 2016
Merged

stefanv merged 1 commit into
numpy:masterfrom
amueller:add_source_lines

Conversation

@amueller

@amueller amueller commented Sep 7, 2016 •

Copy link
Copy Markdown
Contributor

Fixes #52 to some degree.
This adds references to the original source files instead of gigantic output.
However, the numpy mangling might add lines and so the numbers might be slightly off.
I would argue this is already a big improvement though.


This change is Reviewable

@pv

pv commented Sep 7, 2016 via email

Copy link
Copy Markdown
Member

@amueller

amueller commented Sep 7, 2016

Copy link
Copy Markdown
Contributor Author

same as without numpydoc:
/home/andy/checkout/sphinx_autodoc_debug/main.py:docstring of main.my_function:20: ERROR: Unknown target name: "reference".
(using this minimal example: https://github.com/amueller/sphinx_autodoc_debug)

@amueller

amueller commented Sep 7, 2016

Copy link
Copy Markdown
Contributor Author

It would be great to have the line number in the .py file but that is an issue of how autodoc (I think) formats the source. Now at least numpydoc is not messing up the stuff that autodoc generates.

@amueller

amueller commented Sep 7, 2016

Copy link
Copy Markdown
Contributor Author

I found out that there were just a couple of empty lines added and other empty lines removed in the parsing which made the line length different . I'm trying to figure that out, so we can get better matching line numbers.

@amueller

amueller commented Sep 7, 2016

Copy link
Copy Markdown
Contributor Author

ok I did a rough heuristic for better lines. The main reason I prefer the heuristic is that classes are single documents, and I want to know which method the problem is in. This information gets lost otherwise. My heuristic might be off, but I think it's a net improvement.

I ran it over the scikit-learn docs and it didn't break in a horrible way.

Comment thread numpydoc/numpydoc.py Outdated
for i, line in enumerate(lines):
# go to next non-empty line in old:
# line.strip("") checks whether the string is all whitespace
while j < len(lines_old) - 1 and not lines_old[j].strip(" "):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why strip(" ") and not strip()?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

good point.

Comment thread numpydoc/numpydoc.py Outdated


def match_items(lines, content_old):
"""Create the right items for lines.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I found myself digging into the docutils source to figure out what these "right 'items'" are. Can we clear up the docstring of this function a bit, describing what it is doing and why? I see some of that below, but it's not easy to understand without the context of the PR.

@amueller amueller Sep 9, 2016 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

will do. These are really "Best guess".
So the explanation will be "most of the lines are the same after mangling, but we delete and insert some blank lines. This function tries to match the lines as best as possible. Any other changes, like including figures or reformatting references will lead to wrong line numbers." And then I'll explain the scan that I do.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Actually, this has nothing to do with docutils. The mangle_docstring function changes the lines but not the items. That's pretty much a design error. It should keep track of both.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I added a really long-winded explanation and a doctest. Better ? ;)

@stefanv

stefanv commented Sep 9, 2016

Copy link
Copy Markdown
Contributor

@amueller The new docstring is excellent, thank you!

@amueller

Copy link
Copy Markdown
Contributor Author

I don't understand the test failure... "cannot import monkey"

@stefanv

stefanv commented Sep 15, 2016 via email

Copy link
Copy Markdown
Contributor

@NelleV

NelleV commented Sep 20, 2016

Copy link
Copy Markdown
Contributor

@amueller Do you mind rebasing? (I'll try to have Stéfan push the green button today, as this patch will be super useful for our students)

more agressive change to match up new lines with old lines.

adjust expectations in docstring

strip() instead of strip(" ")

added really long explanation and doctest

make lines actually 80 chars long and dont guess

typo
@amueller

Copy link
Copy Markdown
Contributor Author

@NelleV Done :)
And thanks, hopefully this will benefit a bunch of numpdoc-based projects.
What are your students doing?

1 similar comment
@amueller

Copy link
Copy Markdown
Contributor Author

@NelleV Done :)
And thanks, hopefully this will benefit a bunch of numpdoc-based projects.
What are your students doing?

@NelleV

NelleV commented Sep 22, 2016

Copy link
Copy Markdown
Contributor

They'll be working on matplotlib. I think the first task is going to be documentation changes.
They'll also be working on scikit-image and possibly some documentation changes as well.

We're supposed to have a website, but I don't know where it is yet.

@amueller

Copy link
Copy Markdown
Contributor Author

"we"? anyhow, I hope this helps. I've been lobbying for matplotlib documentation changes but didn't find any pots of gold yet :(

@NelleV

NelleV commented Sep 22, 2016

Copy link
Copy Markdown
Contributor

We being @stefanv and me, but I just hoped on the project a couple of weeks ago. Stéfan has already run this once during the spring, but I wasn't at Berkeley yet. He knows where the source of the website is, while I am still getting up to speed on pretty much everything.

@stefanv
stefanv merged commit c9b9634 into numpy:master Oct 4, 2016
@amueller

amueller commented Oct 4, 2016

Copy link
Copy Markdown
Contributor Author

thanks for the merge @stefanv, hope this helps.

@stefanv

stefanv commented Oct 4, 2016 via email

Copy link
Copy Markdown
Contributor

mpharrigan pushed a commit to mpharrigan/numpydoc that referenced this pull request Nov 30, 2016
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.

4 participants