cloud-run-job-base/readme/python_init.md
2025-12-04 12:46:35 +09:00

82 lines
1.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Python Project
## 仮想環境を構築する
### venvで構築する
```sh
python3 -m venv .venv
# Linux
source .venv/bin/activate
# Windows
# .venv/Scripts/activate
pip install -r requirements.txt
# For Develop(Tests,Docs)
pip install -r requirements-dev.txt
```
### uvで構築する
プロジェクトを生成する場合
```bash
uv init <ProjectName>
# --pythonまたは-pにバージョンを指定できます
# uv init <ProjectName> -p 3.10とすると">=3.10,<3.11"となる
```
同期する場合
```sh
uv sync
```
## Linter
### ruffライブラリの場合
RuffFlake8 のルールを多数サポートしています。
ruff.tomlで設定できます
```toml
select = ["E", "W"]
line-length = 88
```
| 分類 | コード | 内容 |
| ---- | ------ | ----------------------------------- |
| W | W291 | 末尾スペースtrailing whitespace |
| | W293 | ファイル末尾の空行の空白 |
| E | E303 | 空行が多すぎる |
| | E501 | 行が長すぎる |
リンターを実行する場合
```sh
# プロジェクト全体のPythonファイルを確認する
ruff check .
# ソースコードのみ実行する場合
ruff check src
```
**レポートを生成する場合**
シンプルなレポートとしては`generate_linter.sh`を実行してください
```sh
sh scripts/generate_linter.sh
```
形式を指定して出力する方法
```sh
ruff check . --output-format json --output-file ruff-report.json
```
`--output-file``github`など様々な形式が指定できます
コメントを生成する方法を検討が必要