Code development
Editors
Info
Emacs has a unique shortcuts system, but it is very effective. To exit use control+x, control+c. Emacs has some features that other editors don't have: macros. It has tons of extensions.
On a remote machine usually you have a simple text editor. For example on proof you can run Emacs:
emacs -nw myfile.txt # (1)!
-nw
is the option to avoid opening the graphics interface
Info
To exit vim press :q
enter. One popular editor is Neovim
You can try vim
vi myfile.txt
Redirect graphic
It is quite discouraged to redirect the graphic of a remote machine to your laptop using ssh -Y
since the experience is quite bad. There are better ways to use edit remote files, see at the end of this chapter.
Version control
You can create a git repository from the GitLab interface at CERN. To be able to interact with that with the git
command you need to be authenticated. This can be easily done with ssh keys: go into the setting and follow the tutorial to generate the keys and upload them into your GitLab settings. Remember you have to repeat this for each machine you use.
Some resources:
- official guide for git
- official gitlab guide
- Tutorial oriented to ATLAS core software
After having created the git repository clone it on your laptop or on the remote machine with git clone url
where the url
is the one from the GitLab page (under the clone button, since you have an ssh-key use the SSH link). When you want to add files add them to the stage with git add myfile
, commit them with a message git commit -m "my message"
and push to origin
(the default remote you have created when cloning the repository) with git push
. Keep your local copy updated pulling coming from other people with git pull
. Become confident with Git and the GitLab interface (add collaborators as members, ...)
Warning
Don't put large binaries (e.g. figures, ROOT files) into a GitLab repository, in particular if they change frequently. You will waste a lot of space and cloning your repository will be very expensive. See the next chapter about the storage for where to store large files.
Tip
To respect the above warning automatically, create into your main git repo folder a file called .gitignore
and fill it with the pattern you want to be ignored, for example, add a line *.root
. Then add and commit it: from then on git
will ignore any files with this extension. You can find examples of gitignore https://github.com/github/gitignore.
Tip
Choose a proper name for your repository. Remember that the name you choose is usually the name of the directory other people will get when cloning your repository. Don't use names such as "Tesi", "Magistrale", ...
Remote edit
SSHFS
You can mount a remote folder into your computer, for example, on your laptop:
mkdir ~/proof-remote # create an empty dir
sshfs username@proof.mi.infn.it: ~/proof-remote
if you edit the files in the proof-remote
directory you are changing the files on the remote machine. The good thing is that you can open the files on your laptop with your favourite editor. You can also explore the remote filesystem using your favourite file manager installed on your laptop, open images, ...
The cons of this problem is that if your connection is not stable it can create problems for your system. In case of problems you can try to unmount the folder:
fusermount -u ~/proof-remote
Tip
If the last command complains since some processes are using that folder you can find these processes with lsof | grep proof-remote
Or in the worst-case scenario, you can kill the ssh process on your laptop.
Visual Studio Code remote
Visual Studio Code is a very popular editor. You can install the Remote development extensions to edit from your computer to a remote machine via SSH with SSH remote. Then click on the bottom left arrow and follow the instructions. The same extension can do much more for example you can develop inside a docker container.
You can have a look at this guide oriented to the ATLAS software.
VS code on old remote machines
VS code require the remote machine to have use a recent version of the operating system. For example centos7 (presently used on proof) is not supported. In this case you will get the error "The remote host does not meet the prerequisites for running VS Code Server". You can use the RemoteCommand
as explained in here. Assuming you have create a new host in ~/.ssh/config
called el9-proof-10
you can run open vs code and connect with SSH Remote to this new machine.
There are two extra complications.
The first is easy: in VS code You have to turn on the option remote.SSH.enableRemoteCommand
.
The second is related to the fact that vscode needs to download the server and other files (e.g. extensions) on the remote machine and the fact that proof-10
and el9-proof10
(very probably) share the same filesystem, in particular the home directory where these files are saved by default. To avoid this, in vscode setting, change the section remote.SSH.serverInstallPath
. Here create a new row with the same name of the remote host (e.g. item=el9-proof-10
) and set a custom path as value (e.g. /cnfs/home_fs/username/.vscode-server/el9-proof-10
). This way you can have multiple remote machines with the same home directory and different vscode server installations.