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 snippet1- One or more files are missing the snippet2- Usage/configuration/runtime error
Matching Rules (Default)
.mdfiles: Raw substring match.py,.yml,.yamlfiles: 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
--comment-prefix(highest) - forces global commented matching--infer-comment-prefix+--comment-prefix-map- per-file inference- 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file contains_snippet-20260108014512.tar.gz.
File metadata
- Download URL: contains_snippet-20260108014512.tar.gz
- Upload date:
- Size: 17.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aa5a998c650abf04f62fe1c75de7827b368ade79a451160fbfdd4e393bec3730
|
|
| MD5 |
37d2a020d16411feb629226517d00f94
|
|
| BLAKE2b-256 |
e135b6dda95a4ae7bd29c1259919f4a7b7c5b0be851d547e11e27b38631eb4b5
|
Provenance
The following attestation bundles were made for contains_snippet-20260108014512.tar.gz:
Publisher:
release.yml on 10U-Labs-LLC/contains-snippet
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
contains_snippet-20260108014512.tar.gz -
Subject digest:
aa5a998c650abf04f62fe1c75de7827b368ade79a451160fbfdd4e393bec3730 - Sigstore transparency entry: 804078671
- Sigstore integration time:
-
Permalink:
10U-Labs-LLC/contains-snippet@98739047afc9156817b9bea3a40b06aa322a646f -
Branch / Tag:
refs/heads/main - Owner: https://github.com/10U-Labs-LLC
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@98739047afc9156817b9bea3a40b06aa322a646f -
Trigger Event:
workflow_run
-
Statement type:
File details
Details for the file contains_snippet-20260108014512-py3-none-any.whl.
File metadata
- Download URL: contains_snippet-20260108014512-py3-none-any.whl
- Upload date:
- Size: 9.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d525e0f64cd74e10cf6284a02af04f1d1ca883c46499b963070c4b91e9e96691
|
|
| MD5 |
26d5edec5f1fab8bb6c910e141a146bc
|
|
| BLAKE2b-256 |
2bd436c831aef232a266219482a207f1f1f38a0a3773f642e3d3428ca2a32489
|
Provenance
The following attestation bundles were made for contains_snippet-20260108014512-py3-none-any.whl:
Publisher:
release.yml on 10U-Labs-LLC/contains-snippet
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
contains_snippet-20260108014512-py3-none-any.whl -
Subject digest:
d525e0f64cd74e10cf6284a02af04f1d1ca883c46499b963070c4b91e9e96691 - Sigstore transparency entry: 804078699
- Sigstore integration time:
-
Permalink:
10U-Labs-LLC/contains-snippet@98739047afc9156817b9bea3a40b06aa322a646f -
Branch / Tag:
refs/heads/main - Owner: https://github.com/10U-Labs-LLC
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@98739047afc9156817b9bea3a40b06aa322a646f -
Trigger Event:
workflow_run
-
Statement type: