Skip to content

Pycharm

PyCharm

Current situation

There are multiple ways to develop on a remote server using PyCharm

  1. VNC approach

    • PyCharm runs locally on the server using a "virtual screen"
    • Your laptop interacts with a VNC server to get the GUI locally
    • Pros:
    • Everything works
    • You can run anything like you are local on the server, since you are in practice just using a virtual screen
    • Cons:
    • Without enough bandwidth it's slow and not snappy enough
  2. X11 approach

    • Same as VNC, but instead of sending bitmaps through VNC, a "compressed" version of the GUI is sent to the local computer directly
    • Pros:
    • Maybe faster than VNC
    • PyCharm window is like a native window on your laptop
    • Cons:
    • X11 is old crap developed long time again and not really supported any more
    • One needs to tunnel X11 traffic, set things up, and so on
  3. PyCharm Gateway

    • New client-server architecture for PyCharm
    • A "headless" PyCharm runs on the server
    • A GUI client PyCharm runs on your laptop
    • Pros
    • It's as fast as possible, probably as fast as running locally
    • Cons
    • Need a PyCharm pro license (not a problem, we have money)
    • It's not super polished: kind of beta, but it will get better and better
  4. PyCharm Remote Set-up

    • This is described below in PyCharm - Advanced tip and tricks
    • Edit locally and then PyCharm moves the files back and forth
    • Pros
    • Only requires ssh
    • Cons
    • You can't run / debug remotely

Current situation

  • Approach 1) seems to require lots of memory and CPU and it's not really fast.

  • Approach 2) works but it's a pain to set-up and slow.

  • We want to try with 3)

  • TODO(gp): @Juraj pls a short tutorial on how to install
  • TODO(gp): @Juraj understand if it works, if it's fast, and if it requires less memory

How to run our cmamp container directly from PyCharm

How to review a PR inside Pycharm

  • CTRL + SHIFT + A -> View Pull Request

How to edit remote code

  • You need to use a certain local directory (e.g., /Users/saggese/src/commodity_research1) and a remote directory (e.g., /wd/saggese/src/commodity_research1)

  • They need to be synced at the same git branch (e.g., master or AmpTask1112_Audit_amp_Docker_system_03)

  • Set-up Deployment

  • The deployment options are

  • You can see what file is changed in the file transfer window:

pycharm

  • Develop on one node, sync, run on the server
  • Run local application with venv

  • Database

  • Run application inside Docker

  • Run application remotely inside Docker

General ssh config

  • File | Settings | Tools | SSH Configurations
  • Once setup, ssh config can be used for all tools in PyCharm.

  • Remote Interpreter
  • DataGrip
  • Deployment
  • Etc.

DB connection via ssh

Note: PyCharm Professional DataGrip is used as an example. There are numerous open source alternatives such as Beaver. Config below should apply to them also.

  • To add a new data source in DataGrip, go to the database section in the lower left corner.
  • Then pick your desired data source from the dropdown in the upper right corner.

  • You will be presented with a dummy config that needs to be replaced with proper data as shown below.

  • Before that is done, be sure that proper ssh info is added in SSH/SSL section.

Deployment with remote repository (through sync)

Note: Before setting up deployment, pull the cmamp repo on EC2 instance and use the same name as on your local machine (example: cmamp1). Always try to keep both repos in sync via git. For more subtle and simpler changes use File | Reload All From Disk . This will upload changes to the remote repo.

  • Tools | Deployment | Configuration
  • Tools | Deployment | Options

    • Uncheck "Skip external changes" and check "Delete remote files"
  • Tools | Deployment | Automatic Upload

  • Check it

  • Tools | Deployment | Browse Remote Host

PUDB - remote debugging - ToDo

How to run tests inside a container

Installing PyCharm Professional

Windows

  1. Download the installer using this link
  2. Run the installer and follow the wizard steps.
  3. To run PyCharm, find it in the Windows Start menu or use the desktop shortcut.

macOS

There are separate disk images for Intel and Apple Silicon processors.

  1. Download the image, based on your processor using this link

  2. Mount the image and drag the PyCharm app to the Applications folder.

  3. Run the PyCharm app from the Applications directory, Launchpad, or Spotlight.

Linux

**Using tar archives **

  1. Download the tar archive using this link

  2. Unpack the pycharm-*.tar.gz file to a different folder, if your current Download folder doesn't support file execution: ```

    tar xzf pycharm-*.tar.gz -C `` ```

The recommended installation location according to the filesystem hierarchy standard (FHS) is /opt. To install PyCharm into this directory, enter the following command:

> sudo tar xzf pycharm-\*.tar.gz -C /opt/
  1. Switch to the bin subdirectory: ```

    cd /pycharm-*/bin # E.g., cd /opt/pycharm-*/bin ```

  2. Run pycharm.sh from the bin subdirectory ```

    sh pycharm.sh ```

Using snap packages

  1. For Ubuntu 16.04 and later, you can use snap packages to install PyCharm. ```

    sudo snap install pycharm-professional --classic # or sudo snap install pycharm-community --classic ```

  2. Run in the Terminalu ```

    pycharm-professional # or pycharm-community # or pycharm-educational ```

Connecting via PyCharm gateway (SSH)

The first thing you need to do is sign up for a free trial license or use it if it already have

Then make sure you have a VPN connection to our VPC

  1. Click on Connect via SSH
  2. Into Username: write <> Example: richard
  3. Into Host: write <> Example: 172.30.2.136
  4. Mark the Specify private key check box and locate the private key from the zip which was sent in the onboarding process. Example: crypto.pub
  5. Leave Port: 22 as it is.
  6. Click on Check Connection and Continue.
  7. Select IDE version: PyCharm Py 213.6777.x
  8. Locate your directory. Example: /data/richard
  9. Click on Download and Start IDE.

Connecting via VNC

  • Make sure you have a VPN connection.

Installing VNC

Sysadmin has sent you:

  • os_password.txt
  • Your username $USER
  • A key crypto.pub that looks like: -----BEGIN OPENSSH PRIVATE KEY----- b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABlwAAAAdzc2gtcn NhAAAAAwEAAQAAAYEA0IQsLy1lL3bhPT+43sht2/m9tqZm8sEQrXMAVtfm4ji/LXMr7094 ... hakqVTlQ2sr0YTAAAAHnNhZ2dlc2VAZ3BtYWMuZmlvcy1yb3V0ZXIuaG9tZQECAwQ= -----END OPENSSH PRIVATE KEY-----

Let's say you are connected via VNC.

  1. Login into the OS.
  2. Run pycharm.sh using terminal (should be there) ```

    bash /opt/pycharm-community-2021.2.3/bin/pycharm.sh ```

Configuration

Reflow

  • Set the reflow to reindent