Prettier for VS Code ssh connection

Hi everyone,

I use VS Code to write and edit .py scripts on Gadi. I recently found plugin Prettier that automatically formats the scripts and I’d like to be able to use it in the remote sessions, too. May I know if it’s installed or request it to be installed on a remote server? Or should I contact NCI regarding this?

Hi Polina

Black and black-jupyter are common code formatters for Python and are installed in conda/analysis from hh5

i.e.

$ module use /g/data/hh5/public/modules ; module load conda/analysis 
$ black YOUR_FILE.ipynb

I can’t see any easy way to use Prettier on a remote host

1 Like

In VSCode you can also install the ms-python.black-formatter extension, and you can also install it on Gadi.
If you want to use a specific black executable you can do it by inserting its path in the Black-formatter: Path extension settings (on Remote).

For example, to select black from the hh5 ananlysis3 conda environment, you can write the following in the Black-formatter: Path extension settings:

["/g/data/hh5/public/apps/miniconda3/envs/analysis3/bin/python3","-m","black"]

Also, you have to set ms-python.black-formatter as the default editor formatter (at least for Python). You can also add the options to automatically format the code while typing, and on save.
To set these options you can open the VScode settings.json (Shift+Ctrl/Cmd+P and type “open user settings (JSON)”) and add the following lines:

"[python]": {
    "editor.defaultFormatter": "ms-python.black-formatter",
    "editor.formatOnType": true,
    "editor.formatOnSave": true,
  },
2 Likes