pylint-silent


Namepylint-silent JSON
Version 1.4.1 PyPI version JSON
download
home_pageNone
SummaryAutomatically add code comments to silence the output of pylint
upload_time2024-04-29 00:46:00
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseGPL-2.0-or-later
keywords pylint
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pylint-silent
**Automatically add code comments to silence the output of [pylint](https://github.com/PyCQA/pylint).**

`pylint` can be very useful in finding software bugs in python code. A good article demonstrating this is [Why Pylint is both useful and unusable, and how you can actually use it](https://pythonspeed.com/articles/pylint/). In short, when running `pylint` on existing code, it tends to output tons of messages.

`pylint-silent` is suppose to make `pylint` usable. The idea is to automatically add code comments of the form `# pylint: disable` to silent every `pylint` message. This will allow you to deploy `pylint` in a Continuous Integration (CI) setup. If a code commit introduces **new** `pylint` messages, these will be visible immediately.

On top of that, all existing `pylint` messages will show up as comments in the code. When you work on a piece of code and see a `pylint` comment, you can try to fix it.

### Install
`pylint-silent` can be installed from [pypi](https://pypi.org/project/pylint-silent/):
```
pip install pylint-silent
```
### Usage
The basic workflow for running `pylint-silent` for the first time is:
```
pylint my_package > pylint.log
pylint-silent apply pylint.log
pylint my_package  # This should return a perfect 10.00 score.
```
**WARNING: `pylint-silent` modifies python files in place.
It is assumed that you are using some version control system.**

For example, if `pylint` produced this message:
```
test.py:35:10: W0613: Unused argument 'name' (unused-argument)
```

`pylint-silent` would add this comment:
```
def func(name):  # pylint: disable=unused-argument
```

If adding the comment would make the line too long, `pylint-silent` would instead add:
```
# pylint: disable-next=unused-argument
def very-long-function-name-with-some-arguments(first_argument, second_argument):
```
`--max-line-length` specfies the maximum line length.
This feature is disabled by default for compatibility with previous versions.
It is disabled by having a default maximum line length of 999.
In the future the default should change to 88.

Another option is to run `pylint-silent --signature` to add a signature to each generated comment:
```
def func(name):  # pylint: disable=unused-argument; silent
```
This way you can easily identify which comments were generated by `pylint-silent`.

For subsequent runs, you probably want to clear the old comments first.
Assuming you are using signatures:
```
pylint-silent reset --signature my_package/*.py  # List all python files here
pylint my_package > pylint.log
pylint-silent apply --signature pylint.log
```

There are two reasons to clear old comments:

1. Remove stale comments to code that was already fixed.
2. `pylint-silent` does not know how to handle lines that already have a `# pylint` comment in them.

To reset or show statistics on all python files in a folder you might want to use the `find` command:
```
find my_package -name "*.py" -exec pylint-silent stats {} +
find my_package -name "*.py" -exec pylint-silent reset {} +
```

### Known limitations
In some cases `pylint-silent` may break your code:
```
FAVICON = base64.decodestring("""  # pylint: disable=deprecated-method
...
```
Luckily, you can simply run `pylint` a second time to detect such cases. In this case `pylint` would ignore the comment because it is part of the string. Therefore, the warning message would still show up. This code has to be fixed manually:
```
FAVICON = base64.decodestring(  # pylint: disable=deprecated-method
"""...
```

Another issue is that messages that involve multiple files cannot be silenced. I'm aware of two such messages:

* cyclic-import
* duplicate-code

You could just disable these messages. Personally I think that these are relevant messages. So instead I just modify `pylint` score calculation to something like:
```
evaluation=10.0 + 0.15 - 10 * ((float(5 * error + warning + refactor + convention) / statement) * 10)
```
The `0.15` artificially raises the score to 10.0 and makes `pylint` return a success code. The factor of `10 *` increases the score sensitivity, which, by default, is way too low even for a medium sized project.

`pylint` also lets you disable a checks on a block of code:
```
# pylint: disable=unused-import
import time
import sys
# pylint: enable=unused-import
```
`pylint-silent` would ignore these blocks. `pylint-silent reset` would not clear these messages and `pylint-silent stats` would not count them.

### Alternatives

An alternative solution to `pylint` noise is [pylint-ignore](https://pypi.org/project/pylint-ignore/).
Whichever option you choose, I recommend reading their documentation about how `pylint` should be used.

### Summary
`pylint`'s motto is: **It's not just a linter that annoys you!**

`pylint-silent` helps `pylint` live up to its motto.

### Changelog

#### 1.4.1 (2024-04-28)

* Preserve file permissions also during reset. Fixes #6.

#### 1.4 (2024-02-11)

* Update compatible python versions to currently supported python 3.8 through 3.12.

#### 1.3 (2023-05-12)

* Mark every pylint-silent comment with a signature. Fixes #4. PR #5.
* Add a --max-line-length option. Fixes #3.
* Fix tests for pylint 2.16. Require pylint >= 2.16 for the tests.

#### 1.2 (2022-12-23)

* Preserve comments meant for other non-pylint tools. PR #2.

#### 1.1.2 (2022-11-30)

* Use pyproject.toml instead of setup.py.
* Update compatible python versions to currently supported python 3.7 through 3.11.
* Fix bug in `pylint-silent stats` that got confused with `=` symbols in code.
* Document in README.md how to reset or get statistics on all files in folder.

#### 1.1.1 (2021-04-13)

* Preserve file permissions in generated code. Fixes #1.

#### 1.1 (2021-03-04)

* Ignore disable/enable blocks.
* Add reference to pylint-ignore in the README.
* Add testing based on pytest and tox.
* Handle missing-module-docstring correctly.

#### 1.0.1 (2020-07-22)

* Fix link from pypi.org to github.
* Fix markdown in README.md.

#### 1.0 (2020-07-20)

* Initial release.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "pylint-silent",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "pylint",
    "author": null,
    "author_email": "Udi Fuchs <udifuchs@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/5b/1a/2078e188ceef3836ab37b730ac8c803ecfbfaa07ad90a4a256e6bc023d5c/pylint_silent-1.4.1.tar.gz",
    "platform": null,
    "description": "# pylint-silent\n**Automatically add code comments to silence the output of [pylint](https://github.com/PyCQA/pylint).**\n\n`pylint` can be very useful in finding software bugs in python code. A good article demonstrating this is [Why Pylint is both useful and unusable, and how you can actually use it](https://pythonspeed.com/articles/pylint/). In short, when running `pylint` on existing code, it tends to output tons of messages.\n\n`pylint-silent` is suppose to make `pylint` usable. The idea is to automatically add code comments of the form `# pylint: disable` to silent every `pylint` message. This will allow you to deploy `pylint` in a Continuous Integration (CI) setup. If a code commit introduces **new** `pylint` messages, these will be visible immediately.\n\nOn top of that, all existing `pylint` messages will show up as comments in the code. When you work on a piece of code and see a `pylint` comment, you can try to fix it.\n\n### Install\n`pylint-silent` can be installed from [pypi](https://pypi.org/project/pylint-silent/):\n```\npip install pylint-silent\n```\n### Usage\nThe basic workflow for running `pylint-silent` for the first time is:\n```\npylint my_package > pylint.log\npylint-silent apply pylint.log\npylint my_package  # This should return a perfect 10.00 score.\n```\n**WARNING: `pylint-silent` modifies python files in place.\nIt is assumed that you are using some version control system.**\n\nFor example, if `pylint` produced this message:\n```\ntest.py:35:10: W0613: Unused argument 'name' (unused-argument)\n```\n\n`pylint-silent` would add this comment:\n```\ndef func(name):  # pylint: disable=unused-argument\n```\n\nIf adding the comment would make the line too long, `pylint-silent` would instead add:\n```\n# pylint: disable-next=unused-argument\ndef very-long-function-name-with-some-arguments(first_argument, second_argument):\n```\n`--max-line-length` specfies the maximum line length.\nThis feature is disabled by default for compatibility with previous versions.\nIt is disabled by having a default maximum line length of 999.\nIn the future the default should change to 88.\n\nAnother option is to run `pylint-silent --signature` to add a signature to each generated comment:\n```\ndef func(name):  # pylint: disable=unused-argument; silent\n```\nThis way you can easily identify which comments were generated by `pylint-silent`.\n\nFor subsequent runs, you probably want to clear the old comments first.\nAssuming you are using signatures:\n```\npylint-silent reset --signature my_package/*.py  # List all python files here\npylint my_package > pylint.log\npylint-silent apply --signature pylint.log\n```\n\nThere are two reasons to clear old comments:\n\n1. Remove stale comments to code that was already fixed.\n2. `pylint-silent` does not know how to handle lines that already have a `# pylint` comment in them.\n\nTo reset or show statistics on all python files in a folder you might want to use the `find` command:\n```\nfind my_package -name \"*.py\" -exec pylint-silent stats {} +\nfind my_package -name \"*.py\" -exec pylint-silent reset {} +\n```\n\n### Known limitations\nIn some cases `pylint-silent` may break your code:\n```\nFAVICON = base64.decodestring(\"\"\"  # pylint: disable=deprecated-method\n...\n```\nLuckily, you can simply run `pylint` a second time to detect such cases. In this case `pylint` would ignore the comment because it is part of the string. Therefore, the warning message would still show up. This code has to be fixed manually:\n```\nFAVICON = base64.decodestring(  # pylint: disable=deprecated-method\n\"\"\"...\n```\n\nAnother issue is that messages that involve multiple files cannot be silenced. I'm aware of two such messages:\n\n* cyclic-import\n* duplicate-code\n\nYou could just disable these messages. Personally I think that these are relevant messages. So instead I just modify `pylint` score calculation to something like:\n```\nevaluation=10.0 + 0.15 - 10 * ((float(5 * error + warning + refactor + convention) / statement) * 10)\n```\nThe `0.15` artificially raises the score to 10.0 and makes `pylint` return a success code. The factor of `10 *` increases the score sensitivity, which, by default, is way too low even for a medium sized project.\n\n`pylint` also lets you disable a checks on a block of code:\n```\n# pylint: disable=unused-import\nimport time\nimport sys\n# pylint: enable=unused-import\n```\n`pylint-silent` would ignore these blocks. `pylint-silent reset` would not clear these messages and `pylint-silent stats` would not count them.\n\n### Alternatives\n\nAn alternative solution to `pylint` noise is [pylint-ignore](https://pypi.org/project/pylint-ignore/).\nWhichever option you choose, I recommend reading their documentation about how `pylint` should be used.\n\n### Summary\n`pylint`'s motto is: **It's not just a linter that annoys you!**\n\n`pylint-silent` helps `pylint` live up to its motto.\n\n### Changelog\n\n#### 1.4.1 (2024-04-28)\n\n* Preserve file permissions also during reset. Fixes #6.\n\n#### 1.4 (2024-02-11)\n\n* Update compatible python versions to currently supported python 3.8 through 3.12.\n\n#### 1.3 (2023-05-12)\n\n* Mark every pylint-silent comment with a signature. Fixes #4. PR #5.\n* Add a --max-line-length option. Fixes #3.\n* Fix tests for pylint 2.16. Require pylint >= 2.16 for the tests.\n\n#### 1.2 (2022-12-23)\n\n* Preserve comments meant for other non-pylint tools. PR #2.\n\n#### 1.1.2 (2022-11-30)\n\n* Use pyproject.toml instead of setup.py.\n* Update compatible python versions to currently supported python 3.7 through 3.11.\n* Fix bug in `pylint-silent stats` that got confused with `=` symbols in code.\n* Document in README.md how to reset or get statistics on all files in folder.\n\n#### 1.1.1 (2021-04-13)\n\n* Preserve file permissions in generated code. Fixes #1.\n\n#### 1.1 (2021-03-04)\n\n* Ignore disable/enable blocks.\n* Add reference to pylint-ignore in the README.\n* Add testing based on pytest and tox.\n* Handle missing-module-docstring correctly.\n\n#### 1.0.1 (2020-07-22)\n\n* Fix link from pypi.org to github.\n* Fix markdown in README.md.\n\n#### 1.0 (2020-07-20)\n\n* Initial release.\n",
    "bugtrack_url": null,
    "license": "GPL-2.0-or-later",
    "summary": "Automatically add code comments to silence the output of pylint",
    "version": "1.4.1",
    "project_urls": {
        "Homepage": "http://github.com/udifuchs/pylint-silent"
    },
    "split_keywords": [
        "pylint"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ed402efcdfe7929e7c66304ac2dafc91c43fe0c37faf877e62d9abd1125d72a5",
                "md5": "c05f5717b65394abe66835ffbb06955f",
                "sha256": "ccf994e92bbe71ae5fbd2831acbbeb238d4d82e1cd7b20bbe609990acab5acde"
            },
            "downloads": -1,
            "filename": "pylint_silent-1.4.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c05f5717b65394abe66835ffbb06955f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 7926,
            "upload_time": "2024-04-29T00:45:58",
            "upload_time_iso_8601": "2024-04-29T00:45:58.265013Z",
            "url": "https://files.pythonhosted.org/packages/ed/40/2efcdfe7929e7c66304ac2dafc91c43fe0c37faf877e62d9abd1125d72a5/pylint_silent-1.4.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5b1a2078e188ceef3836ab37b730ac8c803ecfbfaa07ad90a4a256e6bc023d5c",
                "md5": "80dab06e6bd053d4c6f33cf6b934a8d3",
                "sha256": "0872d51101d280a18113ac059feb4b3671743d8d876af31c27488254f5d1c1d4"
            },
            "downloads": -1,
            "filename": "pylint_silent-1.4.1.tar.gz",
            "has_sig": false,
            "md5_digest": "80dab06e6bd053d4c6f33cf6b934a8d3",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 9871,
            "upload_time": "2024-04-29T00:46:00",
            "upload_time_iso_8601": "2024-04-29T00:46:00.028502Z",
            "url": "https://files.pythonhosted.org/packages/5b/1a/2078e188ceef3836ab37b730ac8c803ecfbfaa07ad90a4a256e6bc023d5c/pylint_silent-1.4.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-29 00:46:00",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "udifuchs",
    "github_project": "pylint-silent",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "pylint-silent"
}
        
Elapsed time: 0.24668s