LoginSignup
27
21

More than 3 years have passed since last update.

VS Codeで効率的にPythonコーディングするためのsettings.jsonを晒してみる

Last updated at Posted at 2020-05-24

普段Pythonでコーディングすることが多いので、効率的にコーディングできるようにVS Codeで設定をしています。
その設定を紹介しようと思います。

環境

  • MacOS
  • VS Code
  • Python3

効率的にコーディングするための開発用ライブラリ

pipenvで開発環境を構築するのを前提としています

  • black
  • isort
  • mypy
  • flake8
  • pytest

settings.json

設定全文

.vscode/settings.json
{
  "[python]": {
    "editor.tabSize": 4,
    "editor.formatOnSave": true,
    "editor.formatOnPaste": false,
    "editor.formatOnType": false,
    "editor.insertSpaces": true,
    "editor.codeActionsOnSave": {
      "source.organizeImports": true
    },
  },
  "python.pythonPath": "${workspaceFolder}/.venv/bin/python",
  "python.envFile": "${workspaceFolder}/.env",
  "python.linting.enabled": true,
  "python.linting.pylintEnabled": false,
  "python.linting.pycodestyleEnabled": false,
  "python.linting.flake8Enabled": true,
  "python.formatting.provider": "black",
  "python.formatting.blackPath": "${workspaceFolder}/.venv/bin/black",
  "python.sortImports.path": "${workspaceFolder}/.venv/bin/isort",
  "python.linting.mypyEnabled": true,
  "python.linting.mypyPath": "${workspaceFolder}/.venv/bin/mypy",
  "python.linting.mypyArgs": [
    "--config-file", "mypy.ini"
  ],
  "python.testing.unittestEnabled": false,
  "python.testing.nosetestsEnabled": false,
  "python.testing.pytestEnabled": true,
  "python.testing.pytestArgs": [
    "-vv",
    "--show-capture=all",
    "tests"
  ],
  "autoDocstring.docstringFormat": "google",
}

環境変数の読み込み

"python.envFile": "${workspaceFolder}/.env"

環境変数を設定しているファイルをpython.envFileで指定すれば、環境変数を読み込んでくれます

isortによる自動フォーマット

isortでimport文を自動フォーマットするには、isortのPATHを指定する以外に自動フォーマットを有効にする設定が必要です。

"editor.codeActionsOnSave": {
   "source.organizeImports": true
}

Add isort CodeAction (sort imports on save) #1926のプルリクに設定が書いてあります。

docstring

docstringはgoogleの記法を使用しています。
"""をタイプしてEnterを押下すると自動でdocstringを補完してくれます。

"autoDocstring.docstringFormat": "google"

参考

27
21
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
27
21