question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Catch errors when running --pipe black

See original GitHub issue

If you try to run the --pipe black command over a set of notebooks in one or more directories, and black fails for some reason, the pipe fails at that point.

Non-runnable illustrative fragment:

jupytext --sync  --pipe black  Part*/*.ipynb

---

[jupytext] Executing black -
reformatted -
All done! ✨ 🍰 ✨
1 file reformatted.
[jupytext] Updating 'Part 03 Notebooks/03.2 Selecting and projecting, sorting and limiting.ipynb'
[jupytext] Updating 'Part 03 Notebooks/.md/03.2 Selecting and projecting, sorting and limiting.md'
[jupytext] Reading Part 03 Notebooks/03.3 Combining data from multiple datasets.ipynb in format ipynb
[jupytext] Loading 'Part 03 Notebooks/.md/03.3 Combining data from multiple datasets.md'
[jupytext] Executing black -
error: cannot format -: Cannot parse: 156:9: result = %sql SELECT * FROM quickdemo WHERE value > 25
Oh no! 💥 💔 💥
1 file failed to reformat.

In the above case, black failed trying to parse a line that assigned the result of a line magic call to a variable.

It would be useful if the Jupytext pipe did not fail, but did perhaps warn that a file could not be parsed.

Another solution might be to allow a cell to be tagged as no-black or similar and be ignored somehow (--ignore-tag no-black?) (I’m not sure if you apply the formatter at the cell level?)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mwoutscommented, May 30, 2021

Hi @psychemedia , I expect to have fixed both issues in the development version. Feel free to give it a try, cf. https://jupytext.readthedocs.io/en/latest/developing.html

0reactions
MarcoGorellicommented, Jul 12, 2021

Jupytext does not identify the line myvar = %dont_format_me as a magic command, maybe we could improve that part as well

Suggestion for how to do this:

>>> from IPython.core.inputtransformer2 import TransformerManager
>>> TransformerManager().transform_cell('myvar = %dont_format_me')
"myvar = get_ipython().run_line_magic('dont_format_me', '')\n"

Then, using ast.parse, detect lines with get_ipython().run_line_magic (and other functions which magics would get transformed to) and comment them out (e.g. of what I’m referring to: https://github.com/psf/black/pull/2357 , where jupytext has been mentioned)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Node.js: Error handling when using pipe with streams
The pipeline handles errors and closes streams correctly. Using a pipeline, the example ... catch( error ){ console.log('error.....'); }.
Read more >
Global Error Handling in Angular - Philipp Kief
In this article you will learn how to catch various errors in Angular — one of the world's most popular front end frameworks...
Read more >
Catching Multiple Exception Types and Rethrowing ...
The catch clause specifies the types of exceptions that the block can handle, and each exception type is separated with a vertical bar...
Read more >
about Try Catch Finally - PowerShell | Microsoft Learn
A try statement can include multiple catch blocks for the different specified error types. The finally keyword is followed by a statement list ......
Read more >
Angular error handling best practices - YouTube
In todays angular 4/5/6 error handling best practices tutorial session I will demonstrate the best possible ways to handle angular http ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found