0
2

VSCode環境構築備忘録(Python+GithubCopilot+etc)

Last updated at Posted at 2024-08-22

事前準備

  • Python
  • VSCode

VSCode: プラグインのインストール

Extensionsから以下をインストール
image.png

  • Python (ID: ms-python.python)
  • Ruff (ID: charliermarsh.ruff)
  • Mypy Type Checker (ID: ms-python.mypy-type-checker)
  • Remote Development (ID: ms-vscode-remote.vscode-remote-extensionpack)
  • Git History (ID: donjayamanne.githistory)
  • Github Copilot (ID: ms-vscode-remote.vscode-remote-extensionpack)
    • ログインが必要

VSCode: Python周りの設定

検索窓(ctrl+shift+p)から設定(Preferences: Open Settings (UI))を開く
image.png

以下の設定を行う

  • Editor: Format On Save -> True
  • Editor: Default Formatter -> Ruff
    • フィルターに「@lang:python defaultFormatter」と入れることで、Pythonファイルの場合のみ適用することができる
  • Files: insertFinalNewline -> True
  • Mypy-type-checker: Args -> --config=pyproject.toml
  • terminal.integrated.env.windows へ以下の設定を記述する
"terminal.integrated.env.windows": {
    "PSExecutionPolicyPreference": "RemoteSigned"
}

Python: pyproject.toml

プロジェクトフォルダのルートにpyproject.tomlを配置し、以下の設定を記述する。
※プロジェクト方針があるならそれに従う。

pyproject.toml
[tool.ruff]
select = ["F", "B", "I", "E", "W"]
ignore = []
fixable = ["ALL"]
line-length = 119
indent-width = 4
target-version = "py312"

[tool.ruff.lint.mccabe]
max-complexity = 5

[tool.ruff.isort]
force-single-line = true

[tool.ruff.format]
quote-style = "double"
indent-style = "space"
skip-magic-trailing-comma = false
line-ending = "auto"

[tool.mypy]
ignore_missing_imports = true # 未解決インポートを無視する
# Disallow dynamic typing
disallow_any_unimported = true # 未解決の型を禁止
disallow_any_expr = true       # 型のない式を禁止
disallow_any_decorated = true  # 型のないデコレータを禁止
disallow_any_explicit = true   # 型のない明示的な型アノテーションを禁止
disallow_any_generics = true   # 型のないジェネリックを禁止
# Untyped definitions and calls
disallow_untyped_calls = true      # 型定義のない関数の呼び出しを禁止
disallow_untyped_defs = true       # 型定義のない関数の定義を禁止
check_untyped_defs = true          # 型定義のない関数の定義をチェック
disallow_untyped_decorators = true # 型定義のないデコレータを禁止
# Configuring warnings
warn_redundant_casts = true # 冗長なキャストを警告
warn_unused_ignores = true  # 未使用の型アノテーションを警告
warn_return_any = true      # 戻り値の型がAnyであることを警告
warn_unreachable = true     # 到達不能コードを警告
# Miscellaneous strictness flags
strict_equality = true # 厳密な等価性を有効にする

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