Skip to main content

CLI tool to check if a snippet exists in files

Project description

contains-snippet

A command-line tool that checks whether a given snippet exists anywhere within a file. For plain text files (like .md), it searches the raw content directly. For source code files (.py, .yml, .yaml), it checks for the snippet rendered as comments.

Installation

pip install -e .

Usage

contains-snippet --snippet-file SNIPPET_FILE FILE [FILE ...]

Exit Codes

  • 0 - All files contain the snippet
  • 1 - One or more files are missing the snippet
  • 2 - Usage/configuration/runtime error

Matching Rules (Default)

  • .md files: Raw substring match
  • .py, .yml, .yaml files: Commented match (lines prefixed with #)
  • Other extensions: Raw substring match

Examples

Check if a license notice appears in a README:

contains-snippet --snippet-file license_notice.txt README.md

Check if a header comment exists in multiple Python files:

contains-snippet --snippet-file header.txt src/*.py

Configuring Match Behavior

Force Commented Matching: --comment-prefix

Force all files to use commented matching with a specific prefix:

# Check JavaScript files with // comments
contains-snippet --snippet-file header.txt --comment-prefix "//" src/*.js

# Force .md files to match as comments (not raw)
contains-snippet --snippet-file notice.txt --comment-prefix "#" docs/*.md

Infer from Extension: --infer-comment-prefix

Enable extension-based inference using built-in mapping:

Extension Match Type
.md raw
.py # comments
.yml # comments
.yaml # comments
(other) raw
contains-snippet --snippet-file header.txt --infer-comment-prefix src/*.py docs/*.md

Custom Extension Mapping: --comment-prefix-map

Override or extend the built-in mapping (requires --infer-comment-prefix):

# Add JavaScript and TypeScript support
contains-snippet --snippet-file header.txt \
  --infer-comment-prefix \
  --comment-prefix-map ".js=//,.ts=//" \
  src/*

# Override Python to use raw matching
contains-snippet --snippet-file notice.txt \
  --infer-comment-prefix \
  --comment-prefix-map ".py=raw" \
  src/*.py

Precedence

  1. --comment-prefix (highest) - forces global commented matching
  2. --infer-comment-prefix + --comment-prefix-map - per-file inference
  3. Default behavior - current hardcoded rules

CI Checks

The following checks run on every push and pull request:

  • yamllint - YAML linting for workflow files
  • pylint - Python linting for source and test code
  • mypy - Static type checking for source code
  • jscpd - Duplicate code detection
  • pytest - Unit, integration, and E2E tests

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

contains_snippet-20260108014512.tar.gz (17.6 kB view details)

Uploaded Source

Built Distribution

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

contains_snippet-20260108014512-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file contains_snippet-20260108014512.tar.gz.

File metadata

File hashes

Hashes for contains_snippet-20260108014512.tar.gz
Algorithm Hash digest
SHA256 aa5a998c650abf04f62fe1c75de7827b368ade79a451160fbfdd4e393bec3730
MD5 37d2a020d16411feb629226517d00f94
BLAKE2b-256 e135b6dda95a4ae7bd29c1259919f4a7b7c5b0be851d547e11e27b38631eb4b5

See more details on using hashes here.

Provenance

The following attestation bundles were made for contains_snippet-20260108014512.tar.gz:

Publisher: release.yml on 10U-Labs-LLC/contains-snippet

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file contains_snippet-20260108014512-py3-none-any.whl.

File metadata

File hashes

Hashes for contains_snippet-20260108014512-py3-none-any.whl
Algorithm Hash digest
SHA256 d525e0f64cd74e10cf6284a02af04f1d1ca883c46499b963070c4b91e9e96691
MD5 26d5edec5f1fab8bb6c910e141a146bc
BLAKE2b-256 2bd436c831aef232a266219482a207f1f1f38a0a3773f642e3d3428ca2a32489

See more details on using hashes here.

Provenance

The following attestation bundles were made for contains_snippet-20260108014512-py3-none-any.whl:

Publisher: release.yml on 10U-Labs-LLC/contains-snippet

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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