-
Notifications
You must be signed in to change notification settings - Fork 9
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
Compatibility with jupyter notebooks #31
Conversation
Does nbconvert do a roundtrip conversion of notebooks? I'm worried some metadata in the notebooks might be lost if we do this. |
AFIK, nbconvert can not do that. Only In my code, .py file is not converted back to the notebook. Rather, string replacements were done only in the code-cells of the original notebook. Other fields of the notebook e.g. metadata are not operated on. |
Oh I see. That seems better then. It would be good to have at least one test of this. Maybe you can generate an example before and after notebook file and check that it converts the one to the other. |
removestar/removestar.py
Outdated
|
||
def replace_imports(code, repls, *, max_line_length=100, file=None, verbose=False, quiet=False): | ||
def replace_imports(code, repls, *, max_line_length=100, file=None, verbose=False, quiet=False,return_replacements=False): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keyword arguments that change the return type aren't great. It would be better to just have a separate function to return replacements.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had a look again. As I see it, refactoring replace_imports
for removestar_nb
might be problematic because it would need duplicating the code. I agree that the keyword arguments that change the return type are not ideal. But I am not sure if there's any alternative here.
I just added a test for |
I hope the test I added for |
I've refactored almost the whole PR while keeping the original logic intact, but the code is still very repetitive and can be refactored more. The code now looks similar to the old code and everything works now, the new tests pass and the old ones are passing too. I think it should be okay to merge this in, make a new release, and then iteratively work on refactoring the code. Thanks for taking this up, @rraadd88! I'll maybe let this sit for a few days and then merge (I might end up gathering the courage to refactor this further over the weekend). |
Steps:
nbformat
,nbconvert
,removestar
to find replacements,nbformat
.Apart from core functionalities inherited from
removestar
:-o
command line argument.replace_imports
function returns a dictionary with string replacements, usingreturn_replacements
flag. This would allow further extensions as needed.pip install removestar[nb]
Not added: