Home Artificial Intelligence The Perfect Text Editor for Jupyter: A Complete Python IDE Conquer of Completion Installation Summary In regards to the Writer

The Perfect Text Editor for Jupyter: A Complete Python IDE Conquer of Completion Installation Summary In regards to the Writer

2
The Perfect Text Editor for Jupyter: A Complete Python IDE
Conquer of Completion
Installation
Summary
In regards to the Writer

From syntax highlighting to code completion, an entire Python IDE inside Jupyter

Photo by Max Duzij on Unsplash

This text is the fourth a part of a series. Try the complete series: Part I, Part II, Part III.

Over the past few days, we’ve been constructing an entire Python IDE inside Jupyter. In this text, we’ll add the ultimate touches and package every part in a Docker image to create a conveyable working environment for data scientists and Machine Learning engineers.

Jupyter shouldn’t be exactly an IDE. It’s not even an IPython UI, as many might imagine. I’d argue that Jupyter is a development platform, and you’ll be able to create your personal workspace the best way you prefer it. Because it features a terminal emulator, you’ll be able to do anything you might think. Thus, we’ll use it to create an entire, feature-packed Python IDE.

Thus, in previous articles, we installed Neovim and configured it to act and look much like the most well-liked text editor lately: Visual Studio Code. In this text, we’ll install one tool to beat all: code completion, code formatting, git integration, spell checking, and lining. Let’s begin!

Learning Rate is a newsletter for individuals who are interested by the world of ML and MLOps. If you should learn more about topics like this subscribe here. You’ll hear from me on the last Sunday of each month with updates and thoughts on the most recent MLOps news and articles!

Many tools promise to make a developer’s life easier with regards to Vim/Neovim, but my preference is Conquer of Completion.

Conquer of Completion (CoC) is a preferred plugin for Vim and Neovim that gives a robust autocompletion engine. Listed here are a number of key things to learn about CoC:

  • CoC supports multiple languages: it may well provide autocompletion suggestions for various programming languages, including Python, JavaScript, C, Go, and lots of others. It uses language servers to offer intelligent recommendations based in your code context.
  • CoC is extremely configurable: it allows users to customize the autocompletion engine to suit their preferences in a VS Code-like way. Users can arrange custom mappings for triggering completion, adjust the priority of completion sources, and more.
  • CoC has a big user community: it’s a preferred plugin with a big user community, which implies many resources can be found for troubleshooting and customization. The plugin can be actively maintained and updated. Furthermore, the community provides several great extensions we’ll use.

Overall, Conquer of Completion is a robust plugin that may significantly enhance your autocompletion experience in Vim or Neovim, mainly in case you work with multiple programming languages.

CoC requires some setup. You’ll have to install and configure some additional components, including NodeJS and the npm package manager. Depending in your case, you might also have to install a language server for your chosen programming language.

In our case, let’s first install NodeJS.

NodeJS Installation

NodeJS and npm are hard requirements to put in the CoC plugin for Neovim and enable auto-completion for a lot of programming languages.

To put in the 2 packages execute the next commands:

  1. Install the PPA to get access to its packages:
curl -sL https://deb.nodesource.com/setup_18.x -o nodesource_setup.sh
sudo bash nodesource_setup.sh

2. Install Node.js:

sudo apt install nodejs

3. Confirm:

node -v

If you happen to get something like v18.15.0 (the most recent version on the time of writing this text) you’re good to go. But even when you will have one other version installed, you must have the opportunity to proceed.

Install CoC

Installing the CoC plugin is so simple as some other plugin. Just place the next line in your init.vim configuration file:

Plug 'neoclide/coc.nvim', {'branch': 'release'} " Auto complete Python

Restart the editor and run the :PlugInstall Vim command. vim-plug, the plugin manager we’re using will install CoC for you. To finish the installation process, restart the editor again.

To see the installation strategy of a plugin in Neovim intimately, refer back to the second blog of this series.

We’re able to install the extensions we’d like to show our editor right into a full-fledged IDE. Run the :CocInstall coc-pyright Vim command to put in support for Python. After ending the installation, quit every window of your editor and open a Python file like this:

nvim test.py

Autocomplete ought to be enabled; nonetheless, it’s not very practical. So, let’s configure CoC. Add the next lines in your init.vim configuration file:

" CoC customization

" Applying code actions to the chosen code block
vmap a (coc-codeaction-selected)
xmap a (coc-codeaction-selected)

" Format motion on
vmap f (coc-format-selected)
xmap f (coc-format-selected)

" GoTo code navigation
nmap gd (coc-definition)
nmap gv :vsp(coc-definition)L
nmap gy (coc-type-definition)
nmap gi (coc-implementation)
nmap gr (coc-references)

" Symbol renaming
nmap rn (coc-rename)

" Refactor
nmap re (coc-codeaction-refactor)
xmap r (coc-codeaction-refactor-selected)
nmap r (coc-codeaction-refactor-selected)

" Confirm selection by pressing Tab
inoremap pumvisible() ? coc#_select_confirm() : ""

" Open autocomplete menu by pressing Ctrl + Space
inoremap coc#refresh()

" Open documentation by pressing K
nnoremap K :call ShowDocumentation()

function! ShowDocumentation()
if CocAction('hasProvider', 'hover')
call CocActionAsync('doHover')
else
call feedkeys('K', 'in')
endif
endfunction

I left a comment for every line so you’ll be able to understand what it does. Now CoC is configured, and you should utilize these key bindings to get probably the most out of it.

Nevertheless, things don’t end here. As we said, CoC has several extensions (like coc-pyright) you could install. A few of them are:

  • coc-git
  • coc-docker
  • coc-yaml
  • coc-json
  • coc-prettier
  • coc-pairs
  • coc-spell-checker

To put in any of them, just run the :CocInstall command and supply the name of the extension. For a whole list of extensions, visit the coc-extensions page: https://github.com/topics/coc-extensions

Finally, you’ll be able to configure CoC very similar to you do with VS Code. Run the :CocConfig command and the coc-settings.json file will pop up. I actually have the next settings set there:

{
"python.venvPath": "/home/dimpo/.pyenv/versions/",
"python.linting.flake8Enabled": true,
"python.formatting.provider": "autopep8",
"pyright.inlayHints.variableTypes": false,
"pyright.inlayHints.functionReturnTypes": false,
"git.addGBlameToVirtualText": true,
}

Each row is self-explanatory, but when you should discover what exactly you’ll be able to configure, consult with the documentation of every CoC extension.

As usual, save your work using the docker commit command (consult with previous articles on this series in case you don’t know what this implies). Yow will discover my image in DockerHub.

On this series of articles, we built an entire Python IDE inside a JupyterLab environment. We began with a straightforward Neovim installation, which we configured to act and appear like the most well-liked text editor today, VS Code.

This text concludes this story, but when you should see more things, like how one can use a debugger or configure a selected plugin further, please leave a comment, and I’ll do my best! Till then, comfortable coding.

My name is Dimitris Poulopoulos, and I’m a machine learning engineer working for Arrikto. I actually have designed and implemented AI and software solutions for major clients resembling the European Commission, Eurostat, IMF, the European Central Bank, OECD, and IKEA.

If you happen to are considering reading more posts about Machine Learning, Deep Learning, Data Science, and DataOps, follow me on Medium, LinkedIn, or @james2pl on Twitter.

Opinions expressed are solely my very own and don’t express the views or opinions of my employer.

2 COMMENTS

LEAVE A REPLY

Please enter your comment!
Please enter your name here