Skip to main content

Check Python files for repeat use of strings

Project description

License pypi CI CodeQL codecov.io readthedocs.org python3.8 black

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 ...]]

positional arguments:
  path                                       path(s) to check files for (default: .)

optional arguments:
  -h, --help                                 show this help message and exit
  -v, --version                              show version 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)
3   | Hey
4   | Hello
5   | Hello, world
<BLANKLINE>
1

With the count argument

>>> constcheck(string=EXAMPLE, count=4)
4   | Hello
5   | Hello, world
<BLANKLINE>
1

With the length argument

>>> constcheck(string=EXAMPLE, length=6)
5   | Hello, world
<BLANKLINE>
1

With the ignore_strings argument which accepts list of str objects

>>> constcheck(string=EXAMPLE, ignore_strings=["Hello, world", "Hello"])
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"

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

constcheck-0.7.0.tar.gz (10.8 kB view details)

Uploaded Source

Built Distribution

constcheck-0.7.0-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

Details for the file constcheck-0.7.0.tar.gz.

File metadata

  • Download URL: constcheck-0.7.0.tar.gz
  • Upload date:
  • Size: 10.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.1 CPython/3.8.13 Darwin/22.2.0

File hashes

Hashes for constcheck-0.7.0.tar.gz
Algorithm Hash digest
SHA256 7090fa6df84e154898670891dbdedcc48c3525cf571466e5046eb4a30effb7ab
MD5 aa21da2d11b6fe3cff3252dd5a3d52c7
BLAKE2b-256 a24be506b9336e0fbb0e3c8192431085cde35c36a4fb4cbb23486c410d28a4f3

See more details on using hashes here.

File details

Details for the file constcheck-0.7.0-py3-none-any.whl.

File metadata

  • Download URL: constcheck-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 10.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.1 CPython/3.8.13 Darwin/22.2.0

File hashes

Hashes for constcheck-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 abadb4cfed80dd7b2f6667f5eff9acb16e60fb5dc97885544f9532239cbdea06
MD5 adbd5ae484947f243378cfff940d607e
BLAKE2b-256 ee6d90cafe3869808c409c4112eaeb19ce31863627db253584c89a3b9319cbd1

See more details on using hashes here.

Supported by

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