remove-print-statements


Nameremove-print-statements JSON
Version 0.5.2 PyPI version JSON
download
home_pagehttps://github.com/dhruvmanila/remove-print-statements
SummaryA command-line tool (and pre-commit hook) to remove print statements from your Python project.
upload_time2023-06-13 05:40:33
maintainer
docs_urlNone
authorDhruv Manilawala
requires_python>=3.7,<4.0
licenseMIT
keywords python codemod libcst
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <div align="center">

# remove-print-statements

[![test](https://github.com/dhruvmanila/remove-print-statements/actions/workflows/test.yml/badge.svg)](https://github.com/dhruvmanila/remove-print-statements/actions/workflows/test.yml)
[![codecov](https://codecov.io/gh/dhruvmanila/remove-print-statements/branch/main/graph/badge.svg)](https://codecov.io/gh/dhruvmanila/remove-print-statements)
[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/dhruvmanila/remove-print-statements/main.svg)](https://results.pre-commit.ci/latest/github/dhruvmanila/remove-print-statements/main)
[![PyPi Status](https://img.shields.io/pypi/v/remove-print-statements.svg?color=blue)](https://pypi.org/project/remove-print-statements/)
![Python versions](https://img.shields.io/pypi/pyversions/remove-print-statements.svg)
[![MIT License](https://img.shields.io/pypi/l/remove-print-statements.svg)](./LICENSE)

A command-line tool (and pre-commit hook) to remove all the `print` statements
from your Python project.

</div>

Do you use `print` statements for debugging? We all do, and there's nothing wrong
with it. After the bug has been resolved, we need to manually open all the files
which we added the print statements in, only if we remember all of them after
hours of debugging, and remove them. A better way would be to use some sort of
find and replace from the editor or command-line, but that's still a lot of
manual work. Worst case, it gets pushed and deployed to production.

Who wants to do all the manual work in the age of automation? No one. So,
install this tool and forget about removing the print statements manually
forever. You could either run this tool manually or add it as a `pre-commit`
hook. You could even preview the print statements along with it's location
without removing it. How nice is that!

## Installation

You can install `remove-print-statements` from the Python Package Index (PyPI)
with [`pipx`] or equivalent.

```
pipx install remove-print-statements
```

Or, try it out using [`pipx`]:

```
pipx run remove-print-statements --help
```

Or, with [pre-commit](https://pre-commit.com) in the `repos` section of your
`.pre-commit-config.yaml` file ([docs](https://pre-commit.com/#plugins)):

```yaml
- repo: https://github.com/dhruvmanila/remove-print-statements
  rev: ''  # Replace with latest tag on GitHub
  hooks:
  - id: remove-print-statements
    # args: ['--verbose']   # Show all the print statements to be removed
```

## Usage

Run it on a given set of files:
```sh
remove-print-statements foo.py bar.py ...
# or use globbing
remove-print-statements *.py
```

You can ignore files as well. To specify multiple files to ignore, use the flag
multiple times otherwise it's difficult to know the difference between the files
to ignore and the ones to check.
```sh
remove-print-statements *.py --ignore foo.py --ignore bar.py
```

You can preview the print statements which would be removed without modifying
the source files using both `--dry-run` and `--verbose` flags like so:

```console
$ remove-print-statements --dry-run --verbose test.py
test.py
  7 print("module")
  18 print("property")
  27 print("method")
  29 print("for loop")

1 file would be transformed, 4 print statements would be removed
```

`remove-print-statements` is a command-line tool that rewrites the files in
place. It focuses on upgrading your code and not on making it look nice. Run
remove-print-statements before formatters like [Black](https://black.readthedocs.io/en/stable/).

`remove-print-statements` does not have any ability to recurse through
directories. Use the pre-commit integration, globbing, or another technique for
applying to many files such as [with `git ls-files | xargs`][1].

### Single statement

If there's only a single statement in the body of a function, for/while loop, if
statement, etc., which is a print statement, then it will be replaced with the
`pass` keyword.

```diff
def foo():
-    print()
+    pass


for _ in range(5):
-    print()
+    pass

if __name__ == "__main__":
-    print()
+    pass
```

### Exit status

`remove-print-statements` command returns exit statuses as follows:

| Status       | Description                                      |
| :----------: | ------------------------------------------------ |
| 0            | No print statements / changes made successfully |
| 1            | Files would be updated (dry run)                 |
| 123          | Some error happened                              |

## Development

[![packaging: poetry](https://img.shields.io/badge/packaging-poetry-299bd7?logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAASCAYAAABrXO8xAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAJJSURBVHgBfZLPa1NBEMe/s7tNXoxW1KJQKaUHkXhQvHgW6UHQQ09CBS/6V3hKc/AP8CqCrUcpmop3Cx48eDB4yEECjVQrlZb80CRN8t6OM/teagVxYZi38+Yz853dJbzoMV3MM8cJUcLMSUKIE8AzQ2PieZzFxEJOHMOgMQQ+dUgSAckNXhapU/NMhDSWLs1B24A8sO1xrN4NECkcAC9ASkiIJc6k5TRiUDPhnyMMdhKc+Zx19l6SgyeW76BEONY9exVQMzKExGKwwPsCzza7KGSSWRWEQhyEaDXp6ZHEr416ygbiKYOd7TEWvvcQIeusHYMJGhTwF9y7sGnSwaWyFAiyoxzqW0PM/RjghPxF2pWReAowTEXnDh0xgcLs8l2YQmOrj3N7ByiqEoH0cARs4u78WgAVkoEDIDoOi3AkcLOHU60RIg5wC4ZuTC7FaHKQm8Hq1fQuSOBvX/sodmNJSB5geaF5CPIkUeecdMxieoRO5jz9bheL6/tXjrwCyX/UYBUcjCaWHljx1xiX6z9xEjkYAzbGVnB8pvLmyXm9ep+W8CmsSHQQY77Zx1zboxAV0w7ybMhQmfqdmmw3nEp1I0Z+FGO6M8LZdoyZnuzzBdjISicKRnpxzI9fPb+0oYXsNdyi+d3h9bm9MWYHFtPeIZfLwzmFDKy1ai3p+PDls1Llz4yyFpferxjnyjJDSEy9CaCx5m2cJPerq6Xm34eTrZt3PqxYO1XOwDYZrFlH1fWnpU38Y9HRze3lj0vOujZcXKuuXm3jP+s3KbZVra7y2EAAAAAASUVORK5CYII=)](https://python-poetry.org/)
[![code style: black](https://img.shields.io/static/v1?label=code%20style&message=black&color=black)](https://github.com/psf/black)
[![pre-commit: enabled](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit)

### Release

1. Run `poetry lock`
2. Bump version in `pyproject.toml` and `__version__` variable
3. Commit and push the changes with message `release: <version>`
4. Publish a new release on GitHub which will trigger an automated workflow to
   publish on PyPi

## License

remove-print-statements is licensed under the MIT License.

See [LICENSE](./LICENSE) for details.

<!-- References -->

[1]: https://adamj.eu/tech/2022/03/09/how-to-run-a-command-on-many-files-in-your-git-repository/
[`pipx`]: https://github.com/pypa/pipx

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/dhruvmanila/remove-print-statements",
    "name": "remove-print-statements",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7,<4.0",
    "maintainer_email": "",
    "keywords": "python,codemod,libCST",
    "author": "Dhruv Manilawala",
    "author_email": "dhruvmanila@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/b7/12/3910d960b598cf623033c0a0a569fe43764dba7c66a26b957ed64088797b/remove_print_statements-0.5.2.tar.gz",
    "platform": null,
    "description": "<div align=\"center\">\n\n# remove-print-statements\n\n[![test](https://github.com/dhruvmanila/remove-print-statements/actions/workflows/test.yml/badge.svg)](https://github.com/dhruvmanila/remove-print-statements/actions/workflows/test.yml)\n[![codecov](https://codecov.io/gh/dhruvmanila/remove-print-statements/branch/main/graph/badge.svg)](https://codecov.io/gh/dhruvmanila/remove-print-statements)\n[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/dhruvmanila/remove-print-statements/main.svg)](https://results.pre-commit.ci/latest/github/dhruvmanila/remove-print-statements/main)\n[![PyPi Status](https://img.shields.io/pypi/v/remove-print-statements.svg?color=blue)](https://pypi.org/project/remove-print-statements/)\n![Python versions](https://img.shields.io/pypi/pyversions/remove-print-statements.svg)\n[![MIT License](https://img.shields.io/pypi/l/remove-print-statements.svg)](./LICENSE)\n\nA command-line tool (and pre-commit hook) to remove all the `print` statements\nfrom your Python project.\n\n</div>\n\nDo you use `print` statements for debugging? We all do, and there's nothing wrong\nwith it. After the bug has been resolved, we need to manually open all the files\nwhich we added the print statements in, only if we remember all of them after\nhours of debugging, and remove them. A better way would be to use some sort of\nfind and replace from the editor or command-line, but that's still a lot of\nmanual work. Worst case, it gets pushed and deployed to production.\n\nWho wants to do all the manual work in the age of automation? No one. So,\ninstall this tool and forget about removing the print statements manually\nforever. You could either run this tool manually or add it as a `pre-commit`\nhook. You could even preview the print statements along with it's location\nwithout removing it. How nice is that!\n\n## Installation\n\nYou can install `remove-print-statements` from the Python Package Index (PyPI)\nwith [`pipx`] or equivalent.\n\n```\npipx install remove-print-statements\n```\n\nOr, try it out using [`pipx`]:\n\n```\npipx run remove-print-statements --help\n```\n\nOr, with [pre-commit](https://pre-commit.com) in the `repos` section of your\n`.pre-commit-config.yaml` file ([docs](https://pre-commit.com/#plugins)):\n\n```yaml\n- repo: https://github.com/dhruvmanila/remove-print-statements\n  rev: ''  # Replace with latest tag on GitHub\n  hooks:\n  - id: remove-print-statements\n    # args: ['--verbose']   # Show all the print statements to be removed\n```\n\n## Usage\n\nRun it on a given set of files:\n```sh\nremove-print-statements foo.py bar.py ...\n# or use globbing\nremove-print-statements *.py\n```\n\nYou can ignore files as well. To specify multiple files to ignore, use the flag\nmultiple times otherwise it's difficult to know the difference between the files\nto ignore and the ones to check.\n```sh\nremove-print-statements *.py --ignore foo.py --ignore bar.py\n```\n\nYou can preview the print statements which would be removed without modifying\nthe source files using both `--dry-run` and `--verbose` flags like so:\n\n```console\n$ remove-print-statements --dry-run --verbose test.py\ntest.py\n  7 print(\"module\")\n  18 print(\"property\")\n  27 print(\"method\")\n  29 print(\"for loop\")\n\n1 file would be transformed, 4 print statements would be removed\n```\n\n`remove-print-statements` is a command-line tool that rewrites the files in\nplace. It focuses on upgrading your code and not on making it look nice. Run\nremove-print-statements before formatters like [Black](https://black.readthedocs.io/en/stable/).\n\n`remove-print-statements` does not have any ability to recurse through\ndirectories. Use the pre-commit integration, globbing, or another technique for\napplying to many files such as [with `git ls-files | xargs`][1].\n\n### Single statement\n\nIf there's only a single statement in the body of a function, for/while loop, if\nstatement, etc., which is a print statement, then it will be replaced with the\n`pass` keyword.\n\n```diff\ndef foo():\n-    print()\n+    pass\n\n\nfor _ in range(5):\n-    print()\n+    pass\n\nif __name__ == \"__main__\":\n-    print()\n+    pass\n```\n\n### Exit status\n\n`remove-print-statements` command returns exit statuses as follows:\n\n| Status       | Description                                      |\n| :----------: | ------------------------------------------------ |\n| 0            | No print statements / changes made successfully |\n| 1            | Files would be updated (dry run)                 |\n| 123          | Some error happened                              |\n\n## Development\n\n[![packaging: poetry](https://img.shields.io/badge/packaging-poetry-299bd7?logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAASCAYAAABrXO8xAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAJJSURBVHgBfZLPa1NBEMe/s7tNXoxW1KJQKaUHkXhQvHgW6UHQQ09CBS/6V3hKc/AP8CqCrUcpmop3Cx48eDB4yEECjVQrlZb80CRN8t6OM/teagVxYZi38+Yz853dJbzoMV3MM8cJUcLMSUKIE8AzQ2PieZzFxEJOHMOgMQQ+dUgSAckNXhapU/NMhDSWLs1B24A8sO1xrN4NECkcAC9ASkiIJc6k5TRiUDPhnyMMdhKc+Zx19l6SgyeW76BEONY9exVQMzKExGKwwPsCzza7KGSSWRWEQhyEaDXp6ZHEr416ygbiKYOd7TEWvvcQIeusHYMJGhTwF9y7sGnSwaWyFAiyoxzqW0PM/RjghPxF2pWReAowTEXnDh0xgcLs8l2YQmOrj3N7ByiqEoH0cARs4u78WgAVkoEDIDoOi3AkcLOHU60RIg5wC4ZuTC7FaHKQm8Hq1fQuSOBvX/sodmNJSB5geaF5CPIkUeecdMxieoRO5jz9bheL6/tXjrwCyX/UYBUcjCaWHljx1xiX6z9xEjkYAzbGVnB8pvLmyXm9ep+W8CmsSHQQY77Zx1zboxAV0w7ybMhQmfqdmmw3nEp1I0Z+FGO6M8LZdoyZnuzzBdjISicKRnpxzI9fPb+0oYXsNdyi+d3h9bm9MWYHFtPeIZfLwzmFDKy1ai3p+PDls1Llz4yyFpferxjnyjJDSEy9CaCx5m2cJPerq6Xm34eTrZt3PqxYO1XOwDYZrFlH1fWnpU38Y9HRze3lj0vOujZcXKuuXm3jP+s3KbZVra7y2EAAAAAASUVORK5CYII=)](https://python-poetry.org/)\n[![code style: black](https://img.shields.io/static/v1?label=code%20style&message=black&color=black)](https://github.com/psf/black)\n[![pre-commit: enabled](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit)\n\n### Release\n\n1. Run `poetry lock`\n2. Bump version in `pyproject.toml` and `__version__` variable\n3. Commit and push the changes with message `release: <version>`\n4. Publish a new release on GitHub which will trigger an automated workflow to\n   publish on PyPi\n\n## License\n\nremove-print-statements is licensed under the MIT License.\n\nSee [LICENSE](./LICENSE) for details.\n\n<!-- References -->\n\n[1]: https://adamj.eu/tech/2022/03/09/how-to-run-a-command-on-many-files-in-your-git-repository/\n[`pipx`]: https://github.com/pypa/pipx\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A command-line tool (and pre-commit hook) to remove print statements from your Python project.",
    "version": "0.5.2",
    "project_urls": {
        "Bug Tracker": "https://github.com/dhruvmanila/remove-print-statements/issues",
        "Homepage": "https://github.com/dhruvmanila/remove-print-statements",
        "Repository": "https://github.com/dhruvmanila/remove-print-statements"
    },
    "split_keywords": [
        "python",
        "codemod",
        "libcst"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e5e742bf9acbaa01df7d9738f00df1037a1eeba95bcaf845485ce4e8e28e7119",
                "md5": "60d9e4aa3680284a93929ba9fcae9a27",
                "sha256": "2d9e6f56b735cb32fe1d5a1bd07f158fedbc5a0cf2fc9b6bb3728fecefd99823"
            },
            "downloads": -1,
            "filename": "remove_print_statements-0.5.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "60d9e4aa3680284a93929ba9fcae9a27",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7,<4.0",
            "size": 8656,
            "upload_time": "2023-06-13T05:40:31",
            "upload_time_iso_8601": "2023-06-13T05:40:31.938970Z",
            "url": "https://files.pythonhosted.org/packages/e5/e7/42bf9acbaa01df7d9738f00df1037a1eeba95bcaf845485ce4e8e28e7119/remove_print_statements-0.5.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b7123910d960b598cf623033c0a0a569fe43764dba7c66a26b957ed64088797b",
                "md5": "1949982a11f5463d5cfc9bb06ad58811",
                "sha256": "61c7bac7feab96c712760c11285bc73f3caa822705bc192c67235cb297f22148"
            },
            "downloads": -1,
            "filename": "remove_print_statements-0.5.2.tar.gz",
            "has_sig": false,
            "md5_digest": "1949982a11f5463d5cfc9bb06ad58811",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7,<4.0",
            "size": 7995,
            "upload_time": "2023-06-13T05:40:33",
            "upload_time_iso_8601": "2023-06-13T05:40:33.441249Z",
            "url": "https://files.pythonhosted.org/packages/b7/12/3910d960b598cf623033c0a0a569fe43764dba7c66a26b957ed64088797b/remove_print_statements-0.5.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-06-13 05:40:33",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "dhruvmanila",
    "github_project": "remove-print-statements",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "remove-print-statements"
}
        
Elapsed time: 0.07796s