-
Notifications
You must be signed in to change notification settings - Fork 4
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
Allow >>> Python style doctests #236
Conversation
I'm on fence (say "+0" to merge) and would like a little more information first. Thoughts:
|
I think I would be ok with this change, but maybe change the regex to allow any number of I certainly don't think this should be advertised or encouraged, but it seems fairly harmless to allow as an option for those who want to exploit this magic shortcut. I glanced at Sphinx and Docutils, and as far as I can tell, the prompt is hardcoded here, no option to teach Docutils to recognize a different prompt string. But again, this is just a convenience shortcut recognized by Sphinx for embedded Python doctests. |
@@ -30,7 +30,7 @@ | |||
% extract tests from docstring | |||
TEST_RE = [ % loosely based on Python 2.6 doctest.py, line 510 | |||
'(?m)(?-s)' ... % options | |||
'(?:^ *>> )' ... % ">> " | |||
'(?:^ *>>>? )' ... % ">> " or ">>> " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about (?:^ *>>>* )
? This would make valid prompts out of >>
, or >>>
, or even >>>>>>
, without giving any special significance to Python's default >>>
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could do that, of course. Can you think of a situation, where it would be useful to have more than three >
?
Doctests come from Python (to my best knowledge). Since Matlab does not have a mature documentation system, we are required to use s.th. like Sphinx instead. Afaik it is not possible to change that in Sphinx, since Python doctests are pretty straight-forward.
That's right. But, as @mtmiller stated, I wouldn't advertise this, just add support for people, who are using Sphinx for document generation. That's why I only changed the regex searching for tests not the other occurances of
You're right. Readability is most important here. I don't expect users to care about two or three guillemet. I think they care more about the additional indentation level and two extra lines. |
One possible counterargument to this: Octave, but not Matlab, uses the
Unfortunately this doesn't work with doctest right now, should it? Obviously recognizing |
Hmm, that's a good point @mtmiller. It is probably something that one could reasonably expect to work with doctest. The reason that it hasn't come up yet is that one would typically just match on the syntax error but add |
Hmm, I think the issue with this example is different one. Python doctest is using the keyword ## >> x = 2 * (1 + 1))
## ??? parse error:
## <BLANKLINE>
## syntax error
## <BLANKLINE>
## >>> x = 2 * (1 + 1))
##
## >> % The next doctest See https://docs.python.org/3.7/library/doctest.html#how-are-docstring-examples-recognized |
I believe we are not using a special keyword for empty lines (unlike Python). From a quick glance the regex part capturing the output does stop upon meeting |
I filed #237 for the "quick glance" comment of @catch22. But I'm not sure what we should do here. They way we handle errors is already a bit wonky. We prepend whatever Matlab/Octave give us with We could prepend all lines of error messages with |
I filed #238 for |
Turns out we've actually had much of this discussion already in #100 sigh. Interestingly, @oheim claimed almost no one was using @catch22: do you use Perhaps Sphinx usage (with |
What if the first |
That would certainly be a clever solution! (Is it too clever? 😄) @skycaptain - are you directly running Sphinx on your Matlab code, or are you doing some preprocessing/extraction first? Is there a GitHub repository where we can have a look at your work flow? |
@catch22: I'm using sphinx-contrib/matlabdomain for in addition to Sphinx. The project itself is private I fear. I'll try to setup a public repo mimicing my usecase. |
In a way, it would make more sense to "fix" sphinx-contrib/matlabdomain so that it can deal with Matlab/Octave-style prompts than for us to use Python's prompt. Is this a realistic option? On the other hand, even Octave itself isn't consistent in its prompt. I think it's
|
Hmm. Not an elegant solution, but one could Monkey-patch this line. I filed sphinx-contrib/matlabdomain#94 |
Thanks for filing the issue at sphinx-contrib/matlabdomain#94. This sounds like a problem best solved by discussing across projects. |
We're using Sphinx for generating HTML docs out of help texts. Sphinx recognizes doctests starting with
>>>
and formats them as accordingly. Maybe we could add support for that.This would allow us to use:
Instead of: