8000 [MRG] EHN support #%% cell separators by lucyleeow · Pull Request #518 · sphinx-gallery/sphinx-gallery · GitHub
[go: up one dir, main page]

Skip to content

[MRG] EHN support #%% cell separators #518

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 11 commits into from
Jul 15, 2019
Merged

Conversation

lucyleeow
Copy link
Contributor
@lucyleeow lucyleeow commented Jul 11, 2019

closes #370

Support # %% as cell separators.
Amend 'test_bug_cases_of_notebook_syntax.py' to test 2 input docs - the original one that uses only #'s as a cell separator and one that uses both #'s and # %% as cell separators.
Amend docs to advise that # %% can also be used.

@lucyleeow lucyleeow changed the title [WIP] EHN support # %% cell separators [MRG] EHN support # %% cell separators Jul 11, 2019
@codecov-io
Copy link
codecov-io commented Jul 11, 2019

Codecov Report

Merging #518 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #518      +/-   ##
==========================================
+ Coverage   96.23%   96.24%   +<.01%     
==========================================
  Files          29       29              
  Lines        2686     2687       +1     
==========================================
+ Hits         2585     2586       +1     
  Misses        101      101
Impacted Files Coverage Δ
sphinx_gallery/py_source_parser.py 91.76% <ø> (ø) ⬆️
sphinx_gallery/tests/test_gen_rst.py 98.75% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f2e6cc9...b54e8f4. Read the comment docs.

====================

When writting latex in a Python string keep in mind to escape the backslashes
or use a raw docstring
Copy link
Contributor

Choose a reason for hiding this comment

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

this file looks too much a copy paste from https://sphinx-gallery.github.io/tutorials/plot_parse.html
I would suggest to see how to integrate both so users find the information more easily.

my 2c

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It IS a copy paste from that.
The original test I modified (test_bug_cases_of_notebook_syntax() from https://github.com/sphinx-gallery/sphinx-gallery/blob/master/sphinx_gallery/tests/test_gen_rst.py) tests that split_code_and_text_blocks() is performed correctly on the file 'tutorials/plot_parse.py'. I just amended that test to also test a version of 'plot_parse.py' ('plot_parse_both.py') which uses # %% as separators as well as #'s.

Sorry, what do you mean integrate both? I can change the test to test only the 'new' plot_parse_both.py file which uses both #'s and # %% as a separator?

8000

Copy link
Contributor

Choose a reason for hiding this comment

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

now 2 almost identical files are going to show up on the documentation. I agree that it does the job for the testing but from a narrative doc perspective I would suggest this new example is as easy to discover as the old one OR to integrate them into one (at least for the documentation perspective).

my 2c

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah I see the problem now. I will integrate them into one.

@choldgraf
Copy link
Contributor

shit why didn't we think of this before haha, I think it's a good patch, seems reasonable to me. So if I wanted to add rST underneath it would look something like:

# %%
# my rst
# ======

my = "code"

?

@@ -11,7 +11,7 @@
Closing this string quotes on same line"""


##############################################################################
# %%
Copy link
Contributor

Choose a reason for hiding this comment

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

I would add a note that at the top of the file that 2 types of separators are possible. Say you'll use
the ### at the beginning of the file, put a note saying that you'll use in what follows the alternative
approach with # %%

does it make sense?

Copy link
Contributor Author
@lucyleeow lucyleeow Jul 11, 2019

Choose a reason for hiding this comment

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

Yes I realised above when you talked about the double up that the plot_parse.py file is actually a page in the sphinx-gallery documentation (whoops). Am now amending this file to add the relevant information.

@lucyleeow lucyleeow changed the title [MRG] EHN support # %% cell separators [WIP] EHN support # %% cell separators Jul 11, 2019
Copy link
Contributor
@GaelVaroquaux GaelVaroquaux left a comment

Choose a reason for hiding this comment

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

Looks good overall !

I think that an entry in the changelog is needed.

Also, it might be good to add somewhere a note on productivity tips (for instance using the sphinx directive "topic"), explaining to people how they can work in a convenient way bending these tools)

Copy link
Contributor
@larsoner larsoner left a comment

Choose a reason for hiding this comment

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

Can you tweak this test:

https://github.com/sphinx-gallery/sphinx-gallery/blob/master/sphinx_gallery/tests/test_gen_rst.py#L105

By making the second set of ####### into # %%?

Otherwise LGTM!

@lucyleeow
Copy link
Contributor Author
lucyleeow commented Jul 12, 2019

After speaking with @GaelVaroquaux we think both # %% and #%% (with and without space) should be supported:

  • Spyder supports both because Eclipse's automatic code formatting changes #%% into # %% (see this issue)
  • Hydrogen states that # %% is supported in their documentation but on testing both syntaxes work and exports correct cell formatting to jupyter notebook.
  • VSCode states that #%% is supported but on testing both syntaxes work.
  • Could not test in PyCharm as this functionality is only available in their professional version.

If there are no objections, I will change the code and documentation to support both syntaxes. I think I will state that a line of #'s or #%% can be used and just note that # %% is also acceptable for compatibility.

Will also add to the documentation a guide/tips to using the various IDE's with sphinx-gallery suggested by @GaelVaroquaux above.

@larsoner
Copy link
Contributor

Works for me

@lucyleeow lucyleeow changed the title [WIP] EHN support # %% cell separators [WIP] EHN support #%% cell separators Jul 12, 2019
@larsoner
Copy link
Contributor

I think that an entry in the changelog is needed.

I just noticed this bit. FYI we don't need changelog entries because we autogenerate them based on PR labels. But it's fine to leave the one you added in there

Copy link
Contributor
@larsoner larsoner left a comment

Choose a reason for hiding this comment

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

Other than a tiny suggestion LGTM +1 for merge

Please remove WIP from the title if it is indeed ready to go

@lucyleeow lucyleeow changed the title [WIP] EHN support #%% cell separators [MRG] EHN support #%% cell separators Jul 15, 2019
@lucyleeow
Copy link
Contributor Author
lucyleeow commented Jul 15, 2019

Amended the doc to add a note on using sphinx gallery with code blocks. Hopefully this makes sense.

@choldgraf
Copy link
Contributor

This seems good to me! @GaelVaroquaux you're still blocking changes just FYI :-)

@larsoner
Copy link
Contributor

@GaelVaroquaux you're still blocking changes just FYI :-)

From the above I'm pretty sure it's just for the changelog update and link updating which are done. So I'll merge but if there was something still wrong @GaelVaroquaux feel free to chime in and we'll fix it.

Thanks @lucyleeow !

@larsoner larsoner merged commit 46e1335 into sphinx-gallery:master Jul 15, 2019
@GaelVaroquaux
Copy link
Contributor
GaelVaroquaux commented Jul 15, 2019 via email

@rth
Copy link
rth commented Apr 28, 2020

Thanks for this @lucyleeow ! it is going to make scikit-learn examples much more readable in plain text mode scikit-learn/scikit-learn#17068

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: Add an option for different cell separations
7 participants
0