Skip to main content

Custom pre-commit utility for scanning diffs for debug/test patterns, hardcoded paths, and other configurable checks.

Project description

jps-pre-commit-utils

Build Publish to PyPI codecov

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

pip install jps-pre-commit-utils

For local development:

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

🧩 Usage

Run manually:

jps-pre-commit-util-checks

Or integrate with Git pre-commit:

# .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)

# 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

---------------------------------------------------------
🔧 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:

make install-build-tools

Run all development checks:

make fix && make format && make lint
make test

🧪 Testing

make test

🧾 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

# 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:

 No issues detected. (0 findings)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jps_pre_commit_utils-1.3.0.tar.gz (15.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jps_pre_commit_utils-1.3.0-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

Details for the file jps_pre_commit_utils-1.3.0.tar.gz.

File metadata

  • Download URL: jps_pre_commit_utils-1.3.0.tar.gz
  • Upload date:
  • Size: 15.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for jps_pre_commit_utils-1.3.0.tar.gz
Algorithm Hash digest
SHA256 e4a0c023be060d32eb7f8bdc12d4f12477c0755e4130a9442dade6855771d70f
MD5 ceddb71baa2d3fcb7f9574dbd4edad92
BLAKE2b-256 3652aab731c8999b71dccf335db9c6b42ad4d9f3b60b68d17b5b3394554626f5

See more details on using hashes here.

File details

Details for the file jps_pre_commit_utils-1.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for jps_pre_commit_utils-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 943d91de3e12d08ac017d47b13b22c3cee723b825e98b1b5000a948461836af5
MD5 3d230f874d5b52ec5abc53781c08a303
BLAKE2b-256 814e3ca441a5759dc89c5282444b3a78b635861b190faf600b50cd69565ecbef

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page