Skip to content

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

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

Merged
merged 1 commit into from
Oct 4, 2016

Conversation

amueller
Copy link
Contributor

@amueller amueller commented Sep 7, 2016

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
Copy link
Member

pv commented Sep 7, 2016 via email

@amueller
Copy link
Contributor Author

amueller commented Sep 7, 2016

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
Copy link
Contributor Author

amueller commented Sep 7, 2016

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
Copy link
Contributor Author

amueller commented Sep 7, 2016

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
Copy link
Contributor Author

amueller commented Sep 7, 2016

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.

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
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
Contributor Author

Choose a reason for hiding this comment

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

good point.

@@ -184,6 +183,33 @@ class NumpyCDomain(ManglingDomainBase, CDomain):
}


def match_items(lines, content_old):
"""Create the right items for lines.
Copy link
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.

Copy link
Contributor Author

@amueller amueller Sep 9, 2016

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
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
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
Copy link
Contributor

stefanv commented Sep 9, 2016

@amueller The new docstring is excellent, thank you!

@amueller
Copy link
Contributor Author

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

@stefanv
Copy link
Contributor

stefanv commented Sep 15, 2016 via email

@NelleV
Copy link
Contributor

NelleV commented Sep 20, 2016

@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
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
Contributor Author

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

@NelleV
Copy link
Contributor

NelleV commented Sep 22, 2016

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
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
Copy link
Contributor

NelleV commented Sep 22, 2016

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
Copy link
Contributor Author

amueller commented Oct 4, 2016

thanks for the merge @stefanv, hope this helps.

@stefanv
Copy link
Contributor

stefanv commented Oct 4, 2016 via email

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