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] [-p PATH] [-c INT] [-l INT] [-s STR] [-i LIST] [-I LIST]
                             [--ignore-from [FILE=LIST [FILE=LIST ...]]] [-f] [-n] [-v]

optional arguments:
  -h, --help                                 show this help message and exit
  -p PATH, --path PATH                       path to check files for (default: .)
  -c INT, --count INT                        minimum number of repeat strings (default: 3)
  -l INT, --len 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
  -f, --filter                               filter out empty results
  -n, --no-color                             disable color output
  -v, --version                              show version and exit

API

>>> 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.main(string=EXAMPLE)
3   | Hey
4   | Hello
5   | Hello, world
<BLANKLINE>
1

With the count argument

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

With the len argument

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

With the ignore_strings argument which accepts a str iterable

>>> constcheck.main(string=EXAMPLE, ignore_strings=["Hello, world", "Hello"])
3   | Hey
<BLANKLINE>
1
>>> constcheck.main(string=EXAMPLE, ignore_strings="Hello, world")
3   | Hey
<BLANKLINE>
1
>>> constcheck.main(string=EXAMPLE, ignore_strings=["Hello, world", "Hello", "Hey"])
<BLANKLINE>
0

Config

All keyword arguments available to constcheck.main() can be configured in the pyproject.toml file

[tool.constcheck]
path = "."
count = 3
len = 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"]

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.3.0.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

constcheck-0.3.0-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: constcheck-0.3.0.tar.gz
  • Upload date:
  • Size: 10.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.8.11+ Linux/5.16.18-200.fc35.x86_64

File hashes

Hashes for constcheck-0.3.0.tar.gz
Algorithm Hash digest
SHA256 0d127ee36a00dffee9bbc79c7c1955931868160d0ee52d80a6cdd87de736a13f
MD5 102e335288df305a40e11fc2286b47be
BLAKE2b-256 378e00bd3c8b49c7337d90ee1fc548a1ebb4dcd7ed5ef803ef1cf694a062da20

See more details on using hashes here.

File details

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

File metadata

  • Download URL: constcheck-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 10.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.8.11+ Linux/5.16.18-200.fc35.x86_64

File hashes

Hashes for constcheck-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cce9de2c4abc937dc0c1491678cc264f32b3c75129b7838fcfb16d90dbecd2e6
MD5 5b95c3677241f6e3b2fc3e92d3d62feb
BLAKE2b-256 6deb6a4de5b671e2d94cdcb80d30413c9de91acf4a399adf52745460a1a3e18f

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