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
Can autoreload magics be kept above isort output? #488
Comments
Thanks for your report! I couldn't reproduce this: I tried pasting your input into a cell and got the following:
Could you please paste the output of
That's very kind of you, thanks! Please do let us know of any other issues you run into and/or if you have any ideas for how to improve it |
Hey Marco! Thanks for the fast reply. Here is my output
|
ah, so you have
? |
Does isort has - - float-to-top setting present it's configuration? |
And if I put
I have just checked and it's the same behavior when I put them in the same cell.
|
Do you have a Because I can't reproduce this unless, as suggested by Girish, I use
|
Yes, you are right. That solves it! Sorry for the trouble. |
Cool, thanks both 👍 - closing then |
We are indeed using |
Because I see that if I add a new cell on top, which is markdown, it stays where it is. |
that should be the default behaviour - if you just run |
The reason imports go to top of the file with that setting is because nbqa converts the contents of all the "code cells" to become statements of a python file in the order in which they appear in the notebook. Ipython magics also become valid python statements |
I see, thank you guys. But is there a way to override the |
Oh, I think I've found it. |
That's a bit of a hack though, as it won't sort the content of those cells. Could you show us the content of |
Try passing |
Sure, this is what our ITs have put in the project (and what I cannot change):
I guess most settings are set just to be compatible with |
If your isort config is present in setup.cfg, then create a different file called my_isort.cfg and pass it via the - -nbqa-config flag |
I guess I have to create a |
Got you. That should work! |
wait, passing a custom It should be possible to overwrite it, will just try something and get back to you |
Yes, I was just wondering if I can tell |
Got it - you can just do
EDIT: ignore this message, this soln is wrong |
I thought a file like [isort] |
Weirdly, it produces no output at all (so sys and pathlib are not sorted either). I have tried |
Yes, this could absolutely be a solution. I just need to create a file 👍 |
you're right, And yup, if you just want to ignore the present configs, then passing some dummy .cfg file to |
That's weird right. I thought setting to 0 would work |
Yes, good point. But I have checked in the isort repo, and they only store true if the key is provided. So there seems to be no simple way to override. |
Thanks. Indeed, float-to-top is considered by isort guys as something that you would not supply at each run. So they seem to have not thought about a mechanism to disable it. |
Thanks anyway for the discussion! Very helpful! |
Btw, I have found another workaround: I can put the jupyter magic in the startup script of jupyter thus removing it from the nb. |
This'll be in isort 5.7.0 🎉 PyCQA/isort#1603 |
I have tried to look around, but I am not sure if one of the recent fixed addresses this problem. I am using
nbQA
for itsisort
functionality and have the following problem.A notebook which looks like this (MWE)
is converted by
nbqa isort
intowhich actually invalidates the
autoreload
extension that must be loaded before any imports. I have tried to use# isort:skip
or put it in a different cell, but to no avail.Do you know if there's a fix for this?
Otherwise, thanks for the great hooks!
The text was updated successfully, but these errors were encountered: