Is there any way to generate a diff between two versions of an IPython notebook? - diff

I have started using IPython notebook quite a bit for writing up draft sections for my dissertation. However, given two versions of a draft (i.e., notebook), I would like to be able to generate some form of diff output to show what has changed. Does anyone know if this is currently possible, either through IPython notebook itself, or through some extension?

Notebook diff can be generated with nbdime. After installing nbdime you can run following to see notebook diff in browser:
> nbdiff-web notebook_1.ipynb notebook_2.ipynb
If you are using Github for version control you can use ReviewNB for Notebook diff. It lets you login via Github and browse commits/pull-request diff on your repo. You'll see visual diff like below:

1- VS Code has added to its Aug 2020 version
see here
2- try nbdime

Try the following steps:
Install nbdime by typing pip install nbdime on a terminal.
Integrate with Git by typing nbdime config-git --enable --global on a terminal.
Type nbdiff-web path/to/notebook.ipynb on a terminal.
You can choose to ignore certain types of cells. For example, if you want to ignore output cells, type: nbdiff-web --ignore-outputs path/to/notebook.ipynb.
More information on the different diff options here:
https://nbdime.readthedocs.io/en/latest/cli.html#common-diff-options

Since this question was answered, NBdiff, a diffing and merging tool for the IPython Notebook appeared on GitHub. Unfortunately, it has yet to be updated for Jupyter / IPython 3 Notebook format.

Another utility from the git issue that looks to have gotten official traction is nbdime.

Not yet. This is a often a requested feature, but there are different "level" of diff you might want.
Do you want only diff of codecell, or also output, what about prompt number ? etc, etc.
Lots of people have chimed in but nobody really took the time to wrote anything, even if notebook are pretty "simple" json file where cell "just" need to be "aligned" then produce a diffed-json notebook.

Curvenote provides a chrome extension that allows you to put your notebook in version control and then you can diff individual cells nbdime style, but also see previous outputs (plots, tables, streams,...) generated by the different versions of your code.

Related

Does VS Code install some extensions automatically?

I noticed that I have many extensions installed that I don't recall manually installing, e.g. isort, jupiter cell tags, etc.
I only installed the "python" and "jupyter notebooks" extensions myself. Those others seem to be installed later without my knowledge.
Does VS Code install extensions automatically somehow?
To answer the general question
Yes, VS Code does come with some extensions installed "out-of-box". It calls those extensions "Built-In" extensions. If you open the extension page of one of those extensions, it will say:
Notice: This extension is bundled with Visual Studio Code. It can be disabled but not uninstalled.
One example of this is the vscode.typescript-language-features extension. You can get a list of all running with the Developer: Show Running Extensions command. It's kind of hard to find them otherwise, since they don't normally show up in the extensions sidebar.
In your particular case, you misunderstood something
The Python and Jupyter extensions you installed are extension packs. They include isort and Jupyter Cell Tags (as well as others).
You can see for yourself.
https://marketplace.visualstudio.com/items?itemName=ms-python.python:
The Python extension will automatically install the Pylance, Jupyter and isort extensions to give you the best experience when working with Python files and Jupyter notebooks.
https://marketplace.visualstudio.com/items?itemName=ms-toolsai.jupyter:
The Jupyter Extension will automatically install the following extensions by default to provide enhanced Jupyter notebook experiences in VS Code.
Jupyter Keymap - to provide Jupyter-consistent keymaps
Jupyter Notebook Renderers - to provide renderers for MIME types such as latex, plotly, vega, etc.
Jupyter Cell Tags and Jupyter Slide Show - to provide the ability to tag cells in notebooks and support for presentations

Adding tags to Jupyter notebooks

As suggested in the description of the Jupyter Miscrosoft extension for Visual Studio Code (VSC), I come here to ask you about support for cell metadata in jupyter notebooks. It seems nothing is currently available for adding cell metadata and, thus, using the papermill extension when writing python notebooks with VSC.
The last message in this 2019 github discussion, dated 2021-05-28, points to this other discussion where on 2021-05-13 someone suggested to use the Jupyter Powertools extension.
However, as of today 2021-10-03, that extension seems not to be compatible with either of my VSC versions:
VSC 1.60.2
VSC Insiders: 1.61.0
with no updates available for either one of them (using Windows 10).
Is there any way to use papermill with VSC? If not, are you aware of any papermill alternatives for parameterizing notebooks while using VSC?
Thanks
I find extension Jupyter Power Tools that can add tag by click icon tag+ left beside icon python. But it failed in vscode version 1.660
Update - Jupyter Power Tools is now deprecated and functionality to be included within MSFT's Jupyter PowerToys extension. A tags interface / cell metadata editor does not appear to have been included, but they have an open issue here.

How can I enable file path autocompletion in the IPython console in PyCharm?

Note: The suboptimal autocompletion (not necessarily of file paths only, but autocompletion in general) is a known issue, and there seems to be no generic quality solution yet. Please see the researched links below.
Path autocompletion in the IPython console in PyCharm does not work well:
c:/U<TAB>
should autocomplete to:
cd c:/Users/
on my machine; instead, the best it manages is:
cd c:/UserWarning
which is plain wrong. IPython in the Anaconda prompt, however, behaves as it should.
My strong assumption (supported by a link, below) is that this is due to PyCharm not using the standard IPython configuration files.
I'm aware of the console starting script in PyCharm:
Settings->Build, Execution, Deployment->Console->Python console
and I've successfully used it to activate a simple magic command I've written.
So here my question: is there a code configuration snippet that could be inserted there, and that could just enable file path autocompletion? Or a pointer to a general description on how IPython configuration files "work", that would enable me to figure it out myself? That is, I imagine, the most doable hack that would solve the problem for the time being.
Alternatively, any experiences with writing your own autocompletion using the following libraries:
IPython.core.completer
IPython.core.completerlib
?
Is that doable? How much work can that be?
Thanks in advance!
My SW-Setup:
I use:
PyCharm Community Edition 2017.2.1
Anaconda 2 (Python 2.7), version 4.3.22 which contains
IPython 5.1.0
on Windows 7 Professional N
Links supporting claims in the question(s) above - just two, due to lack of StackOverflow-"reputation" :(
1) Autocompletion in IPython console in PyCharm not working as it should
JetBrains (creators of PyCharm) knows about this since, at least, two years (please Google it under "PyCharm Console tab completion" or similar, I'm allowed to add just a limited number of links here), and seems to have started working on it, but never finished it.
The discussion states " this is only the initial step to getting full IPython tab completions": https://youtrack.jetbrains.com/issue/PY-9345, but the issue is closed since October 2016.
On StackOverflow there are three questions with similar wording, but not one substantial answer (no, using Ctrl+Space instead of Tab does not solve anything). Again, I can't add more links here.
_2) PyCharm not using ipython_config.py to configure IPython Console:_
https://intellij-support.jetbrains.com/hc/en-us/community/posts/206603035-Which-ipython-config-py-is-used-to-configure-IPython-for-Python-Console-
See the comment by JetBrains at the end of the page.

Elpy to allow pyenv to work on a project basis

I've used Emacs for all my coding projects so far. Soon I will start some python projects for the first time and would love to stick to Emacs for these as well.
I was looking into elpy which seems to provide already alot of desired functionality. The part I was not able to figure out completely is the following. I like to define virtual environments and python version to be used on a project basis. Let's say I start a project A, then I would use pyenv-virtualenv or pyenv-virtualenvwrapper to set it up
pyenv virtualenv 3.4.2 my-virtual-env-3.4.2
by doing this I've linked the python version 3.4.2 to that specific virtualenv / project. I have two questions regarding this in combination with elpy.
Question: This is a rather basic one. All the above can be achieved via the terminal. What is the advantage to emacs to support this? The workflow for me would be: Create project with associated virtualenv and python version. Activate virtualenv and start coding in emacs. If I need to install a package I will run pip in the terminal to ensure virtualenv is captured properly. There must be a reason why it's beneficial to support this in emacs. With my lack of knowledge I just don't see it :)
As pointed out there is for sure a good reason why we want emacs / elpy to support this. My second question would then be
**Question: How can I achieve this in emacs? Lokks like this blog has a solution. I was wondeirng if someone already tried this setup if it is a neat solution with makes sense conceptually. **
Well I strongly guess the goal is to use more features than just syntax highlighting: flycheck/flake8/linting, refactoring, elpy's test runner to use the right python version, install a pip package directly from emacs, stuff like this. You can carry on doing this in the terminal, but once you want an emacs feature, you'll need to set it up.
IĀ found two modes to do that (see wikemacs python page and doubled-checked on melpa): pyenv-mode (in melpa) and pyenv-mode-auto (change the version when there is a .python-version file).

(g)Vim with version control like Eclipse

I was an Eclipse user, now I have to use Vim in my machine.
I used to "compare" a file I edited with a CVS repository to do merges an commit the files, using a context menu and my mouse.
Is this possible in Vim? Opening a vimdiff for a file before commiting, and commit it from vim itself?
And how is that supposed to work?
I'm supposing I would be editing a file. Then, I want to see the modifications. I run vimdiff in gvim, and a new window (or buffer) is opened. I run the modifications, save what is applicable (using vimdiff commands), and commit running another command.
Is this all transparent in vim? Do I have to keep getting out of vim to my terminal, or can all be done inside it?
Do I need to use some plugins, or just really simple functions inside my vimrc?
There is a couple plugins to integrate VCS to vim.
I personnally use vcscommand. It does at least the 2 things you're asking for: comparing from repository using vimdiff and commiting from within vim.
I personally just switch between vim and the terminal.
Usually I'd have several console tabs open at the same time (if you're on windows, Console can do that).
It depends on the VCS used, but you can linked that VCS with vimdiff (see git, for instance)
You could also try and integrate directly Vim into your Eclipse session with eclim.
(should you still be using eclipse. If not, I leave the following for others)
It does support the Eclipse local History.