pyproject-pre-commit


Namepyproject-pre-commit JSON
Version 0.3.6 PyPI version JSON
download
home_pageNone
Summarypre-commit hooks for python projects using pyproject.toml.
upload_time2024-12-14 15:01:13
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9.0
licenseApache-2.0
keywords pre-commit pyproject.toml uv
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pyproject-pre-commit<a name="pyproject-pre-commit"></a>

[![test](https://github.com/rcmdnk/pyproject-pre-commit/actions/workflows/test.yml/badge.svg)](https://github.com/rcmdnk/pyproject-pre-commit/actions/workflows/test.yml)
[![test coverage](https://img.shields.io/badge/coverage-check%20here-blue.svg)](https://github.com/rcmdnk/pyproject-pre-commit/tree/coverage)

[pre-commit](https://pre-commit.com/) hooks for python projects.

**.pre-commit-hooks.yaml** provides pre-defined ids which you just need to add these ids to your **.pre-commit-config.yaml**.

By installing **pyproject-pre-commit** package,
all necessary tools are installed as dependencies.

<!-- mdformat-toc start --slug=github --maxlevel=6 --minlevel=2 -->

- [Requirement](#requirement)
- [Usage](#usage)
  - [Install pyproject-pre-commit](#install-pyproject-pre-commit)
  - [Install pyproject-pre-commit with ruff](#install-pyproject-pre-commit-with-ruff)
  - [Prepare .pre-commit-config.yaml](#prepare-pre-commit-configyaml)
  - [Run pre-commit](#run-pre-commit)
- [Available ids](#available-ids)
- [Options for tools](#options-for-tools)
- [pyproject.toml](#pyprojecttoml)

<!-- mdformat-toc end -->

## Requirement<a name="requirement"></a>

- Python >= 3.9.0
- Poetry (For development)

## Usage<a name="usage"></a>

### Install pyproject-pre-commit<a name="install-pyproject-pre-commit"></a>

If your project uses poetry, do:

```
$ poetry add --group dev pyproject-pre-commit
```

Otherwise, install the package in your working environment.

If you use pip, do:

```
$ pip install pyproject-pre-commit
```

This will install tools for pre-commit hooks in your working environment,
so that you can use these tools, such as black, directly.

### Install pyproject-pre-commit with ruff<a name="install-pyproject-pre-commit-with-ruff"></a>

If you want to use ruff, you can install pyproject-pre-commit with ruff option.

```
$ poetry add --group dev "pyproject-pre-commit[ruff]"
```

```
$ pip install pyproject-pre-commit[ruff]
```

### Prepare .pre-commit-config.yaml<a name="prepare-pre-commit-configyaml"></a>

Add **https://github.com/rcmdnk/pyproject-pre-commit** to your **.pre-commit-config.yaml**, like:

```yaml
repos:
  - repo: https://github.com/rcmdnk/pyproject-pre-commit
    rev: v0.3.0
    hooks:
      - id: black-diff
      - id: black
      - id: blacken-docs
      - id: autoflake-diff
      - id: autoflake
      - id: autopep8-diff
      - id: autopep8
      - id: isort-diff
      - id: isort
      - id: flake8
      - id: bandit
      - id: mypy
      - id: shellcheck
      - id: mdformat-check
      - id: mdformat
```

By using **pyproject-pre-commit**, you can simplify your **.pre-commit-config.yaml**
that you need only repo of **https://github.com/rcmdnk/pyproject-pre-commit**.

These hooks uses local installation of tools, so pre-commit will use
tools installed in your working environment.

This can be made by `ppc` command:

```
$ ppc --pre-commit > .pre-commit-config.yaml
```

> \[!NOTE\]
> If you are using poetry, run `poetry run ppc ... ` or run after `poetry shell`.

If you already have it, add hooks w/o `repos:` by

```
$ ppc --pre-commit |grep -v "^repos:" >> .pre-commit-config.yaml
```

You may want to modify after adding these configurations.

To use `ruff` instead of such as `black`, `flake8`, `isort`, add following hooks:

```yaml
repos:
  - repo: https://github.com/rcmdnk/pyproject-pre-commit
    rev: v0.3.0
    hooks:
      - id: ruff-lint-diff
      - id: ruff-lint
      - id: ruff-format-diff
      - id: ruff-format
      - id: mypy
      - id: shellcheck
      - id: mdformat-check
      - id: mdformat
```

This can be made by `ppc` command:

```
$ ppc --pre-commit --ruff > .pre-commit-config.yaml
```

### Run pre-commit<a name="run-pre-commit"></a>

`pre-commit` command is installed as dependencies of **pyproject-pre-commit** package.

After installing **pyproject-pre-commit** package, you can run `pre-commit` command.

First, install pre-commit hooks by:

```
$ pre-commit install
```

then you can run pre-commit by:

```
$ pre-commit run --all-files
```

> \[!NOTE\]
> If you are using poetry, run `poetry run pre-commit ... ` or run after `poetry shell`.

## Available ids<a name="available-ids"></a>

You can find ids in **.pre-commit-hooks.yaml**.

There are ids for following tools:

- For Python
  - [black-diff](https://black.readthedocs.io/en/stable): Just show Black result.
  - [black](https://black.readthedocs.io/en/stable): Black: The uncompromising Python code formatter.
  - [blacken-docs](https://github.com/adamchainz/blacken-docs): Run `black` on python code blocks in documentation files.
  - [autoflake-diff](https://github.com/PyCQA/autoflake): Just show autoflake result.
  - [autoflake](https://github.com/PyCQA/autoflake): autoflake removes unused imports and unused variables from Python code.
  - [autopep8-diff](https://github.com/hhatto/autopep8): Just show autopep8.
  - [autopep8](https://github.com/hhatto/autopep8): autopep8 automatically formats Python code to conform to the PEP 8 style guide.
  - [isort-diff](https://github.com/PyCQA/isort): Just show isort result.
  - [isort](https://github.com/PyCQA/isort): isort your imports, so you don't have to.
  - [flake8](https://github.com/PyCQA/flake8): `flake8` is a command-line utility for enforcing style consistency across Python projects.
    - With following plugins:
      - [flake8-pyproject](https://github.com/csachs/pyproject-flake8)
      - [flake8-annotations-complexity](https://github.com/best-doctor/flake8-annotations-complexity)
      - [flake8-bugbear](https://github.com/PyCQA/flake8-bugbear)
      - [flake8-builtins](https://github.com/gforcada/flake8-builtins)
      - [flake8-comprehensions](https://github.com/adamchainz/flake8-comprehensions)
      - [flake8-debugger](https://github.com/jbkahn/flake8-debugger)
      - [flake8-docstrings](https://github.com/pycqa/flake8-docstrings)
      - [flake8-executable](https://github.com/xuhdev/flake8-executable)
      - [flake8-pep3101](https://github.com/gforcada/flake8-pep3101)
      - [flake8-print](https://github.com/jbkahn/flake8-print)
      - [flake8-rst-docstrings](https://github.com/peterjc/flake8-rst-docstrings)
      - [flake8-string-format](https://github.com/xZise/flake8-string-format)
      - [pep8-naming](https://github.com/PyCQA/pep8-naming)
      - [pycodestyle](https://pycodestyle.pycqa.org/en/latest/)
  - [bandit](https://github.com/PyCQA/bandit): Bandit is a tool for finding common security issues in Python code.
  - [mypy](https://www.mypy-lang.org/): Mypy is a static type checker for Python.
  - [ruff-lint-diff](https://docs.astral.sh/ruff/): Just show ruff check result.
  - [ruff-lint](https://docs.astral.sh/ruff/): Fix by ruff for lint.
  - [ruff-format-diff](https://docs.astral.sh/ruff/): Just show ruff format result.
  - [ruff-format](https://docs.astral.sh/ruff/): Format by ruff.
- For Shell script
  - [shellcheck](https://www.shellcheck.net/): ShellCheck - A shell script static analysis tool
- For Markdown
  - mdformat-check: Just show mdformat result.
  - [mdformat](https://mdformat.readthedocs.io/en/stable/): CommonMark compliant Markdown formatter.
    - with following plugins:
      - [mdformat-gfm](https://github.com/hukkin/mdformat-gfm)
      - [mdformat-frontmatter](https://github.com/butler54/mdformat-frontmatter)
      - [mdformat-footnote](https://github.com/executablebooks/mdformat-footnote)

All tools are installed as dependencies of **pyproject-pre-commit** package.

shellcheck and mdformat are given in addition to python tools
as they can be managed by pip and most projects have README.md
and some have shell scripts.

For tools which can format files, there are additional ids with `-diff` or `--check`
which show the results before modifying files.
You can see the differences after formatting if you place these ids before ids w/o `--diff` or `--check`.

## Options for tools<a name="options-for-tools"></a>

You can set options in pyproject.toml for all tools above.

For flake8, flake8-pyproject allows to read options from pyproject.toml

About bandit, there is a plugin for the flake8, but plugin version does not read options from pyproject.toml even with pyproject.toml. Therefore, use bandit directly and give `-c pyproject.toml` option in the hooks.

## pyproject.toml<a name="pyprojecttoml"></a>

You can set options in pyproject.toml for all tools.

Example options can be made by `ppc` command:

```
$ ppc --pyproject >> pyproject.toml
```

or

```
$ ppc --pyproject --ruff >> pyproject.toml
```

You may want to modify after adding these configurations.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "pyproject-pre-commit",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9.0",
    "maintainer_email": null,
    "keywords": "pre-commit, pyproject.toml, uv",
    "author": null,
    "author_email": "rcmdnk <rcmdnk@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/15/fd/4b0a5ecba5be3cf6121eb380e8b9eafafa2e1ed0510cc6a53da14f90e297/pyproject_pre_commit-0.3.6.tar.gz",
    "platform": null,
    "description": "# pyproject-pre-commit<a name=\"pyproject-pre-commit\"></a>\n\n[![test](https://github.com/rcmdnk/pyproject-pre-commit/actions/workflows/test.yml/badge.svg)](https://github.com/rcmdnk/pyproject-pre-commit/actions/workflows/test.yml)\n[![test coverage](https://img.shields.io/badge/coverage-check%20here-blue.svg)](https://github.com/rcmdnk/pyproject-pre-commit/tree/coverage)\n\n[pre-commit](https://pre-commit.com/) hooks for python projects.\n\n**.pre-commit-hooks.yaml** provides pre-defined ids which you just need to add these ids to your **.pre-commit-config.yaml**.\n\nBy installing **pyproject-pre-commit** package,\nall necessary tools are installed as dependencies.\n\n<!-- mdformat-toc start --slug=github --maxlevel=6 --minlevel=2 -->\n\n- [Requirement](#requirement)\n- [Usage](#usage)\n  - [Install pyproject-pre-commit](#install-pyproject-pre-commit)\n  - [Install pyproject-pre-commit with ruff](#install-pyproject-pre-commit-with-ruff)\n  - [Prepare .pre-commit-config.yaml](#prepare-pre-commit-configyaml)\n  - [Run pre-commit](#run-pre-commit)\n- [Available ids](#available-ids)\n- [Options for tools](#options-for-tools)\n- [pyproject.toml](#pyprojecttoml)\n\n<!-- mdformat-toc end -->\n\n## Requirement<a name=\"requirement\"></a>\n\n- Python >= 3.9.0\n- Poetry (For development)\n\n## Usage<a name=\"usage\"></a>\n\n### Install pyproject-pre-commit<a name=\"install-pyproject-pre-commit\"></a>\n\nIf your project uses poetry, do:\n\n```\n$ poetry add --group dev pyproject-pre-commit\n```\n\nOtherwise, install the package in your working environment.\n\nIf you use pip, do:\n\n```\n$ pip install pyproject-pre-commit\n```\n\nThis will install tools for pre-commit hooks in your working environment,\nso that you can use these tools, such as black, directly.\n\n### Install pyproject-pre-commit with ruff<a name=\"install-pyproject-pre-commit-with-ruff\"></a>\n\nIf you want to use ruff, you can install pyproject-pre-commit with ruff option.\n\n```\n$ poetry add --group dev \"pyproject-pre-commit[ruff]\"\n```\n\n```\n$ pip install pyproject-pre-commit[ruff]\n```\n\n### Prepare .pre-commit-config.yaml<a name=\"prepare-pre-commit-configyaml\"></a>\n\nAdd **https://github.com/rcmdnk/pyproject-pre-commit** to your **.pre-commit-config.yaml**, like:\n\n```yaml\nrepos:\n  - repo: https://github.com/rcmdnk/pyproject-pre-commit\n    rev: v0.3.0\n    hooks:\n      - id: black-diff\n      - id: black\n      - id: blacken-docs\n      - id: autoflake-diff\n      - id: autoflake\n      - id: autopep8-diff\n      - id: autopep8\n      - id: isort-diff\n      - id: isort\n      - id: flake8\n      - id: bandit\n      - id: mypy\n      - id: shellcheck\n      - id: mdformat-check\n      - id: mdformat\n```\n\nBy using **pyproject-pre-commit**, you can simplify your **.pre-commit-config.yaml**\nthat you need only repo of **https://github.com/rcmdnk/pyproject-pre-commit**.\n\nThese hooks uses local installation of tools, so pre-commit will use\ntools installed in your working environment.\n\nThis can be made by `ppc` command:\n\n```\n$ ppc --pre-commit > .pre-commit-config.yaml\n```\n\n> \\[!NOTE\\]\n> If you are using poetry, run `poetry run ppc ... ` or run after `poetry shell`.\n\nIf you already have it, add hooks w/o `repos:` by\n\n```\n$ ppc --pre-commit |grep -v \"^repos:\" >> .pre-commit-config.yaml\n```\n\nYou may want to modify after adding these configurations.\n\nTo use `ruff` instead of such as `black`, `flake8`, `isort`, add following hooks:\n\n```yaml\nrepos:\n  - repo: https://github.com/rcmdnk/pyproject-pre-commit\n    rev: v0.3.0\n    hooks:\n      - id: ruff-lint-diff\n      - id: ruff-lint\n      - id: ruff-format-diff\n      - id: ruff-format\n      - id: mypy\n      - id: shellcheck\n      - id: mdformat-check\n      - id: mdformat\n```\n\nThis can be made by `ppc` command:\n\n```\n$ ppc --pre-commit --ruff > .pre-commit-config.yaml\n```\n\n### Run pre-commit<a name=\"run-pre-commit\"></a>\n\n`pre-commit` command is installed as dependencies of **pyproject-pre-commit** package.\n\nAfter installing **pyproject-pre-commit** package, you can run `pre-commit` command.\n\nFirst, install pre-commit hooks by:\n\n```\n$ pre-commit install\n```\n\nthen you can run pre-commit by:\n\n```\n$ pre-commit run --all-files\n```\n\n> \\[!NOTE\\]\n> If you are using poetry, run `poetry run pre-commit ... ` or run after `poetry shell`.\n\n## Available ids<a name=\"available-ids\"></a>\n\nYou can find ids in **.pre-commit-hooks.yaml**.\n\nThere are ids for following tools:\n\n- For Python\n  - [black-diff](https://black.readthedocs.io/en/stable): Just show Black result.\n  - [black](https://black.readthedocs.io/en/stable): Black: The uncompromising Python code formatter.\n  - [blacken-docs](https://github.com/adamchainz/blacken-docs): Run `black` on python code blocks in documentation files.\n  - [autoflake-diff](https://github.com/PyCQA/autoflake): Just show autoflake result.\n  - [autoflake](https://github.com/PyCQA/autoflake): autoflake removes unused imports and unused variables from Python code.\n  - [autopep8-diff](https://github.com/hhatto/autopep8): Just show autopep8.\n  - [autopep8](https://github.com/hhatto/autopep8): autopep8 automatically formats Python code to conform to the PEP 8 style guide.\n  - [isort-diff](https://github.com/PyCQA/isort): Just show isort result.\n  - [isort](https://github.com/PyCQA/isort): isort your imports, so you don't have to.\n  - [flake8](https://github.com/PyCQA/flake8): `flake8` is a command-line utility for enforcing style consistency across Python projects.\n    - With following plugins:\n      - [flake8-pyproject](https://github.com/csachs/pyproject-flake8)\n      - [flake8-annotations-complexity](https://github.com/best-doctor/flake8-annotations-complexity)\n      - [flake8-bugbear](https://github.com/PyCQA/flake8-bugbear)\n      - [flake8-builtins](https://github.com/gforcada/flake8-builtins)\n      - [flake8-comprehensions](https://github.com/adamchainz/flake8-comprehensions)\n      - [flake8-debugger](https://github.com/jbkahn/flake8-debugger)\n      - [flake8-docstrings](https://github.com/pycqa/flake8-docstrings)\n      - [flake8-executable](https://github.com/xuhdev/flake8-executable)\n      - [flake8-pep3101](https://github.com/gforcada/flake8-pep3101)\n      - [flake8-print](https://github.com/jbkahn/flake8-print)\n      - [flake8-rst-docstrings](https://github.com/peterjc/flake8-rst-docstrings)\n      - [flake8-string-format](https://github.com/xZise/flake8-string-format)\n      - [pep8-naming](https://github.com/PyCQA/pep8-naming)\n      - [pycodestyle](https://pycodestyle.pycqa.org/en/latest/)\n  - [bandit](https://github.com/PyCQA/bandit): Bandit is a tool for finding common security issues in Python code.\n  - [mypy](https://www.mypy-lang.org/): Mypy is a static type checker for Python.\n  - [ruff-lint-diff](https://docs.astral.sh/ruff/): Just show ruff check result.\n  - [ruff-lint](https://docs.astral.sh/ruff/): Fix by ruff for lint.\n  - [ruff-format-diff](https://docs.astral.sh/ruff/): Just show ruff format result.\n  - [ruff-format](https://docs.astral.sh/ruff/): Format by ruff.\n- For Shell script\n  - [shellcheck](https://www.shellcheck.net/): ShellCheck - A shell script static analysis tool\n- For Markdown\n  - mdformat-check: Just show mdformat result.\n  - [mdformat](https://mdformat.readthedocs.io/en/stable/): CommonMark compliant Markdown formatter.\n    - with following plugins:\n      - [mdformat-gfm](https://github.com/hukkin/mdformat-gfm)\n      - [mdformat-frontmatter](https://github.com/butler54/mdformat-frontmatter)\n      - [mdformat-footnote](https://github.com/executablebooks/mdformat-footnote)\n\nAll tools are installed as dependencies of **pyproject-pre-commit** package.\n\nshellcheck and mdformat are given in addition to python tools\nas they can be managed by pip and most projects have README.md\nand some have shell scripts.\n\nFor tools which can format files, there are additional ids with `-diff` or `--check`\nwhich show the results before modifying files.\nYou can see the differences after formatting if you place these ids before ids w/o `--diff` or `--check`.\n\n## Options for tools<a name=\"options-for-tools\"></a>\n\nYou can set options in pyproject.toml for all tools above.\n\nFor flake8, flake8-pyproject allows to read options from pyproject.toml\n\nAbout bandit, there is a plugin for the flake8, but plugin version does not read options from pyproject.toml even with pyproject.toml. Therefore, use bandit directly and give `-c pyproject.toml` option in the hooks.\n\n## pyproject.toml<a name=\"pyprojecttoml\"></a>\n\nYou can set options in pyproject.toml for all tools.\n\nExample options can be made by `ppc` command:\n\n```\n$ ppc --pyproject >> pyproject.toml\n```\n\nor\n\n```\n$ ppc --pyproject --ruff >> pyproject.toml\n```\n\nYou may want to modify after adding these configurations.\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "pre-commit hooks for python projects using pyproject.toml.",
    "version": "0.3.6",
    "project_urls": {
        "Documentation": "https://github.com/rcmdnk/pyproject-pre-commit",
        "Homepage": "https://github.com/rcmdnk/pyproject-pre-commit",
        "Issue": "https://github.com/rcmdnk/pyproject-pre-commit/issues",
        "Repository": "https://github.com/rcmdnk/pyproject-pre-commit"
    },
    "split_keywords": [
        "pre-commit",
        " pyproject.toml",
        " uv"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "d133f86d3b08f3cccbece1a5c78974c56b01e1702ac3182a38a05f20d5078697",
                "md5": "64cd93b23b5b6c37280e164bd5bfe5bd",
                "sha256": "66ad16b5d53060418870be49632065fd7216bbf004d363de157bf3a2f5b916d4"
            },
            "downloads": -1,
            "filename": "pyproject_pre_commit-0.3.6-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "64cd93b23b5b6c37280e164bd5bfe5bd",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9.0",
            "size": 11070,
            "upload_time": "2024-12-14T15:01:10",
            "upload_time_iso_8601": "2024-12-14T15:01:10.799940Z",
            "url": "https://files.pythonhosted.org/packages/d1/33/f86d3b08f3cccbece1a5c78974c56b01e1702ac3182a38a05f20d5078697/pyproject_pre_commit-0.3.6-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "15fd4b0a5ecba5be3cf6121eb380e8b9eafafa2e1ed0510cc6a53da14f90e297",
                "md5": "0cac138861ff83e6308d1c07418e8268",
                "sha256": "f1e89da6accb1b8a35b82236a706228ce4265efd003623fff69de6459e5e734b"
            },
            "downloads": -1,
            "filename": "pyproject_pre_commit-0.3.6.tar.gz",
            "has_sig": false,
            "md5_digest": "0cac138861ff83e6308d1c07418e8268",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9.0",
            "size": 76297,
            "upload_time": "2024-12-14T15:01:13",
            "upload_time_iso_8601": "2024-12-14T15:01:13.801599Z",
            "url": "https://files.pythonhosted.org/packages/15/fd/4b0a5ecba5be3cf6121eb380e8b9eafafa2e1ed0510cc6a53da14f90e297/pyproject_pre_commit-0.3.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-14 15:01:13",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "rcmdnk",
    "github_project": "pyproject-pre-commit",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "pyproject-pre-commit"
}
        
Elapsed time: 4.48986s