Python开发工具包

一个现代化的Python项目开发工具包,提供代码质量检查、安全扫描、自动化测试、文档生成等功能。

  • by okadai23
  • Shell
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 daisuke19891023/mcp-pii-detector

使用说明

{{PROJECT_NAME}}

{{PROJECT_DESCRIPTION}}

Features

  • Modern Python project structure with uv and nox
  • Comprehensive code quality tools (Ruff, Black, isort, Pyright)
  • Security scanning (Bandit, pip-audit, Safety)
  • Automated testing with pytest and coverage
  • Documentation with MkDocs Material
  • Pre-commit hooks for code quality
  • Conventional commits with Commitizen
  • GitHub Actions CI/CD pipeline
  • Docker support

Quick Start

Prerequisites

  • Python 3.12+
  • uv (Python package manager)

Installation

# Clone the repository
git clone <your-repo-url>
cd {{PROJECT_NAME_SLUG}}

# Install dependencies
uv pip install -e ".[dev]"

# Install pre-commit hooks
pre-commit install

Development Commands

Command Description
nox -s lint Run linting with Ruff
nox -s format_code Format code with Ruff
nox -s typing Run type checking with Pyright
nox -s test Run tests with coverage
nox -s security Run security checks
nox -s docs Build documentation
nox -s ci Run all CI checks
nox -s all_checks Run all quality checks

Testing

# Run tests with coverage
nox -s test

# Run tests in parallel
pytest -n auto

# Run specific test markers
pytest -m "not slow"

Documentation

# Build documentation
nox -s docs

# Serve documentation locally
mkdocs serve

Docker

# Build Docker image
docker build -t {{PROJECT_NAME_SLUG}} .

# Run Docker container
docker run {{PROJECT_NAME_SLUG}}

Project Structure

{{PROJECT_NAME_SLUG}}/
├── src/                    # Source code
├── tests/                  # Test files
├── docs/                   # Documentation
├── .github/                # GitHub configuration
├── .vscode/                # VS Code settings
├── constraints/            # Dependency constraints
├── pyproject.toml          # Project configuration
├── noxfile.py              # Nox tasks
├── mkdocs.yml              # Documentation configuration
├── Dockerfile              # Docker configuration
└── README.md               # This file

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Run quality checks: nox -s all_checks
  5. Commit using conventional commits: cz commit
  6. Create a pull request

Development Workflow

Code Quality

The project uses several tools to maintain code quality:

  • Ruff: Fast Python linter and formatter
  • Black: Uncompromising code formatter
  • isort: Import sorting
  • Pyright: Type checking
  • Bandit: Security linting
  • pip-audit: Dependency vulnerability scanning
  • Safety: Commercial-grade security scanning

Pre-commit Hooks

Pre-commit hooks automatically run quality checks before each commit:

# Install pre-commit hooks
pre-commit install

# Run all hooks manually
pre-commit run --all-files

Conventional Commits

The project uses conventional commits for versioning:

# Use Commitizen for commits
cz commit

# Bump version
cz bump

License

This project is licensed under the {{LICENSE_TYPE}} License - see the LICENSE file for details.

開発環境セットアップ手順

手動セットアップ

pipx のインストール(入っていない場合)

sudo apt update
sudo apt install pipx
pipx ensurepath

詳細はpipx の公式ドキュメントを参照してください。

uv のインストール

pipx install uv

詳細はuv の公式ドキュメントを参照してください。

対象の Python バージョンのインストール

uv python install [TARGET_PYTHON_VERSION]

仮想環境の作成

uv venv

ライブラリのインストール

uv sync

pre-commit の設定

uv run pre-commit install

ここまではsetup.shで実行できます

nox の実行

uv run nox

仮想環境の有効化

source .venv/bin/activate

仮想環境の終了

deactivate

自動セットアップスクリプト

環境のセットアップを自動化するために、setup.shスクリプトを用意しています。

setup.sh の使用方法

このスクリプトを使用することで、開発環境のセットアップを簡単に行うことができます。

  1. setup.shファイルをプロジェクトのルートディレクトリに配置します。

  2. スクリプトに実行権限を付与します:

    chmod +x setup.sh
    
  3. スクリプトを実行します:

    ./setup.sh
    

注意事項:

  • スクリプトは sudo コマンドを使用するため、実行時にパスワードの入力を求められる場合があります。
  • Python のバージョンインストール行はデフォルトでコメントアウトされています。使用する場合は、スクリプトを編集し、適切なバージョン番号を指定してください。
  • 仮想環境の有効化と終了は、スクリプト実行後に手動で行う必要があります。