-
Notifications
You must be signed in to change notification settings - Fork 393
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
Jupytext in a pre-commit disagreement with trailing-whitespace and prettier #580
Comments
Jupytext
in a pre-commit disagreement with trailing-whitespace
and prettier
Seems like the problem was that
So the solution, I guess, is either to disband the goal mentioned above, or to run all hooks also on |
Hi @tordbb , thanks for taking the time to report this. I must say that I am not sure yet what is the best way to use pre-commit hooks on notebooks (see also #432 , #446). This is a topic on which I'd like to make progress, but, just like you did here, many times I encountered difficulties in applying pre-commit hooks on pairs of files. Maybe you could consider doing the following: |
Thanks again for your help! The problem turned out to be how When I made I am not sure if jupytext should adapt the formatting that prettier idolizes, but that may be up to you. See my final
|
Thank you @tordbb for sharing this! At some point I'd like to write a quick post or documentation page on how to best use pre-commit hooks, may I reuse your config above?
Nice challenge... let me think about it...
How that's interesting... Jupytext uses Regarding the extra blank line, Jupytext should include a blank line between any two cells (and thus match |
Hi!
Off course, feel free to use it all. I am so thankful for your work on
jupytext, and would be honored if my small contribution is somehow helpful
in your work - published or not.
Regarding your question about YAML, I am afraid I do not know.
Thanks again, and have a great day!
…On Fri, Jul 31, 2020, 18:29 Marc Wouts ***@***.***> wrote:
Thank you @tordbb <https://github.com/tordbb> for sharing this! At some
point I'd like to write a quick post or documentation page on how to best
use pre-commit hooks, may I reuse your config above?
a regex that only excluded .md files inside notebooks/
Nice challenge... let me think about it...
I am not sure if jupytext should adapt the formatting that prettier
idolizes
How that's interesting... Jupytext uses yaml to encode the YAML header,
so I am a bit surprised that the quotes don't match those of prettier..
do you have any idea how prettier parses the YAML, and which one is the
most standard?
Regarding the extra blank line, Jupytext should include a blank line
between any two cells (and thus match prettier, right?)
When you don't get a line in between, this is because the cell has a cell
metadata lines_to_next_cell=0, which is itself coming from the text file,
if at some point the markdown cell and the code cell were not separated by
a blank line.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#580 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACXBS4F5TNXFP72U7IO36IDR6LWOFANCNFSM4PN45FUA>
.
|
@tordbb @mwouts I quite like my solution to using JuPyText as a pre-commit hook which can be found below:
This has some benefits:
TLDR: Use --set-formats and --sync will solve a lot of your issues @tordbb since which file is newer will overwrite the changes in the other. |
Thank you @tordbb and @Skylion007 . This is getting interesting! When time permits I will experiment a bit more with this myself, and write a post with all due credit to your examples ! @Skylion007 , do we agree that Also I see you use |
@mwouts More than that, I would like to code up a simple pre-commit yaml for the repo. One that doesn't need to use the current the --pre-commit arg and uses the nice features baked into pre-commit.com |
Oh, that would be awesome! |
I am also having an issue with jupytext and prettier generating conflicting formatting. I think the best would be to pipe the output through prettier as well, as suggested for black: -args: ['--pipe', 'black']
+args: ['--pipe', 'black', '--pipe', 'prettier -w {}'] However, it is the markdown file that would need to be piped through prettier, and I don't think one can have multiple
|
Hi @grst , I do like the suggestion of allowing multiple jupytext/tests/test_pre_commit_5_reformat_markdown.py Lines 38 to 46 in 12964ef
Do you think the same approach could be used to call |
I haven't tried it, but as long as it's two separate steps in pre-commit, I'd expect it to suffer from the same problem: If the first step generates a different formatting than the second one they cannot pass at the same time (pre-commit fails if a file got modified). That being said, in the above example it could work, i.e. the first jupytext command only modifies an |
Hi,
I am trying to run
jupytext
as a first step inpre-commit
, before running among otherstrailing-whitespace
andprettier
.My goal is for jupytext to generate
.md
files based on.ipynb
files, since these are easier to version control than.ipynb
.The idea is that pre-commit will pass if no new
.md
file is added, and if no existing.md
file is changed by jupytext.The way I implemented this seems to cause a problem with two other hooks,
trailing-whitespace
andprettier
. The way jupytext formats the.md
files causetrailing-whitespace
andprettier
to fail and adjusting the code.Is there any way to adjust
jupytext
or the way I use it, so that these other hooks do not fail?This is my file
.pre-commit-config.yaml
which lives in the root directory:If I update an
.ipynb
file and run pre-commit, this happens:Immediately re-running pre-commit causes all other notebooks to be updated by jupytext,.
The text was updated successfully, but these errors were encountered: