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

pip install -e '.[dev]'

Run all development checks:

make lint
make test

Build the distribution:

make build

🧪 Testing

pytest -v --disable-warnings

🚀 Publishing

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

# 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.1.0.tar.gz (7.5 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.1.0-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for jps_pre_commit_utils-1.1.0.tar.gz
Algorithm Hash digest
SHA256 0550efe0b8925103baa07b32d0130c527fa511b438312b8dc627c664dfebfc68
MD5 a61118b82c9025787ae77cde698061b4
BLAKE2b-256 86f22ef3b45ddcf47a6c3885dbf026521dc1b953ec3f87817b9293f85263ccc4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for jps_pre_commit_utils-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 db10db2fa79e4f472408a915dd6a37e88adfcd510e63222320f2d0d01765632a
MD5 2eb57ff133789af9daa174b57a04724f
BLAKE2b-256 84db67b7c228fccc5691d8f63a7ceb95e329ff118a78305e87cfcb044d939d68

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