Metadata-Version: 2.4
Name: jps-pre-commit-utils
Version: 1.2.0
Summary: Custom pre-commit utility for scanning diffs for debug/test patterns, hardcoded paths, and other configurable checks.
Author: Jaideep Sundaram
License: MIT License
Project-URL: Homepage, https://github.com/jai-python3/jps-pre-commit-utils
Project-URL: Repository, https://github.com/jai-python3/jps-pre-commit-utils
Project-URL: Issues, https://github.com/jai-python3/jps-pre-commit-utils/issues
Keywords: pre-commit,git,lint,static-analysis,utilities
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: rich>=13.7.0
Requires-Dist: pyyaml>=6.0
Provides-Extra: test
Requires-Dist: pytest>=8.0.0; extra == "test"
Provides-Extra: dev
Requires-Dist: flake8>=7.0.0; extra == "dev"
Requires-Dist: black>=24.0.0; extra == "dev"
Requires-Dist: build>=1.2.1; extra == "dev"
Requires-Dist: twine>=5.0.0; extra == "dev"
Requires-Dist: pytest>=8.0.0; extra == "dev"
Requires-Dist: pytest-cov>=5.0.0; extra == "dev"
Requires-Dist: isort>=5.13.0; extra == "dev"
Requires-Dist: codecov>=2.1.13; extra == "dev"
Dynamic: license-file

# jps-pre-commit-utils

![Build](https://github.com/jai-python3/jps-pre-commit-utils/actions/workflows/test.yml/badge.svg)
![Publish to PyPI](https://github.com/jai-python3/jps-pre-commit-utils/actions/workflows/publish-to-pypi.yml/badge.svg)
[![codecov](https://codecov.io/gh/jai-python3/jps-pre-commit-utils/branch/main/graph/badge.svg)](https://codecov.io/gh/jai-python3/jps-pre-commit-utils)


Custom pre-commit utilities for detecting debug/test leftovers, hardcoded paths, and environment-specific code fragments  
in Python, Perl, and YAML files before they are committed.  
These checks catch issues that are not easily detected by flake8, black, mypy, or bandit.

---

## 🧩 Features

✅ Scans *staged diffs* (`git diff --cached`) before commit  
✅ Detects newly added lines containing:
- Debugging and testing statements (e.g., `print`, `sys.exit`, `pdb.set_trace`, `logger.debug`)
- Hardcoded filesystem paths (e.g., `/mnt/synth-genomics3/...`)
- Hardcoded environment variables or hostnames
- Inline comments with “test” or “TODO”
✅ Supports **Python**, **Perl**, and **YAML** files  
✅ Configurable via `.my-pre-commit-checks.yaml` or `~/.config/my-pre-commit-checks.yaml`  
✅ Integrates easily with manual usage or `.pre-commit-config.yaml`

---

## 🧩 Installation

```bash
pip install jps-pre-commit-utils
```

For local development:

```bash
git clone git@github.com:jai-python3/jps-pre-commit-utils.git
cd jps-pre-commit-utils
pip install -e '.[dev]'
```

---

## 🧩 Usage

Run manually:

```bash
jps-pre-commit-checks
```

Or integrate with Git pre-commit:

```bash
# .git/hooks/pre-commit
#!/bin/bash
python3 -m jps_pre_commit_utils.check_inserted_lines
```

---

## 🧩 Example Configuration

Configuration file:  
`.my-pre-commit-checks.yaml` *(in repo root)*  
or  
`~/.config/my-pre-commit-checks.yaml` *(global fallback)*

```yaml
# Example configuration for jps-pre-commit-utils
base_paths:
  - /mnt/synth-genomics3
  - /Users
ignore_patterns:
  - /mnt/synth-genomics3/bioinfo/shared/
extra_regexes:
  - "jira/[A-Z]+-[0-9]+"
```

---

## 🧩 Example Output

```bash
---------------------------------------------------------
🔧 Performing the following checks:
---------------------------------------------------------
• 🐍 Python debug/test statements
• 🐪 Perl debug/test statements
• 📁 Hardcoded absolute paths
• 🧪 Comments containing 'test' or 'testing'
---------------------------------------------------------
Scanning inserted lines ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% • 45/45
---------------------------------------------------------
🔍 Pre-commit inserted-line scan results
---------------------------------------------------------
⚠️  File: src/example.py, Line: 18
    Added line contains pattern: "#[ 	]*.*test"
    → # test
---------------------------------------------------------
⚠️  Total findings: 1
---------------------------------------------------------
```

---

## 🧱 Development

Install dependencies for linting, formatting, and testing:

```bash
pip install -e '.[dev]'
```

Run all development checks:

```bash
make lint
make test
```

Build the distribution:

```bash
make build
```

---

## 🧪 Testing

```bash
pytest -v --disable-warnings
```

---

## 🚀 Publishing

```bash
make publish
```

This command builds and uploads the package to PyPI via `twine`.

---

## 🧾 License

MIT License  
© 2025 Jaideep Sundaram

---

## 🧠 Notes

- The utility is designed for use with Git repositories that follow a Gitflow workflow.  
- Configuration is fully customizable; extend `.my-pre-commit-checks.yaml` to add your own regexes.  
- Future versions will include additional checks for breakpoints, asserts, sleep statements, and other runtime risks.  

---

### 🧩 Example Workflow

```bash
# Edit a file
echo '# test' >> src/sample.py

# Stage and check
git add src/sample.py
jps-pre-commit-checks
```

If issues are found, they are listed as warnings.  
If none are found, you’ll see:

```bash
✅ No issues detected. (0 findings)
```
