1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Pythonプロジェクトの開発環境の統一

Posted at

概要

Pythonプロジェクトを開発する際、スタイルを揃えたい。特に複数人で開発するときにそれぞれ違う書き方をされると開発がしにくい。
そこでプロジェクトでフォーマッタなどを導入して、VSCodeでオートフォーマットしてもらう。

まだまだ発展途上なのでもっと良くしていきたい。

プロジェクトの設定

poetryを使う想定。

開発環境にライブラリをインストール

poetry init
poetry add black flake8 mypy --dev

各種ファイルに設定を記述。
現状は一行の最大長を99文字で揃える設定のみ書いている。

pyproject.toml

...

[tool.black]
line-length = 99

.flake8

[flake8]
max-line-length = 99

VSCodeの設定

Settingsメニューは cmd+, で開ける

flake8 Linting

  • Settingsでpython.linting.flake8を検索
  • Whether to lint Python files using flake8にチェックを入れる

image.png

black auto formatting

  • Settingsでeditor.formatOnSaveを検索
  • Editor: Format On Saveにチェック

image.png

  • Settingsでeditor.formatting.providerを検索
  • blackに設定

image.png

mypy static linting

  • Settingsでpython.linting.mypyEnabledを検索
  • Whether tot lint Python files using mypyにチェック

image.png

VSCodeでVirtual Environmentの設定

  • Settingsでpython.venvPathを検索
  • 自分のvirtualenvのパスを追加

image.png

  • プロジェクトを開発する際は左下のPython環境設定部分をクリックして適切な環境を選択する

image.png

参考Links

1
2
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
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?