[Python] Project Setup
Poetry
可以使用 Poetry 來管理 Python 專案的相依套件,在這之前需要先安裝 python 的環境,我使用的是 pyenv-win
來管理 python 的版本。
- 安裝
pyenv-win
- 安裝 python 版本
pyenv install -l
pyenv install <python version>
pyenv global <python version>
python --version
- 安裝 Poetry
pip install poetry
poetry about
poetry init
# OR
poetry new <your project name>
- 安裝套件
poetry add <package name>
poetry add <package name> --dev
poetry remove <package name>
- 進入虛擬環境
poetry shell
flake8
poetry add flake8 --dev
創建一個 .flake8
檔案
.flake8
[flake8]
max-line-length = 88
extend-ignore = E203, W503
exclude = .git, __pycache__, build, dist
black
poetry add black --dev
pyproject.toml
[tool.black]
line-length = 88
target-version = ['py310']
isort
poetry add isort --dev
pyproject.toml
[tool.isort]
profile = "black"
mypy
poetry add mypy --dev
Git
.gitattributes
*.py text eol=lf
.gitignore
可以參考 GitHub
執行
poetry run python src/main.py
poetry run black src
poetry run isort src
poetry run mypy src
poetry run flake8 src