Redash を PyCharm Community Edition でデバッグする

OS X での自分用作業メモ。

ターミナルでの作業

virtualenv で Redash 用の環境を作って、必要な Python モジュールを一通りインストールする。

$ pip2.7 install -U virtualenv
$ brew install python --with-berkeley-db4
$ brew unlink python && brew link python
$ brew install mysql
$ brew install freetds@0.91
$ brew link --force freetds@0.91
$ git clone git@github.com:getredash/redash.git
$ cd redash
$ virtualenv .venv
$ source .venv/bin/activate
$ pip install -r requirements.txt
$ pip install -r requirements_dev.txt
$ pip install -r requirements_all_ds.txt

メモ

  • pymssql のインストールが freetds@0.91 に依存している
  • celery を起動する時にエラーが出るのを brew install python --with-berkeley-db4 で解決する

参考

PostgreSQL と Redis の環境構築

docker-compose.development.yml として以下のファイルを作成。

docker-compose.production.yml から serverworkernginx を除いたものに近い。

version: '2'
services:
  redis:
    image: redis:3.0-alpine
    ports:
      - "6379:6379"
    restart: always
  postgres:
    image: postgres:9.5.6-alpine
    ports:
      - "5432:5432"
    volumes:
      - postgres:/var/lib/postgresql/data
    restart: always
volumes:
  postgres:
    driver: local

その後、以下のコマンドでコンテナを起動。

$ docker-compose -f docker-compose.developmens.yml up

Redash の設定

.env を以下のように作成する。PostgreSQL 、 Redash ともに Docker のコンテナを使うようにする。

export REDASH_LOG_LEVEL=INFO
export REDASH_REDIS_URL=redis://localhost:6379/0
export REDASH_DATABASE_URL=postgresql://postgres@localhost/postgres

次に、必要なテーブルを作成する。

$ ./bin/run ./manage.py database create_tables

次に、JavaScriptをビルドする。

$ npm install
$ npm run build

PyCharm での作業

Python Interpreter

virtualenv で作った環境の python を使うように設定する。

f:id:ariarijp:20180218212206p:plain

server の実行時設定

f:id:ariarijp:20180218212301p:plain

worker の実行時設定

f:id:ariarijp:20180218212310p:plain

serverworker環境変数

.env で設定している値を環境変数として設定しておく。

f:id:ariarijp:20180218212316p:plain

動作確認

server , workerDebug で実行すればブレークポイントを設定できる。

f:id:ariarijp:20180218213413p:plain

便利。

この記事では PyCharm Community Edition を使ったけれど、 Professional Edition であれば Docker 上の Pythonデバッグできるようなので、 Redash の場合はその方がよさそう。

PyCharm を雰囲気で使っているので、もっと便利な使い方を知りたい。