constcheck


Nameconstcheck JSON
Version 0.9.0 PyPI version JSON
download
home_pagehttps://pypi.org/project/constcheck/
SummaryCheck Python files for repeat use of strings
upload_time2024-01-07 12:35:16
maintainerjshwi
docs_urlNone
authorjshwi
requires_python>=3.8,<4.0
licenseMIT
keywords check const constant dry str
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            constcheck
==========
.. image:: https://img.shields.io/badge/License-MIT-yellow.svg
    :target: https://opensource.org/licenses/MIT
    :alt: License
.. image:: https://img.shields.io/pypi/v/constcheck
    :target: https://pypi.org/project/constcheck/
    :alt: PyPI
.. image:: https://github.com/jshwi/constcheck/actions/workflows/build.yaml/badge.svg
    :target: https://github.com/jshwi/constcheck/actions/workflows/build.yaml
    :alt: Build
.. image:: https://github.com/jshwi/constcheck/actions/workflows/codeql-analysis.yml/badge.svg
    :target: https://github.com/jshwi/constcheck/actions/workflows/codeql-analysis.yml
    :alt: CodeQL
.. image:: https://results.pre-commit.ci/badge/github/jshwi/constcheck/master.svg
   :target: https://results.pre-commit.ci/latest/github/jshwi/constcheck/master
   :alt: pre-commit.ci status
.. image:: https://codecov.io/gh/jshwi/constcheck/branch/master/graph/badge.svg
    :target: https://codecov.io/gh/jshwi/constcheck
    :alt: codecov.io
.. image:: https://readthedocs.org/projects/constcheck/badge/?version=latest
    :target: https://constcheck.readthedocs.io/en/latest/?badge=latest
    :alt: readthedocs.org
.. image:: https://img.shields.io/badge/python-3.8-blue.svg
    :target: https://www.python.org/downloads/release/python-380
    :alt: python3.8
.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
    :target: https://github.com/psf/black
    :alt: Black
.. image:: https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336
    :target: https://pycqa.github.io/isort/
    :alt: isort
.. image:: https://img.shields.io/badge/%20formatter-docformatter-fedcba.svg
    :target: https://github.com/PyCQA/docformatter
    :alt: docformatter
.. image:: https://img.shields.io/badge/linting-pylint-yellowgreen
    :target: https://github.com/PyCQA/pylint
    :alt: pylint
.. image:: https://img.shields.io/badge/security-bandit-yellow.svg
    :target: https://github.com/PyCQA/bandit
    :alt: Security Status
.. image:: https://snyk.io/test/github/jshwi/constcheck/badge.svg
    :target: https://snyk.io/test/github/jshwi/constcheck/badge.svg
    :alt: Known Vulnerabilities
.. image:: https://snyk.io/advisor/python/constcheck/badge.svg
    :target: https://snyk.io/advisor/python/constcheck
    :alt: 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
------------

.. code-block:: console

    $ pip install constcheck

Usage
-----

Commandline
***********

.. code-block:: console

    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
***

.. code-block:: python

    >>> from constcheck import constcheck

.. code-block:: python

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

.. code-block:: python

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

With the ``count`` argument

.. code-block:: python

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

With the ``length`` argument

.. code-block:: python

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

With the ``ignore_strings`` argument which accepts ``list`` of ``str`` objects

.. code-block:: python

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

.. code-block:: toml

    [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 <https://pre-commit.com>`_ hook

It can be added to your .pre-commit-config.yaml as follows:

.. code-block:: yaml

    repos:
      - repo: https://github.com/jshwi/constcheck
        rev: v0.7.0
        hooks:
          - id: constcheck
            args:
              - "--count=3"
              - "--length=3"

            

Raw data

            {
    "_id": null,
    "home_page": "https://pypi.org/project/constcheck/",
    "name": "constcheck",
    "maintainer": "jshwi",
    "docs_url": null,
    "requires_python": ">=3.8,<4.0",
    "maintainer_email": "stephen@jshwisolutions.com",
    "keywords": "check,const,constant,dry,str",
    "author": "jshwi",
    "author_email": "stephen@jshwisolutions.com",
    "download_url": "https://files.pythonhosted.org/packages/e7/dc/8bb31e0b1909f567c23a358a5e6948be1940f45d963ba37f14f4bb684873/constcheck-0.9.0.tar.gz",
    "platform": null,
    "description": "constcheck\n==========\n.. image:: https://img.shields.io/badge/License-MIT-yellow.svg\n    :target: https://opensource.org/licenses/MIT\n    :alt: License\n.. image:: https://img.shields.io/pypi/v/constcheck\n    :target: https://pypi.org/project/constcheck/\n    :alt: PyPI\n.. image:: https://github.com/jshwi/constcheck/actions/workflows/build.yaml/badge.svg\n    :target: https://github.com/jshwi/constcheck/actions/workflows/build.yaml\n    :alt: Build\n.. image:: https://github.com/jshwi/constcheck/actions/workflows/codeql-analysis.yml/badge.svg\n    :target: https://github.com/jshwi/constcheck/actions/workflows/codeql-analysis.yml\n    :alt: CodeQL\n.. image:: https://results.pre-commit.ci/badge/github/jshwi/constcheck/master.svg\n   :target: https://results.pre-commit.ci/latest/github/jshwi/constcheck/master\n   :alt: pre-commit.ci status\n.. image:: https://codecov.io/gh/jshwi/constcheck/branch/master/graph/badge.svg\n    :target: https://codecov.io/gh/jshwi/constcheck\n    :alt: codecov.io\n.. image:: https://readthedocs.org/projects/constcheck/badge/?version=latest\n    :target: https://constcheck.readthedocs.io/en/latest/?badge=latest\n    :alt: readthedocs.org\n.. image:: https://img.shields.io/badge/python-3.8-blue.svg\n    :target: https://www.python.org/downloads/release/python-380\n    :alt: python3.8\n.. image:: https://img.shields.io/badge/code%20style-black-000000.svg\n    :target: https://github.com/psf/black\n    :alt: Black\n.. image:: https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336\n    :target: https://pycqa.github.io/isort/\n    :alt: isort\n.. image:: https://img.shields.io/badge/%20formatter-docformatter-fedcba.svg\n    :target: https://github.com/PyCQA/docformatter\n    :alt: docformatter\n.. image:: https://img.shields.io/badge/linting-pylint-yellowgreen\n    :target: https://github.com/PyCQA/pylint\n    :alt: pylint\n.. image:: https://img.shields.io/badge/security-bandit-yellow.svg\n    :target: https://github.com/PyCQA/bandit\n    :alt: Security Status\n.. image:: https://snyk.io/test/github/jshwi/constcheck/badge.svg\n    :target: https://snyk.io/test/github/jshwi/constcheck/badge.svg\n    :alt: Known Vulnerabilities\n.. image:: https://snyk.io/advisor/python/constcheck/badge.svg\n    :target: https://snyk.io/advisor/python/constcheck\n    :alt: constcheck\n\nCheck Python files for repeat use of strings\n--------------------------------------------\n\nEscape commas with \\\\\\\\ (\\\\ when enclosed in single quotes)\n\nDefaults can be configured in your pyproject.toml file\n\nInstallation\n------------\n\n.. code-block:: console\n\n    $ pip install constcheck\n\nUsage\n-----\n\nCommandline\n***********\n\n.. code-block:: console\n\n    usage: constcheck [-h] [-v] [-n] [-c INT] [-l INT] [-s STR] [-i LIST] [-I LIST]\n                                 [--ignore-from [FILE=LIST [FILE=LIST ...]]]\n                                 [path [path ...]]\n\n    Check Python files for repeat use of strings. Escape commas with \\\\. Defaults can be configured in\n    your pyproject.toml file.\n\n    positional arguments:\n      path                                       path(s) to check files for (default: .)\n\n    optional arguments:\n      -h, --help                                 show this help message and exit\n      -v, --version                              show program's version number and exit\n      -n, --no-ansi                              disable ansi output\n      -c INT, --count INT                        minimum number of repeat strings (default: 3)\n      -l INT, --length INT                       minimum length of repeat strings (default: 3)\n      -s STR, --string STR                       parse a string instead of a file\n      -i LIST, --ignore-strings LIST             comma separated list of strings to exclude\n      -I LIST, --ignore-files LIST               comma separated list of files to exclude\n      --ignore-from [FILE=LIST [FILE=LIST ...]]  comma separated list of strings to exclude from file\n\nAPI\n***\n\n.. code-block:: python\n\n    >>> from constcheck import constcheck\n\n.. code-block:: python\n\n    >>> EXAMPLE = \"\"\"\n    ... STRING_1 = \"Hey\"\n    ... STRING_2 = \"Hey\"\n    ... STRING_3 = \"Hey\"\n    ... STRING_4 = \"Hello\"\n    ... STRING_5 = \"Hello\"\n    ... STRING_6 = \"Hello\"\n    ... STRING_7 = \"Hello\"\n    ... STRING_8 = \"Hello, world\"\n    ... STRING_9 = \"Hello, world\"\n    ... STRING_10 = \"Hello, world\"\n    ... STRING_11 = \"Hello, world\"\n    ... STRING_12 = \"Hello, world\"\n    ... \"\"\"\n\n.. code-block:: python\n\n    >>> constcheck(string=EXAMPLE)\n    3   | Hey\n    4   | Hello\n    5   | Hello, world\n    <BLANKLINE>\n    1\n\nWith the ``count`` argument\n\n.. code-block:: python\n\n    >>> constcheck(string=EXAMPLE, count=4)\n    4   | Hello\n    5   | Hello, world\n    <BLANKLINE>\n    1\n\nWith the ``length`` argument\n\n.. code-block:: python\n\n    >>> constcheck(string=EXAMPLE, length=6)\n    5   | Hello, world\n    <BLANKLINE>\n    1\n\nWith the ``ignore_strings`` argument which accepts ``list`` of ``str`` objects\n\n.. code-block:: python\n\n    >>> constcheck(string=EXAMPLE, ignore_strings=[\"Hello, world\", \"Hello\"])\n    3   | Hey\n    <BLANKLINE>\n    1\n\nConfig\n******\n\nAll keyword arguments available to ``constcheck()`` can be configured in the pyproject.toml file\n\n.. code-block:: toml\n\n    [tool.constcheck]\n    path = \".\"\n    count = 3\n    length = 3\n    ignore_strings = [\"Hello\", \"Hello, world\"]\n    ignore_files = [\"tests/__init__.py\"]\n    filter = false\n    no_color = false\n\n    [tool.constcheck.ignore_from]\n    \"tests/__init__.py\" = [\"Hello, world\"]\n\npre-commit\n##########\n\n`constcheck` can be used as a `pre-commit <https://pre-commit.com>`_ hook\n\nIt can be added to your .pre-commit-config.yaml as follows:\n\n.. code-block:: yaml\n\n    repos:\n      - repo: https://github.com/jshwi/constcheck\n        rev: v0.7.0\n        hooks:\n          - id: constcheck\n            args:\n              - \"--count=3\"\n              - \"--length=3\"\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Check Python files for repeat use of strings",
    "version": "0.9.0",
    "project_urls": {
        "Documentation": "https://constcheck.readthedocs.io/en/latest",
        "Homepage": "https://pypi.org/project/constcheck/",
        "Repository": "https://github.com/jshwi/constcheck"
    },
    "split_keywords": [
        "check",
        "const",
        "constant",
        "dry",
        "str"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bed55080231210f864faf4eab6f5ed672b6e296c6fde203cbb638ab4c533f7b4",
                "md5": "3075ecf08779e7cbd83748004f1ad570",
                "sha256": "5360f33542e5218782331115efa7f819d7e6b5c9169a77d1a8466530396b481c"
            },
            "downloads": -1,
            "filename": "constcheck-0.9.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3075ecf08779e7cbd83748004f1ad570",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8,<4.0",
            "size": 11318,
            "upload_time": "2024-01-07T12:35:14",
            "upload_time_iso_8601": "2024-01-07T12:35:14.227585Z",
            "url": "https://files.pythonhosted.org/packages/be/d5/5080231210f864faf4eab6f5ed672b6e296c6fde203cbb638ab4c533f7b4/constcheck-0.9.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e7dc8bb31e0b1909f567c23a358a5e6948be1940f45d963ba37f14f4bb684873",
                "md5": "93f871e97f916515d2d44b48566e87d7",
                "sha256": "66698ce342f9471bc907cad61bf1f23013dfda8284eea1f8ac39880b21164274"
            },
            "downloads": -1,
            "filename": "constcheck-0.9.0.tar.gz",
            "has_sig": false,
            "md5_digest": "93f871e97f916515d2d44b48566e87d7",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8,<4.0",
            "size": 10668,
            "upload_time": "2024-01-07T12:35:16",
            "upload_time_iso_8601": "2024-01-07T12:35:16.301736Z",
            "url": "https://files.pythonhosted.org/packages/e7/dc/8bb31e0b1909f567c23a358a5e6948be1940f45d963ba37f14f4bb684873/constcheck-0.9.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-07 12:35:16",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "jshwi",
    "github_project": "constcheck",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "constcheck"
}
        
Elapsed time: 0.19353s