-
-
Notifications
You must be signed in to change notification settings - Fork 32
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
Support examples section #35
Conversation
Hey @pawamoy, can you check briefly this PR and mkdocstrings/mkdocstrings#112. I think I almost have it, but I think there is something failing... I tried to debug, but I didn't find the way to debug among 3 different projects using Pycharm. How do you debug while using code from 3 different projects (mkdocs, mkdocstrings, pytkdocs)? |
Hey @igonro! Your PRs are looking great so far 🙂 About debugging. MkDocs and mkdocstrings run in the same process, so it's easy to debug them together: in PyCharm, just go to mkdocs code in the site-packages directory, and add your breakpoints there (you can also control-click on an mkdocs object/class to be sent directly where it's defined). But pytkdocs runs in a subprocess. In PyCharm settings, it seems that subprocess that have python in their name are attached to the debugger, however I was not always able to make it work. There is an issue in their bug tracker about it, not sure if it is still relevant: https://youtrack.jetbrains.com/issue/PY-22623. There's also some information on StackOverflow https://stackoverflow.com/questions/26465221/debugging-popen-subprocesses-with-pycharm, but nothing really helping I'm afraid. What you can do to ease debugging is to also install pytkdocs in mkdocstrings project in editable mode. Just go the clone of your mkdocstrings fork, activate the virtualenv (poetry shell), then go to your pytkdocs directory and run |
Now for the review: The idea here is to support the classic syntax for examples block. What you did here is great, but it's only a start. The parser should especially parse blocks like this: >>> print("some statement")
some statement ...to allow users to write their examples naturally, without fenced code blocks or extra indentation. You would need to store the text and examples in order somehow, so we can render them accordingly in mkdocstrings. A more complete example:
The spec to detect and parse such code blocks:
I'm going to ask your and @jaimergp's opinion on this spec. Is it correct? Finally, when rendering examples section, we will have to force the syntax highlight to Python for the detected code blocks. |
I think the doctest spec allows several consecutive test lines: >>> returns_none()
>>> returns_arg("a")
"a" Multiline doctest is also possible and detected with the indentation relative to the >>> for i in range(5):
>>> do_something()
1 2 3 4 5 |
I've done everything I could have done, but I think that the result is pretty good. I've added a test with the following docstring:
|
I don' know why but I'm not being able to run |
Yes it's my fault the CI doesn't pass, don't worry about it, I'll fix it (just the current directory missing in python sys path). So, this all look great 🙂 Thank you very much for having invested time to send these PRs, I really appreciate it. If you don't have more time to spend, which I totally understand, I'll take it from there. I think it's important that we support the full doctest spec, and the link @jaimergp posted shows that we could maybe use If you checked the "allow maintainers to edit this PR" or similar check box on this PR, I'll be able to push commits to your branch. If not, could you check it? Thanks! |
9365643
to
f7fa027
Compare
Thanks again @igonro, I'll merge this now and continue the work from a fresh master. |
This PR is to support the examples section.
In progress...
Issue #8 and PR mkdocstrings/mkdocstrings#112