frappe-pre-commit


Namefrappe-pre-commit JSON
Version 1.0.3 PyPI version JSON
download
home_pageNone
SummaryPre-commit hooks for Frappe Framework coding standards
upload_time2025-09-02 06:22:19
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseNone
keywords frappe erpnext pre-commit hooks code-quality
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # ๐ŸŽฏ Frappe Pre-commit

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Python 3.8+](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/)
[![Pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit)

**Comprehensive pre-commit hooks for Frappe Framework projects** to enforce coding standards, security practices, and best practices automatically.

## โœจ Features

- ๐Ÿ›ก๏ธ **SQL Injection Prevention** - Detect and prevent SQL injection vulnerabilities
- ๐Ÿ“ **Coding Standards** - Enforce Frappe-specific coding conventions and best practices
- ๐Ÿ“ **DocType Naming** - Validate DocType and field naming conventions
- โšก **Fast Execution** - Lightweight checks with minimal dependencies
- ๐ŸŽฏ **Customizable** - Pick and choose hooks based on your project needs

## ๐Ÿš€ Quick Start

### System Requirements

- **Python**: 3.8 or higher
- **pip**: Latest version
- **pre-commit**: Will be installed automatically
- **Git**: For version control

### Python Path Setup

If you encounter "Executable `python` not found" errors, ensure Python is properly configured:

```bash
# Check Python installation
python3 --version

# Create python symlink if needed (Linux/macOS)
sudo ln -s /usr/bin/python3 /usr/bin/python

# Or add alias to your shell profile (~/.bashrc, ~/.zshrc)
echo 'alias python=python3' >> ~/.bashrc
source ~/.bashrc
```

### For New Frappe Projects

```bash
# 1. Initialize new Frappe app
bench new-app my_custom_app
cd apps/my_custom_app

# 2. Create .pre-commit-config.yaml
curl -o .pre-commit-config.yaml https://raw.githubusercontent.com/dhwani-ris/frappe-pre-commit/main/examples/.pre-commit-config.yaml

# 3. Install and run
pip install pre-commit
pre-commit install
pre-commit run --all-files
```

### For Existing Frappe Projects

```bash
# 1. Navigate to your app directory
cd apps/your_app

# 2. Add .pre-commit-config.yaml (see configuration below)
# 3. Install pre-commit
pip install pre-commit
pre-commit install

# 4. Run on existing code
pre-commit run --all-files
```

## ๐Ÿ“‹ Available Hooks

| Hook ID | Description | Files | Dependencies |
|---------|-------------|-------|--------------|
| `frappe-coding-standards` | General coding standards and best practices | `*.py` | None |
| `frappe-sql-security` | SQL injection and security checks | `*.py` | None |
| `frappe-doctype-naming` | DocType and field naming conventions | `*.py`, `*.js`, `*.json` | `pyyaml` |

## โš™๏ธ Configuration

### Basic Configuration

Create `.pre-commit-config.yaml` in your project root:

```yaml
repos:
  # Frappe-specific hooks
  - repo: https://github.com/dhwani-ris/frappe-pre-commit
    rev: v1.0.0  # Use latest tag
    hooks:
      - id: frappe-translation-check
      - id: frappe-sql-security
      - id: frappe-coding-standards

  # Code formatting (recommended)
  - repo: https://github.com/astral-sh/ruff-pre-commit
    rev: v0.8.1
    hooks:
      - id: ruff
        args: ["--select=I", "--fix"]  # Import sorting
      - id: ruff-format  # Code formatting

  # Additional quality checks
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v4.5.0
    hooks:
      - id: trailing-whitespace
      - id: end-of-file-fixer
      - id: check-yaml
      - id: check-json
```

### Complete Configuration

```yaml
repos:
  # Python formatting and linting
  - repo: https://github.com/astral-sh/ruff-pre-commit
    rev: v0.8.1
    hooks:
      - id: ruff
        name: "Ruff import sorter"
        args: ["--select=I", "--fix"]
      - id: ruff
        name: "Ruff linter"
        args: ["--extend-ignore=E501"]
      - id: ruff-format
        name: "Ruff formatter"

  # JavaScript/CSS/JSON formatting
  - repo: https://github.com/pre-commit/mirrors-prettier
    rev: v4.0.0-alpha.8
    hooks:
      - id: prettier
        files: \.(js|jsx|ts|tsx|css|scss|json|md|yml|yaml)$
        exclude: |
          (?x)^(
              .*\.min\.(js|css)$|
              node_modules/.*|
              .*/static/.*
          )$

  # Basic file checks
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v4.5.0
    hooks:
      - id: trailing-whitespace
        exclude: \.(md|rst)$
      - id: end-of-file-fixer
      - id: check-yaml
      - id: check-json
      - id: check-merge-conflict
      - id: debug-statements

  # Frappe-specific coding standards
  - repo: https://github.com/dhwani-ris/frappe-pre-commit
    rev: v1.0.0
    hooks:
      - id: frappe-coding-standards 

# Exclude patterns
exclude: |
  (?x)^(
      .*/migrations/.*|
      .*/patches/.*|
      .*\.min\.(js|css)$|
      node_modules/.*|
      __pycache__/.*
  )$
```

### Selective Hook Usage

```yaml
# Use only specific hooks you need
repos:
  - repo: https://github.com/dhwani-ris/frappe-pre-commit
    rev: v1.0.0
    hooks:
      - id: frappe-sql-security     # Only SQL security checks
      - id: frappe-translation-check # Only translation checks
```

## ๐Ÿ” What Gets Checked

### ๐Ÿ›ก๏ธ SQL Security Checks

**Detects:**
- SQL injection vulnerabilities using `.format()` or f-strings
- String concatenation in SQL queries
- Unencrypted storage of sensitive data (passwords, API keys)

```python
# โŒ Will be flagged
frappe.db.sql("SELECT * FROM tabUser WHERE name = '{}'".format(user_name))
frappe.db.set_value("User", user, "password", plain_password)

# โœ… Correct approach
frappe.db.sql("SELECT * FROM tabUser WHERE name = %s", user_name)
frappe.db.set_value("User", user, "password", frappe.utils.password.encrypt(plain_password))
```


### ๐Ÿ“ Coding Standards

**Enforces:**
- Function length (โ‰ค20 lines recommended)
- Naming conventions (snake_case for functions, PascalCase for classes)
- Ignore setUp and tearDown naming checks in test files, since they follow testing conventions 
- Import organization
- Complexity limits (max nesting depth)

### ๐Ÿ“ DocType Naming Conventions

**Validates:**
- DocType names: Title Case with spaces (`"Sales Order"`)
- Field names: snake_case (`"customer_name"`)
- Field labels: Title Case (`"Customer Name"`)

## ๐Ÿ—๏ธ Integration Examples

### Integration with Bench

```bash
# For bench-managed projects
cd frappe-bench/apps/your_app

# Add pre-commit config
curl -o .pre-commit-config.yaml https://raw.githubusercontent.com/dhwani-ris/frappe-pre-commit/main/examples/.pre-commit-config.yaml

# Install globally in bench environment
~/frappe-bench/env/bin/pip install pre-commit
~/frappe-bench/env/bin/pre-commit install
```

### Integration with GitHub Actions

Create `.github/workflows/code-quality.yml`:

```yaml
name: Code Quality

on: [push, pull_request]

jobs:
  pre-commit:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v4
        with:
          python-version: '3.10'
      - name: Install pre-commit
        run: pip install pre-commit
      - name: Run pre-commit
        run: pre-commit run --all-files
```

### Integration with VS Code

Add to `.vscode/settings.json`:

```json
{
  "python.linting.enabled": true,
  "python.linting.flake8Enabled": true,
  "python.formatting.provider": "black",
  "editor.formatOnSave": true,
  "python.sortImports.args": ["--profile", "black"],
  "[python]": {
    "editor.codeActionsOnSave": {
      "source.organizeImports": true
    }
  }
}
```

## ๐Ÿงช Development and Testing

### Setting Up Development Environment

```bash
# Clone the repository
git clone https://github.com/dhwani-ris/frappe-pre-commit.git
cd frappe-pre-commit

# Create virtual environment
python -m venv dev_env
source dev_env/bin/activate  # On Windows: dev_env\Scripts\activate

# Install development dependencies
pip install -r requirements-dev.txt
pip install pre-commit

# Install pre-commit hooks for this repository
pre-commit install
```

### Running Tests

```bash
# Test individual scripts
python scripts/check_coding_standards.py test_files/sample.py
python scripts/check_sql_security.py test_files/sample.py
python scripts/check_translations.py test_files/sample.py

# Test all hooks
python test_scripts/test_all_hooks.py

# Test with pre-commit
pre-commit run --all-files
```

### Creating Test Files

```bash
# Create test files with issues
mkdir test_project && cd test_project

# Create Python file with intentional issues
cat > bad_example.py << 'EOF'
import frappe

def very_long_function_that_violates_standards():
    frappe.msgprint("Missing translation wrapper")
    result = frappe.db.sql("SELECT * FROM tabUser WHERE name = '{}'".format("test"))
    return result
EOF

# Test your hooks
cd ../
python scripts/check_translations.py test_project/bad_example.py
python scripts/check_sql_security.py test_project/bad_example.py
```

### Testing with Different Frappe Projects

```bash
# Test with ERPNext
cd path/to/erpnext
git clone https://github.com/dhwani-ris/frappe-pre-commit.git .pre-commit-hooks
cp .pre-commit-hooks/examples/.pre-commit-config.yaml .
pre-commit install
pre-commit run --all-files

# Test with custom app
cd path/to/your_custom_app
# Same process as above
```

### Contributing

1. **Fork the repository**
2. **Create feature branch**: `git checkout -b feature/new-check`
3. **Add your hook script** in `scripts/`
4. **Update `.pre-commit-hooks.yaml`**
5. **Add tests** in `test_scripts/`
6. **Update documentation**
7. **Submit pull request**

## ๐Ÿ“š Examples

### Example 1: Basic Frappe App Setup

```bash
# Create new app
cd frappe-bench
bench new-app inventory_management
cd apps/inventory_management

# Add pre-commit
cat > .pre-commit-config.yaml << 'EOF'
repos:
  - repo: https://github.com/dhwani-ris/frappe-pre-commit
    rev: v1.0.0
    hooks:
      - id: frappe-quick-check
EOF

# Install and test
pip install pre-commit
pre-commit install
pre-commit run --all-files
```

### Example 2: ERPNext Customization

```bash
# For ERPNext customizations
cd frappe-bench/apps/erpnext

# Use comprehensive config
curl -o .pre-commit-config.yaml https://raw.githubusercontent.com/dhwani-ris/frappe-pre-commit/main/examples/erpnext-config.yaml

pre-commit install
pre-commit run --all-files
```

### Example 3: CI/CD Integration

```yaml
# .github/workflows/quality-check.yml
name: Quality Check

on:
  pull_request:
    branches: [main, develop]

jobs:
  code-quality:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      
      - name: Set up Python
        uses: actions/setup-python@v4
        with:
          python-version: '3.10'
      
      - name: Install dependencies
        run: |
          pip install pre-commit
          pip install -r requirements.txt
      
      - name: Run pre-commit
        run: pre-commit run --all-files
      
      - name: Comment PR
        if: failure()
        uses: actions/github-script@v6
        with:
          script: |
            github.rest.issues.createComment({
              issue_number: context.issue.number,
              owner: context.repo.owner,
              repo: context.repo.repo,
              body: 'โŒ Code quality checks failed. Please run `pre-commit run --all-files` locally and fix the issues.'
            })
```

## ๐Ÿ”ง Troubleshooting

### Common Issues

**Pre-commit hooks not running:**
```bash
pre-commit uninstall
pre-commit install
pre-commit run --all-files
```

**Python executable not found error:**
```bash
# Error: Executable `python` not found
# Solution: Create a python symlink or alias

# Option 1: Create symlink (Linux/macOS)
sudo ln -s /usr/bin/python3 /usr/bin/python

# Option 2: Create alias (add to ~/.bashrc or ~/.zshrc)
alias python=python3

# Option 3: Use python3 explicitly in PATH
export PATH="/usr/bin:$PATH"

# Option 4: Install python-is-python3 package (Ubuntu/Debian)
sudo apt install python-is-python3

# After fixing, reinstall pre-commit hooks
pre-commit uninstall
pre-commit install
```

**Hooks failing on large files:**
```bash
# Skip hooks for specific commit
git commit -m "Large file update" --no-verify

# Or exclude large files in config
# Add to .pre-commit-config.yaml:
exclude: |
  (?x)^(
      large_files/.*|
      .*\.min\.js$
  )$
```

**Import errors in scripts:**
```bash
# Make sure Python can find the scripts
export PYTHONPATH="${PYTHONPATH}:$(pwd)"
```

**Package installation issues:**
```bash
# If frappe-pre-commit package fails to install automatically
pip install frappe-pre-commit

# Clear pre-commit cache and reinstall
pre-commit clean
pre-commit install
```

### Performance Tips

```bash
# Cache pre-commit environments
export PRE_COMMIT_HOME=~/.cache/pre-commit

# Run only on changed files
pre-commit run

# Skip slow hooks during development
PRE_COMMIT_SKIP=frappe-all-checks git commit -m "Quick fix"
```

## ๐Ÿค Contributing

We welcome contributions! 

### Quick Contribution Steps

1. Fork the repository
2. Clone your fork: `git clone https://github.com/yourusername/frappe-pre-commit.git`
3. Create branch: `git checkout -b feature/improvement`
4. Make changes and test thoroughly
5. Submit pull request

### For Developers

If you want to contribute to the package development, testing, or publishing, see [DEVELOPER.md](DEVELOPER.md) for detailed instructions on:
- Setting up the development environment
- Testing changes locally
- Publishing updates to PyPI
- Version management
- Troubleshooting

## ๐Ÿ“„ License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## ๐Ÿข About

Maintained by **Dhwani RIS** 

- ๐ŸŒ **Website**: [dhwaniris.com](https://dhwaniris.com)
- ๐Ÿ™ **GitHub**: [@dhwani-ris](https://github.com/dhwani-ris)


---

**Ready to improve your Frappe code quality?** Get started with Frappe-Pre-commit today! ๐Ÿš€

```bash
# Install pre-commit
pip install pre-commit

# Download the pre-commit configuration
curl -o .pre-commit-config.yaml https://raw.githubusercontent.com/dhwani-ris/frappe-pre-commit/main/examples/.pre-commit-config.yaml

# Install the pre-commit hooks (frappe-pre-commit package will be installed automatically)
pre-commit install

# Run all checks
pre-commit run --all-files
```

> **Note**: If you encounter "Executable `python` not found" errors, see the [Python Path Setup](#python-path-setup) section above.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "frappe-pre-commit",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "frappe, erpnext, pre-commit, hooks, code-quality",
    "author": null,
    "author_email": "Bhushan Barbuddhe <bhushan.barbuddhe@dhwaniris.com>",
    "download_url": "https://files.pythonhosted.org/packages/52/4e/68d48b2ca77ec5f6def1207e5f79ca1079f0acfae6029632128a125bf6ad/frappe_pre_commit-1.0.3.tar.gz",
    "platform": null,
    "description": "# \ud83c\udfaf Frappe Pre-commit\n\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![Python 3.8+](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/)\n[![Pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit)\n\n**Comprehensive pre-commit hooks for Frappe Framework projects** to enforce coding standards, security practices, and best practices automatically.\n\n## \u2728 Features\n\n- \ud83d\udee1\ufe0f **SQL Injection Prevention** - Detect and prevent SQL injection vulnerabilities\n- \ud83d\udccf **Coding Standards** - Enforce Frappe-specific coding conventions and best practices\n- \ud83d\udcdd **DocType Naming** - Validate DocType and field naming conventions\n- \u26a1 **Fast Execution** - Lightweight checks with minimal dependencies\n- \ud83c\udfaf **Customizable** - Pick and choose hooks based on your project needs\n\n## \ud83d\ude80 Quick Start\n\n### System Requirements\n\n- **Python**: 3.8 or higher\n- **pip**: Latest version\n- **pre-commit**: Will be installed automatically\n- **Git**: For version control\n\n### Python Path Setup\n\nIf you encounter \"Executable `python` not found\" errors, ensure Python is properly configured:\n\n```bash\n# Check Python installation\npython3 --version\n\n# Create python symlink if needed (Linux/macOS)\nsudo ln -s /usr/bin/python3 /usr/bin/python\n\n# Or add alias to your shell profile (~/.bashrc, ~/.zshrc)\necho 'alias python=python3' >> ~/.bashrc\nsource ~/.bashrc\n```\n\n### For New Frappe Projects\n\n```bash\n# 1. Initialize new Frappe app\nbench new-app my_custom_app\ncd apps/my_custom_app\n\n# 2. Create .pre-commit-config.yaml\ncurl -o .pre-commit-config.yaml https://raw.githubusercontent.com/dhwani-ris/frappe-pre-commit/main/examples/.pre-commit-config.yaml\n\n# 3. Install and run\npip install pre-commit\npre-commit install\npre-commit run --all-files\n```\n\n### For Existing Frappe Projects\n\n```bash\n# 1. Navigate to your app directory\ncd apps/your_app\n\n# 2. Add .pre-commit-config.yaml (see configuration below)\n# 3. Install pre-commit\npip install pre-commit\npre-commit install\n\n# 4. Run on existing code\npre-commit run --all-files\n```\n\n## \ud83d\udccb Available Hooks\n\n| Hook ID | Description | Files | Dependencies |\n|---------|-------------|-------|--------------|\n| `frappe-coding-standards` | General coding standards and best practices | `*.py` | None |\n| `frappe-sql-security` | SQL injection and security checks | `*.py` | None |\n| `frappe-doctype-naming` | DocType and field naming conventions | `*.py`, `*.js`, `*.json` | `pyyaml` |\n\n## \u2699\ufe0f Configuration\n\n### Basic Configuration\n\nCreate `.pre-commit-config.yaml` in your project root:\n\n```yaml\nrepos:\n  # Frappe-specific hooks\n  - repo: https://github.com/dhwani-ris/frappe-pre-commit\n    rev: v1.0.0  # Use latest tag\n    hooks:\n      - id: frappe-translation-check\n      - id: frappe-sql-security\n      - id: frappe-coding-standards\n\n  # Code formatting (recommended)\n  - repo: https://github.com/astral-sh/ruff-pre-commit\n    rev: v0.8.1\n    hooks:\n      - id: ruff\n        args: [\"--select=I\", \"--fix\"]  # Import sorting\n      - id: ruff-format  # Code formatting\n\n  # Additional quality checks\n  - repo: https://github.com/pre-commit/pre-commit-hooks\n    rev: v4.5.0\n    hooks:\n      - id: trailing-whitespace\n      - id: end-of-file-fixer\n      - id: check-yaml\n      - id: check-json\n```\n\n### Complete Configuration\n\n```yaml\nrepos:\n  # Python formatting and linting\n  - repo: https://github.com/astral-sh/ruff-pre-commit\n    rev: v0.8.1\n    hooks:\n      - id: ruff\n        name: \"Ruff import sorter\"\n        args: [\"--select=I\", \"--fix\"]\n      - id: ruff\n        name: \"Ruff linter\"\n        args: [\"--extend-ignore=E501\"]\n      - id: ruff-format\n        name: \"Ruff formatter\"\n\n  # JavaScript/CSS/JSON formatting\n  - repo: https://github.com/pre-commit/mirrors-prettier\n    rev: v4.0.0-alpha.8\n    hooks:\n      - id: prettier\n        files: \\.(js|jsx|ts|tsx|css|scss|json|md|yml|yaml)$\n        exclude: |\n          (?x)^(\n              .*\\.min\\.(js|css)$|\n              node_modules/.*|\n              .*/static/.*\n          )$\n\n  # Basic file checks\n  - repo: https://github.com/pre-commit/pre-commit-hooks\n    rev: v4.5.0\n    hooks:\n      - id: trailing-whitespace\n        exclude: \\.(md|rst)$\n      - id: end-of-file-fixer\n      - id: check-yaml\n      - id: check-json\n      - id: check-merge-conflict\n      - id: debug-statements\n\n  # Frappe-specific coding standards\n  - repo: https://github.com/dhwani-ris/frappe-pre-commit\n    rev: v1.0.0\n    hooks:\n      - id: frappe-coding-standards \n\n# Exclude patterns\nexclude: |\n  (?x)^(\n      .*/migrations/.*|\n      .*/patches/.*|\n      .*\\.min\\.(js|css)$|\n      node_modules/.*|\n      __pycache__/.*\n  )$\n```\n\n### Selective Hook Usage\n\n```yaml\n# Use only specific hooks you need\nrepos:\n  - repo: https://github.com/dhwani-ris/frappe-pre-commit\n    rev: v1.0.0\n    hooks:\n      - id: frappe-sql-security     # Only SQL security checks\n      - id: frappe-translation-check # Only translation checks\n```\n\n## \ud83d\udd0d What Gets Checked\n\n### \ud83d\udee1\ufe0f SQL Security Checks\n\n**Detects:**\n- SQL injection vulnerabilities using `.format()` or f-strings\n- String concatenation in SQL queries\n- Unencrypted storage of sensitive data (passwords, API keys)\n\n```python\n# \u274c Will be flagged\nfrappe.db.sql(\"SELECT * FROM tabUser WHERE name = '{}'\".format(user_name))\nfrappe.db.set_value(\"User\", user, \"password\", plain_password)\n\n# \u2705 Correct approach\nfrappe.db.sql(\"SELECT * FROM tabUser WHERE name = %s\", user_name)\nfrappe.db.set_value(\"User\", user, \"password\", frappe.utils.password.encrypt(plain_password))\n```\n\n\n### \ud83d\udccf Coding Standards\n\n**Enforces:**\n- Function length (\u226420 lines recommended)\n- Naming conventions (snake_case for functions, PascalCase for classes)\n- Ignore setUp and tearDown naming checks in test files, since they follow testing conventions \n- Import organization\n- Complexity limits (max nesting depth)\n\n### \ud83d\udcdd DocType Naming Conventions\n\n**Validates:**\n- DocType names: Title Case with spaces (`\"Sales Order\"`)\n- Field names: snake_case (`\"customer_name\"`)\n- Field labels: Title Case (`\"Customer Name\"`)\n\n## \ud83c\udfd7\ufe0f Integration Examples\n\n### Integration with Bench\n\n```bash\n# For bench-managed projects\ncd frappe-bench/apps/your_app\n\n# Add pre-commit config\ncurl -o .pre-commit-config.yaml https://raw.githubusercontent.com/dhwani-ris/frappe-pre-commit/main/examples/.pre-commit-config.yaml\n\n# Install globally in bench environment\n~/frappe-bench/env/bin/pip install pre-commit\n~/frappe-bench/env/bin/pre-commit install\n```\n\n### Integration with GitHub Actions\n\nCreate `.github/workflows/code-quality.yml`:\n\n```yaml\nname: Code Quality\n\non: [push, pull_request]\n\njobs:\n  pre-commit:\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions/checkout@v4\n      - uses: actions/setup-python@v4\n        with:\n          python-version: '3.10'\n      - name: Install pre-commit\n        run: pip install pre-commit\n      - name: Run pre-commit\n        run: pre-commit run --all-files\n```\n\n### Integration with VS Code\n\nAdd to `.vscode/settings.json`:\n\n```json\n{\n  \"python.linting.enabled\": true,\n  \"python.linting.flake8Enabled\": true,\n  \"python.formatting.provider\": \"black\",\n  \"editor.formatOnSave\": true,\n  \"python.sortImports.args\": [\"--profile\", \"black\"],\n  \"[python]\": {\n    \"editor.codeActionsOnSave\": {\n      \"source.organizeImports\": true\n    }\n  }\n}\n```\n\n## \ud83e\uddea Development and Testing\n\n### Setting Up Development Environment\n\n```bash\n# Clone the repository\ngit clone https://github.com/dhwani-ris/frappe-pre-commit.git\ncd frappe-pre-commit\n\n# Create virtual environment\npython -m venv dev_env\nsource dev_env/bin/activate  # On Windows: dev_env\\Scripts\\activate\n\n# Install development dependencies\npip install -r requirements-dev.txt\npip install pre-commit\n\n# Install pre-commit hooks for this repository\npre-commit install\n```\n\n### Running Tests\n\n```bash\n# Test individual scripts\npython scripts/check_coding_standards.py test_files/sample.py\npython scripts/check_sql_security.py test_files/sample.py\npython scripts/check_translations.py test_files/sample.py\n\n# Test all hooks\npython test_scripts/test_all_hooks.py\n\n# Test with pre-commit\npre-commit run --all-files\n```\n\n### Creating Test Files\n\n```bash\n# Create test files with issues\nmkdir test_project && cd test_project\n\n# Create Python file with intentional issues\ncat > bad_example.py << 'EOF'\nimport frappe\n\ndef very_long_function_that_violates_standards():\n    frappe.msgprint(\"Missing translation wrapper\")\n    result = frappe.db.sql(\"SELECT * FROM tabUser WHERE name = '{}'\".format(\"test\"))\n    return result\nEOF\n\n# Test your hooks\ncd ../\npython scripts/check_translations.py test_project/bad_example.py\npython scripts/check_sql_security.py test_project/bad_example.py\n```\n\n### Testing with Different Frappe Projects\n\n```bash\n# Test with ERPNext\ncd path/to/erpnext\ngit clone https://github.com/dhwani-ris/frappe-pre-commit.git .pre-commit-hooks\ncp .pre-commit-hooks/examples/.pre-commit-config.yaml .\npre-commit install\npre-commit run --all-files\n\n# Test with custom app\ncd path/to/your_custom_app\n# Same process as above\n```\n\n### Contributing\n\n1. **Fork the repository**\n2. **Create feature branch**: `git checkout -b feature/new-check`\n3. **Add your hook script** in `scripts/`\n4. **Update `.pre-commit-hooks.yaml`**\n5. **Add tests** in `test_scripts/`\n6. **Update documentation**\n7. **Submit pull request**\n\n## \ud83d\udcda Examples\n\n### Example 1: Basic Frappe App Setup\n\n```bash\n# Create new app\ncd frappe-bench\nbench new-app inventory_management\ncd apps/inventory_management\n\n# Add pre-commit\ncat > .pre-commit-config.yaml << 'EOF'\nrepos:\n  - repo: https://github.com/dhwani-ris/frappe-pre-commit\n    rev: v1.0.0\n    hooks:\n      - id: frappe-quick-check\nEOF\n\n# Install and test\npip install pre-commit\npre-commit install\npre-commit run --all-files\n```\n\n### Example 2: ERPNext Customization\n\n```bash\n# For ERPNext customizations\ncd frappe-bench/apps/erpnext\n\n# Use comprehensive config\ncurl -o .pre-commit-config.yaml https://raw.githubusercontent.com/dhwani-ris/frappe-pre-commit/main/examples/erpnext-config.yaml\n\npre-commit install\npre-commit run --all-files\n```\n\n### Example 3: CI/CD Integration\n\n```yaml\n# .github/workflows/quality-check.yml\nname: Quality Check\n\non:\n  pull_request:\n    branches: [main, develop]\n\njobs:\n  code-quality:\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions/checkout@v4\n      \n      - name: Set up Python\n        uses: actions/setup-python@v4\n        with:\n          python-version: '3.10'\n      \n      - name: Install dependencies\n        run: |\n          pip install pre-commit\n          pip install -r requirements.txt\n      \n      - name: Run pre-commit\n        run: pre-commit run --all-files\n      \n      - name: Comment PR\n        if: failure()\n        uses: actions/github-script@v6\n        with:\n          script: |\n            github.rest.issues.createComment({\n              issue_number: context.issue.number,\n              owner: context.repo.owner,\n              repo: context.repo.repo,\n              body: '\u274c Code quality checks failed. Please run `pre-commit run --all-files` locally and fix the issues.'\n            })\n```\n\n## \ud83d\udd27 Troubleshooting\n\n### Common Issues\n\n**Pre-commit hooks not running:**\n```bash\npre-commit uninstall\npre-commit install\npre-commit run --all-files\n```\n\n**Python executable not found error:**\n```bash\n# Error: Executable `python` not found\n# Solution: Create a python symlink or alias\n\n# Option 1: Create symlink (Linux/macOS)\nsudo ln -s /usr/bin/python3 /usr/bin/python\n\n# Option 2: Create alias (add to ~/.bashrc or ~/.zshrc)\nalias python=python3\n\n# Option 3: Use python3 explicitly in PATH\nexport PATH=\"/usr/bin:$PATH\"\n\n# Option 4: Install python-is-python3 package (Ubuntu/Debian)\nsudo apt install python-is-python3\n\n# After fixing, reinstall pre-commit hooks\npre-commit uninstall\npre-commit install\n```\n\n**Hooks failing on large files:**\n```bash\n# Skip hooks for specific commit\ngit commit -m \"Large file update\" --no-verify\n\n# Or exclude large files in config\n# Add to .pre-commit-config.yaml:\nexclude: |\n  (?x)^(\n      large_files/.*|\n      .*\\.min\\.js$\n  )$\n```\n\n**Import errors in scripts:**\n```bash\n# Make sure Python can find the scripts\nexport PYTHONPATH=\"${PYTHONPATH}:$(pwd)\"\n```\n\n**Package installation issues:**\n```bash\n# If frappe-pre-commit package fails to install automatically\npip install frappe-pre-commit\n\n# Clear pre-commit cache and reinstall\npre-commit clean\npre-commit install\n```\n\n### Performance Tips\n\n```bash\n# Cache pre-commit environments\nexport PRE_COMMIT_HOME=~/.cache/pre-commit\n\n# Run only on changed files\npre-commit run\n\n# Skip slow hooks during development\nPRE_COMMIT_SKIP=frappe-all-checks git commit -m \"Quick fix\"\n```\n\n## \ud83e\udd1d Contributing\n\nWe welcome contributions! \n\n### Quick Contribution Steps\n\n1. Fork the repository\n2. Clone your fork: `git clone https://github.com/yourusername/frappe-pre-commit.git`\n3. Create branch: `git checkout -b feature/improvement`\n4. Make changes and test thoroughly\n5. Submit pull request\n\n### For Developers\n\nIf you want to contribute to the package development, testing, or publishing, see [DEVELOPER.md](DEVELOPER.md) for detailed instructions on:\n- Setting up the development environment\n- Testing changes locally\n- Publishing updates to PyPI\n- Version management\n- Troubleshooting\n\n## \ud83d\udcc4 License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## \ud83c\udfe2 About\n\nMaintained by **Dhwani RIS** \n\n- \ud83c\udf10 **Website**: [dhwaniris.com](https://dhwaniris.com)\n- \ud83d\udc19 **GitHub**: [@dhwani-ris](https://github.com/dhwani-ris)\n\n\n---\n\n**Ready to improve your Frappe code quality?** Get started with Frappe-Pre-commit today! \ud83d\ude80\n\n```bash\n# Install pre-commit\npip install pre-commit\n\n# Download the pre-commit configuration\ncurl -o .pre-commit-config.yaml https://raw.githubusercontent.com/dhwani-ris/frappe-pre-commit/main/examples/.pre-commit-config.yaml\n\n# Install the pre-commit hooks (frappe-pre-commit package will be installed automatically)\npre-commit install\n\n# Run all checks\npre-commit run --all-files\n```\n\n> **Note**: If you encounter \"Executable `python` not found\" errors, see the [Python Path Setup](#python-path-setup) section above.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Pre-commit hooks for Frappe Framework coding standards",
    "version": "1.0.3",
    "project_urls": {
        "Bug Tracker": "https://github.com/dhwani-ris/frappe-pre-commit/issues",
        "Changelog": "https://github.com/dhwani-ris/frappe-pre-commit/blob/main/CHANGELOG.md",
        "Documentation": "https://github.com/dhwani-ris/frappe-pre-commit#readme",
        "Homepage": "https://github.com/dhwani-ris/frappe-pre-commit",
        "Repository": "https://github.com/dhwani-ris/frappe-pre-commit"
    },
    "split_keywords": [
        "frappe",
        " erpnext",
        " pre-commit",
        " hooks",
        " code-quality"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "008127c8ed81a9e4eeceb678f984a29f94cb503657fd50896edaffa1c2ed5b23",
                "md5": "a158786e19fc624099751ad62c13adb8",
                "sha256": "c3101070593dca08fa0baa5b61497454bbc4fe269839d46a6f35f21aa9719ea4"
            },
            "downloads": -1,
            "filename": "frappe_pre_commit-1.0.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a158786e19fc624099751ad62c13adb8",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 13925,
            "upload_time": "2025-09-02T06:22:17",
            "upload_time_iso_8601": "2025-09-02T06:22:17.949873Z",
            "url": "https://files.pythonhosted.org/packages/00/81/27c8ed81a9e4eeceb678f984a29f94cb503657fd50896edaffa1c2ed5b23/frappe_pre_commit-1.0.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "524e68d48b2ca77ec5f6def1207e5f79ca1079f0acfae6029632128a125bf6ad",
                "md5": "e38e406f713bd8a03abcfd6caa151185",
                "sha256": "0cc4af43929a7def52ecdf1e728113444c64aa382c019a3985c57caf6eb997fd"
            },
            "downloads": -1,
            "filename": "frappe_pre_commit-1.0.3.tar.gz",
            "has_sig": false,
            "md5_digest": "e38e406f713bd8a03abcfd6caa151185",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 12399,
            "upload_time": "2025-09-02T06:22:19",
            "upload_time_iso_8601": "2025-09-02T06:22:19.382332Z",
            "url": "https://files.pythonhosted.org/packages/52/4e/68d48b2ca77ec5f6def1207e5f79ca1079f0acfae6029632128a125bf6ad/frappe_pre_commit-1.0.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-09-02 06:22:19",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "dhwani-ris",
    "github_project": "frappe-pre-commit",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "frappe-pre-commit"
}
        
Elapsed time: 1.85039s