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.

Black has syntax error with valid iPython magic when using --pipe

See original GitHub issue

To reproduce:

This occurs on black, version 19.10b0 and ‘jupytext==1.5.2’. When --sync a notebook to py:percent format using the following command:

jupytext --update-metadata '{"jupytext":{"notebook_metadata_filter":"all", "cell_metadata_filter":"-all"}, "accelerator":"GPU"}' --set-formats 'nb_python//py:percent,colabs//ipynb' --pipe black --pipe "sed s/[[:space:]]*\#[[:space:]]\%\%/\#\%\%/g"  --pipe 'isort -' --pipe-fmt 'py:percent' --sync

I get this error:

executing black -
error: cannot format -: Cannot parse: 73:0: !~/miniconda.sh -b -p $HOME/miniconda

Now I tracked down the error, and when I change the lines ipynb to use !bash ~/miniconda.sh -b -p $HOME/miniconda, it works just fine. Also the following lines also generated error:

error: cannot format -: Cannot parse: 78:0: !. activate habitat;``` 

I had to change it to
```bash
!conda . activate

I also had to change:

!./test_locally_pointnav_rgbd.sh

to

!bash ./test_locally_pointnav_rgbd.sh

TLDR: Black has issues when the first arg following ‘!’ isn’t a command, but references an executable file or another bash alias.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
Skylion007commented, Aug 19, 2020

@mwouts I opened a PR that solves the issue.

0reactions
mwoutscommented, Aug 20, 2020

Thanks @Skylion007 for the fix. And for the notebook examples. Great project by the way!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Built-in magic commands — IPython 8.7.0 documentation
To work properly, Magics must use a syntax element which is not valid in the underlying language.
Read more >
IPython Documentation
The main issue is that a basic python setup.py install ... tionally can use colors for this, syntax highlighting source code and various ......
Read more >
Xonsh Change Log - xonsh 0.13.2 documentation
Fixed error caused by unintialized Xonsh session env when using Xonsh as a ... A SyntaxError is raised when string literal concatenation is...
Read more >
How to run IPython script from the command line - syntax ...
You need to name your file script.ipy. When it ends in .ipy it can contain ipython syntax. From ipython --help : Usage ipython...
Read more >
Black
Black is the uncompromising Python code formatter. By using it ... If you want to format Jupyter Notebooks, install with pip install 'black[jupyter]'...
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