Open technic opened 4 years ago
Hi @technic , thank you for sharing this. Well currently Jupytext does not have an option for this, but sure it makes sense to offer compatibility with vscode... Although it is a bit unfortunate that they took a different approach than ours :smile: Do we have any idea why they were not happy with # %%magic_command
? Maybe they though it was too close to the # %%
cell delimiter?
Maybe they though it was too close to the # %% cell delimiter?
I think, yes.
I may address the point soon. @technic , we will have to choose between the two options below
comment_magics_like_vscode
(do you see a better name?), or/andpy:vscode
format (like the py:hydrogen
format, which is the same as py:percent
except for the magics that are not commented)Which is your favorite approach?
Thanks! For me both is ok. I think the second option is easier to setup.
@technic , I was giving a try at this, but I am not sure I can get the magic commands to work in VS Code. Here is what I tried:
%%time
magic cell
# %%
from IPython import get_ipython
get_ipython().run_cell_magic('time', '', '1 + 1')
- add a new cell with the magic syntax reported above, i.e.
1 + 1
- then execute the whole script. In my experience the `#!%%time` command does nothing special (unlike the `run_cell_magic` command), as shown below. Do you get a different outcome? In other words, are we sure that the `#!%` commands are still supported by VS Code?
![image](https://user-images.githubusercontent.com/29915202/95020412-43946c80-066b-11eb-9a44-31a65b5119f6.png)
Oh, and I just tried a simple (uncommented) magic command (activate the option command_magics=False, or use the py:hydrogen
format), and it worked! Is this what you were looking for?
Hi, i think this option has to be enabled in vscode
python.dataScience.magicCommandsAsComments
I didn't know that uncomented commands are supported in vscode now! However this still can raise unnecessary warnings by linters.
Hi, I think this one is on the milestone 1.7.1 but currently we are at 1.11.4. Any chance this 1.7.1 will be done in near future?
Hi @iamdionysus , well we did not implement anything here, but rather I think we noticed that uncommented magic command could be used directly in VS code. You can get these uncommented magic commands with the py:hydrogen
format. Can you give it a try and report whether or not it helps with your use case?
Hi @mwouts Thanks for your feedback. I have tried py:hydrogen
format. That will comment out magic command so I can run in the VS code. But the problem with that is it is not python code so VS code will give me it is a problem because it is not Expected expression
in .py
code. One reason why we use .py
with jupytext
is to make our python
code as pure python code I guess.
I see. I just gave a quick try to the magicCommandsAsComments
setting in the jupyter extension to make sure I could activate the setting on my side:
and indeed it worked (i.e. the magic command #!%%time
became effective when I turned the setting on in vscode)
I agree that this is better than py:hydrogen
as it avoids the python code error:
I think this should be implemented as a new option in config.py
. The name will be important, what do you think of magic_commands_as_vscode_comments
?
Or would you prefer to allow comment_magics = "vscode"
in addition to True
and False
?
Thanks for checking it out! comment_magics = "vscode"
looks good.
Any update on this? The solution described sounds perfect, just need it to be implemented and released. Thanks.
Thanks for the great software! Any update on this? I think this would be a very helpful feature for using jupytext with VSCode.
Hi, vscode has the following feature https://github.com/microsoft/vscode-python/issues/6408 So, the magic commands in the py file commented like this are recognized:
Currently jupytext stores magic like this:
Is there a way to configure it or change?