Skip to content

Instantly share code, notes, and snippets.

@Ningensei848
Created October 22, 2022 08:40
Show Gist options
  • Save Ningensei848/630cb8478b3fccc9d2e6dbd4fc1017c8 to your computer and use it in GitHub Desktop.
Save Ningensei848/630cb8478b3fccc9d2e6dbd4fc1017c8 to your computer and use it in GitHub Desktop.
my python dev-environment
# cf. https://pre-commit.com/
default_language_version:
python: python3.9
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: "v4.3.0"
hooks:
# 容量が大きいファイルがコミットされるのを防ぐ
- id: check-added-large-files
# json, toml, xml, yaml の Syntax をチェックする
- id: check-json
- id: check-toml
- id: check-xml
- id: check-yaml
# 秘密情報を push するのを防ぐ
- id: detect-private-key
- id: detect-aws-credentials
args: [--allow-missing-credentials]
# ファイルの最後が改行で終わっているかどうかを確認する
- id: end-of-file-fixer
# テストファイルの命名規則にあっているか確認
- id: name-tests-test
# 特定ブランチには直接コミットできないようにする(マージされることを前提とする)
# - id: no-commit-to-branch # to protect specific branches from direct checkins.
# args: [--branch, master]
# flake8: style check
- repo: https://github.com/pycqa/flake8
rev: "5.0.4" # Update me! cf. https://github.com/PyCQA/flake8/tags
hooks:
- id: flake8
additional_dependencies: ["Flake8-pyproject"]
# bandit: security check
- repo: https://github.com/PyCQA/bandit
rev: "1.7.4" # Update me! cf. https://github.com/PyCQA/bandit/releases
hooks:
- id: bandit
args: ["-c", "pyproject.toml"]
additional_dependencies: ["bandit[toml]"]
# mypy: static code check
- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v0.982" # Update me! cf. https://github.com/pre-commit/mirrors-mypy/tags
hooks:
- id: mypy
args: ["--ignore-missing-imports", "--config-file", "pyproject.toml"]
# black: code format
- repo: https://github.com/psf/black
rev: "22.10.0" # Update me! cf. https://github.com/psf/black/releases
hooks:
- id: black
# isort: import of libraries sort
- repo: https://github.com/pycqa/isort
rev: "5.10.1" # Update me! cf. https://github.com/PyCQA/isort/releases
hooks:
- id: isort
name: isort (python)
# nbstripout: strip output from Jupyter and IPython notebooks
- repo: https://github.com/kynan/nbstripout
rev: "0.6.1" # Update me! cf. https://github.com/kynan/nbstripout/releases
hooks:
- id: nbstripout
[tool.poetry]
name = "sample"
version = "0.0.0"
description = ""
authors = ["Ningensei848 <k.kubokawa@klis.tsukuba.ac.jp>"]
readme = "README.md"
[tool.poetry.dependencies]
# Note: `python -V` --> 3.9.1 (on Colab @ 2022-10-13)
python = ">=3.9,<3.10"
ipykernel = "^6.16.0"
japanize-matplotlib = "^1.1.3"
[tool.poetry.group.dev]
optional = true
[tool.poetry.group.dev.dependencies]
taskipy = "^1.10.3"
flake8 = "^5.0.4"
bandit = {extras = ["toml"], version = "^1.7.4"}
mypy = "^0.982"
black = {extras = ["jupyter"], version = "^22.8.0"}
isort = {extras = ["pipfile_deprecated_finder", "requirements_deprecated_finder"], version = "^5.10.1"}
Flake8-pyproject = "^1.1.0.post0"
# `pre-commit` は、"TOML で深いネストを表現するのはつらすぎる"ということで pyproject.toml には(今後も永劫)対応しない
# よって、別途設定ファイルを書く必要がある cf. https://github.com/pre-commit/pre-commit/issues/1165
pre-commit = "^2.20.0"
# ipynb の出力をコミット時に削除する pre-commit 向けの hook
nbstripout = "^0.6.1"
pytest = "^7.1.3"
[tool.poetry.group.stub]
optional = true
[tool.poetry.group.stub.dependencies]
pandas-stubs = "^1.5.0.221012"
[tool.taskipy.tasks]
# タスクランナー:実行したいタスクを変数名として宣言
# poetry run task XXXX として実行可能
lint = "flake8 ."
bandit = "bandit -c pyproject.toml -r ."
mypy = "mypy --config-file pyproject.toml"
format = "black ."
isort = "isort ."
[tool.flake8]
# pycodestyle(pep8) エラーコードチートシート - Qiita
# cf. https://qiita.com/KuruwiC/items/8e12704e338e532eb34a
# ignore はデフォルト設定を上書きしてしまうので、それを避けて追記するためには extend-ignore を使う
# black との競合を解消するために E203 も追加
# cf. https://black.readthedocs.io/en/stable/guides/using_black_with_other_tools.html#flake8
extend-ignore = ["E203", "E402", "W501"]
max-line-length = 119
max-complexity = 20
exclude = ".venv"
per-file-ignores = [
'__init__.py:F401',
]
count = true
[tool.bandit]
# cf. https://bandit.readthedocs.io/en/latest/config.html
exclude_dirs = [ ".venv", "tests" ]
tests = ["B201", "B301"]
skips = ["B101", "B601"]
[tool.mypy]
# cf. https://mypy.readthedocs.io/en/stable/config_file.html
python_version = 3.9
# エラー時のメッセージを詳細表示
show_error_context = true
# エラー発生箇所の行数/列数を表示
show_column_numbers = true
# 関数定義の引数/戻り値に型アノテーション必須
disallow_untyped_defs = true
# デフォルト引数に None を取る場合型アノテーションに Optional 必須
no_implicit_optional = true
# 戻り値が Any 型ではない関数の戻り値の型アノテーションが Any のとき警告
warn_return_any = true
# mypy エラーに該当しない箇所に `# type: ignore` コメントが付与されていたら警告
# ※ `# type: ignore` が付与されている箇所は mypy のエラーを無視出来る
warn_unused_ignores = true
# 冗長なキャストに警告
warn_redundant_casts = true
# 設定に書かれた変数に typo があれば警告を出す
warn_unused_configs = true
[[tool.mypy.overrides]]
# Note: small-start ... 型情報がない外部ライブラリについては、一旦無視する
module = [
"matplotlib",
"japanize_matplotlib",
]
# import 先のチェックを行わない (デフォルトだとサードパーティーライブラリまでチェックする)
ignore_missing_imports = true
[tool.black]
line-length = 119
target-version = ["py39"]
include = '\.pyi?$'
# 'singleQuote' を "doubleQuote" に変換しない
skip-string-normalization = true
# フォーマットしないファイル
# 'extend-exclude' excludes files or directories in addition to the defaults
exclude = '''
(
\.eggs
| \.git
| \.hg
| \.mypy_cache
| \.tox
| venv
| \.idea
| \.vscode
| _build
| buck-out
| build
| dist
| migrations
)
'''
[tool.isort]
# blackと共存して使う設定
# https://pycqa.github.io/isort/docs/configuration/black_compatibility.html
profile = "black"
# .gitignoreファイルで指定されているファイルを除外
skip_gitignore = true
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment