Skip to main content

Check Python files for repeat use of strings

Project description

License PyPI Build CodeQL pre-commit.ci status codecov.io readthedocs.org python3.10 Black isort pylint Security Status Known Vulnerabilities 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)
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.12.0.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

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

constcheck-0.12.0-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: constcheck-0.12.0.tar.gz
  • Upload date:
  • Size: 10.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.10.9 Darwin/24.6.0

File hashes

Hashes for constcheck-0.12.0.tar.gz
Algorithm Hash digest
SHA256 fbc2f64c85dbde07c5d87a2e0c0572eb092e26b32fa4025334bfc7c12214eac8
MD5 7b8ee07963024b0f62ef0b5f7273b567
BLAKE2b-256 232ac059a506aa97512c67f4d473519d31c4777da6ab18adc3249ef3afe91201

See more details on using hashes here.

File details

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

File metadata

  • Download URL: constcheck-0.12.0-py3-none-any.whl
  • Upload date:
  • Size: 11.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.10.9 Darwin/24.6.0

File hashes

Hashes for constcheck-0.12.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f63e5a57486faf202928d5e511703e1b93d5fabc736528eb4b40250d3bc16c7b
MD5 71fbfcffcf9cf504b6675e3f638460ce
BLAKE2b-256 2cefcc79ace31a5ac6ea420a006d05d344b21ae50f4a66c08a8bfb8a8e94ef7d

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