constcheck
Check Python files for repeat use of strings
Escape commas with \\ (\ when enclosed in single quotes)
Defaults can be configured in your pyproject.toml file
Installation
$ pip install constcheck
Usage
Commandline
usage: constcheck [-h] [-v] [-n] [-c INT] [-l INT] [-s STR] [-i LIST] [-I LIST]
[--ignore-from [FILE=LIST [FILE=LIST ...]]]
[path [path ...]]
Check Python files for repeat use of strings. Escape commas with \\. Defaults can be configured in
your pyproject.toml file.
positional arguments:
path path(s) to check files for (default: .)
optional arguments:
-h, --help show this help message and exit
-v, --version show program's version number and exit
-n, --no-ansi disable ansi output
-c INT, --count INT minimum number of repeat strings (default: 3)
-l INT, --length INT minimum length of repeat strings (default: 3)
-s STR, --string STR parse a string instead of a file
-i LIST, --ignore-strings LIST comma separated list of strings to exclude
-I LIST, --ignore-files LIST comma separated list of files to exclude
--ignore-from [FILE=LIST [FILE=LIST ...]] comma separated list of strings to exclude from file
API
>>> from constcheck import constcheck
>>> EXAMPLE = """
... STRING_1 = "Hey"
... STRING_2 = "Hey"
... STRING_3 = "Hey"
... STRING_4 = "Hello"
... STRING_5 = "Hello"
... STRING_6 = "Hello"
... STRING_7 = "Hello"
... STRING_8 = "Hello, world"
... STRING_9 = "Hello, world"
... STRING_10 = "Hello, world"
... STRING_11 = "Hello, world"
... STRING_12 = "Hello, world"
... """
>>> constcheck(string=EXAMPLE, no_ansi=True)
3 | Hey
4 | Hello
5 | Hello, world
<BLANKLINE>
1
With the count argument
>>> constcheck(string=EXAMPLE, count=4, no_ansi=True)
4 | Hello
5 | Hello, world
<BLANKLINE>
1
With the length argument
>>> constcheck(string=EXAMPLE, length=6, no_ansi=True)
5 | Hello, world
<BLANKLINE>
1
With the ignore_strings argument which accepts list of str objects
>>> constcheck(string=EXAMPLE, ignore_strings=["Hello, world", "Hello"], no_ansi=True)
3 | Hey
<BLANKLINE>
1
Config
All keyword arguments available to constcheck() can be configured in the pyproject.toml file
[tool.constcheck]
path = "."
count = 3
length = 3
ignore_strings = ["Hello", "Hello, world"]
ignore_files = ["tests/__init__.py"]
filter = false
no_color = false
[tool.constcheck.ignore_from]
"tests/__init__.py" = ["Hello, world"]
pre-commit
constcheck can be used as a pre-commit hook
It can be added to your .pre-commit-config.yaml as follows:
repos:
- repo: https://github.com/jshwi/constcheck
rev: v0.7.0
hooks:
- id: constcheck
args:
- "--count=3"
- "--length=3"
Metadata
Release files for constcheck 0.13.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| constcheck-0.13.0.tar.gz | 11.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| constcheck-0.13.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 22.5 kB
Release files / constcheck-0.13.0.tar.gz
| Download URL | constcheck-0.13.0.tar.gz |
|---|---|
| Size | 11.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
828a107780115b71eaca15947c3725edac6e0a14085bb511fe4fe012c860db46
|
|
BLAKE2b-256 checksum How to use checksums |
ccecec7d4fe0255c2b046a10e30ff5219fbf56adce3032ad4b58d70b76884678
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.2.1 CPython/3.10.9 Darwin/24.6.0
|
Release files / constcheck-0.13.0-py3-none-any.whl
| Download URL | constcheck-0.13.0-py3-none-any.whl |
|---|---|
| Size | 11.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b0950e47b56ae6044a4851ada4fbba2b9d9d2bd3e3bda3562159607434b7a3d3
|
|
BLAKE2b-256 checksum How to use checksums |
a755a2b73a307c1bb78bd9f05a32ca9bf22b99a3de25dd22b8e52c520febbfcb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.2.1 CPython/3.10.9 Darwin/24.6.0
|