Metadata-Version: 2.4
Name: invokelint
Version: 0.19.0
Summary: Invokes Python dev tools at once.
Author-email: Yukihiko Shinoda <yuk.hik.future@gmail.com>
Maintainer-email: Yukihiko Shinoda <yuk.hik.future@gmail.com>
License: MIT License
        
        Copyright (c) 2023 Yukihiko Shinoda
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: homepage, https://github.com/yukihiko-shinoda/invoke-lint
Project-URL: repository, https://github.com/yukihiko-shinoda/invoke-lint
Keywords: autoflake,bandit,black,build,coverage,dist,docformatter,doggy,flake8,invokelint,isort,mypy,pydocstyle,pylint,pytest,radon,ruff,semgrep,xenon
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Natural Language :: English
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Security
Classifier: Topic :: Software Development
Classifier: Topic :: Software Development :: Build Tools
Classifier: Topic :: Software Development :: Documentation
Classifier: Topic :: Software Development :: Libraries
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Software Development :: Quality Assurance
Classifier: Topic :: Software Development :: Testing
Classifier: Topic :: Software Development :: Testing :: Unit
Classifier: Typing :: Typed
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: click
Requires-Dist: invoke
Requires-Dist: packagediscovery>=0.2.0
Requires-Dist: types-invoke
Provides-Extra: basic
Requires-Dist: invokelint[dist,lint,lint-deep,style,test]; extra == "basic"
Provides-Extra: dist
Requires-Dist: build; extra == "dist"
Provides-Extra: lint
Requires-Dist: bandit; python_version >= "3.7" and extra == "lint"
Requires-Dist: cohesion; extra == "lint"
Requires-Dist: dlint>=0.14.0; extra == "lint"
Requires-Dist: dodgy; extra == "lint"
Requires-Dist: flake8!=5.0.0,!=6.0.0,>=4.0.1; python_version >= "3.6" and extra == "lint"
Requires-Dist: flake8-bugbear; extra == "lint"
Requires-Dist: Flake8-pyproject; extra == "lint"
Requires-Dist: hacking>=5.0.0; python_version >= "3.8" and extra == "lint"
Requires-Dist: ruff; python_version >= "3.7" and extra == "lint"
Provides-Extra: lint-deep
Requires-Dist: mypy; extra == "lint-deep"
Requires-Dist: pylint; extra == "lint-deep"
Requires-Dist: setuptools<82.0.0; python_version == "3.9" and extra == "lint-deep"
Requires-Dist: semgrep; (python_version >= "3.9" and python_version < "3.10" or python_version >= "3.6" and platform_system == "Linux") and extra == "lint-deep"
Requires-Dist: semgrep>=1.122.0; python_version >= "3.10" and extra == "lint-deep"
Requires-Dist: setuptools<82.0.0; python_version == "3.9" and extra == "lint-deep"
Provides-Extra: style
Requires-Dist: docformatter[tomli]>=1.7.8; (python_version >= "3.10" and python_version < "3.11") and extra == "style"
Requires-Dist: docformatter>=1.7.8; python_version >= "3.11" and extra == "style"
Requires-Dist: ruff; python_version >= "3.7" and extra == "style"
Provides-Extra: style-legacy
Requires-Dist: autoflake; extra == "style-legacy"
Requires-Dist: black; python_version >= "3.7" and extra == "style-legacy"
Requires-Dist: isort; extra == "style-legacy"
Requires-Dist: pydocstyle; python_version >= "3.6" and extra == "style-legacy"
Provides-Extra: test
Requires-Dist: coverage>=3.5.4; extra == "test"
Requires-Dist: pytest; extra == "test"
Provides-Extra: xenon
Requires-Dist: flake8-polyfill; extra == "xenon"
Requires-Dist: radon<6.0.0; extra == "xenon"
Requires-Dist: xenon; extra == "xenon"
Dynamic: license-file

# Invoke Lint

[![Test](https://github.com/yukihiko-shinoda/invoke-lint/workflows/Test/badge.svg)](https://github.com/yukihiko-shinoda/invoke-lint/actions?query=workflow%3ATest)
[![CodeQL](https://github.com/yukihiko-shinoda/invoke-lint/workflows/CodeQL/badge.svg)](https://github.com/yukihiko-shinoda/invoke-lint/actions?query=workflow%3ACodeQL)
[![Code Coverage](https://qlty.sh/gh/yukihiko-shinoda/projects/invoke-lint/coverage.svg)](https://qlty.sh/gh/yukihiko-shinoda/projects/invoke-lint)
[![Maintainability](https://qlty.sh/gh/yukihiko-shinoda/projects/invoke-lint/maintainability.svg)](https://qlty.sh/gh/yukihiko-shinoda/projects/invoke-lint)
[![Dependabot](https://flat.badgen.net/github/dependabot/yukihiko-shinoda/invoke-lint?icon=dependabot)](https://github.com/yukihiko-shinoda/invoke-lint/security/dependabot)
[![Python versions](https://img.shields.io/pypi/pyversions/invokelint.svg)](https://pypi.org/project/invokelint)
[![Twitter URL](https://img.shields.io/twitter/url?style=social&url=https%3A%2F%2Fgithub.com%2Fyukihiko-shinoda%2Finvoke-lint)](http://twitter.com/share?text=Invoke%20Lint&url=https://pypi.org/project/invokelint/&hashtags=python)

Invokes Python dev tools at once.

## Attention

- The development status of this package is Beta now. It may not be able to keep backward compatibility. Be careful to use, especially for CI.
- Currently, each commands require to run in project home directory.

## Advantage

1. Covers major development tools and they are optional to install
1. Quick response for developer, slow but detail for CI
1. Available to place commands into your selected namespace

### 1. Covers major development tools and they are optional to install

You can choose which dev tool you'll install, this package doesn't force to install each of dev tools. It helps you to avoid conflicts or breaking your project's dependencies.

Supporting tools:

Linters:

- [Ruff]
- [Bandit]
- [Cohesion]
- [dodgy]
- [Flake8]
- [mypy]
- [Pylint]
- [Semgrep]
- [Xenon] (Optional, `xenon` extra)
- [radon] (Optional, `xenon` extra)
- [pydocstyle] (Optional, `style-legacy` extra)

Formatters:

- [docformatter]
- [Ruff]
- [autoflake] (If you want to use it instead of Ruff, `style-legacy` extra)
- [isort] (If you want to use it instead of Ruff, `style-legacy` extra)
- [Black] (If you want to use it instead of Ruff, `style-legacy` extra)

For test and coverage:

- [pytest]
- [Coverage.py]

Package build:

- [build]

### 2. Quick response for developer, slow but detailed for CI

The commands for each kind of tasks are designed as unified into 2 main commands:

- For developer: Runs only quick responsive dev tools at once
- For CI (or final check): Runs slow but detailed responsive tools at once

### 3. Available to place commands into your selected namespace

This doesn't pollute your comfortable namespaces of command line tools. Thanks to [Invoke], you can place commands into your selected namespace. (See: [Quickstart](#quickstart))

## Representative commands

(Note that the namespaces of following commands can be changed as you like. See: [Quickstart](#quickstart))

### `inv style`

Formats code by following tools at once:

1. [docformatter]
2. [Ruff] format
3. [Ruff] check --fix

Optionally, you can use [autoflake], [isort], and [Black] instead of [Ruff] format by `inv style --no-ruff`:

1. [docformatter]
2. [autoflake]
3. [isort]
4. [Black]
5. [Ruff] check --fix

- `inv style --check` can only check.
- `inv style --ruff` can skip `ruff check --fix`.

### `inv lint`

Runs following fast linters at once:

1. [Ruff]
2. [Bandit]
3. [dodgy]
4. [Flake8]

The format task ([described later](#inv-style)) also run before running above linters. You can skip them by `--skip-format` option. Use `--xenon` to enable [Xenon] (requires `xenon` extra), and `--pydocstyle` to enable [pydocstyle] (requires `style-legacy` extra).

### `inv lint.deep`

Runs following slow but detailed linters at once:

1. [mypy]
2. [Pylint]
3. [Semgrep]

### `inv lint.radon`

Reports [radon] both code complexity and maintainability index. (Requires `xenon` extra)

### `inv test`

Runs fast tests (which is not marked `@pytest.mark.slow`) by [pytest].

See:

- [How to mark test functions with attributes — pytest documentation]
- [Working with custom markers — pytest documentation]

### `inv test.all`

Runs all tests including those marked `@pytest.mark.slow` by [pytest].

### `inv test.cov`

Runs all tests and report those coverage by [pytest] and [Coverage.py].

It also can dump the coverage as XML or HTML format.

### `inv dist`

Builds source and wheel packages into `dist/` directory by [build].  
(Currently, not support in Windows)

See:

- [Building and Distributing Packages with Setuptools - setuptools latest documentation]
- [Package Discovery and Namespace Packages - setuptools latest documentation]

## Quickstart

### 1. Install

We should use [uv] or one of the [dependency management tools] to resolve dependencies of many dev tools.

`invokelint` publishes its supported tools as [pip extras], so you can pull them in directly. For example, in case when we use [uv], `pyproject.toml` is like below:

```toml
[dependency-groups]
dev = [
    "invokelint[basic]",
]
```

Available extras:

| Extra | Invoke task | Tools |
| --- | --- | --- |
| `basic` | core tasks | `invokelint[lint,lint-deep,style,test,dist]` |
| `lint` | `inv lint` | ruff, bandit, cohesion, dodgy, flake8 + plugins |
| `lint-deep` | `inv lint.deep` | mypy, pylint, semgrep |
| `style` | `inv style` | docformatter, ruff |
| `style-legacy` | `inv style --no-ruff`, `inv lint --pydocstyle` | autoflake, isort, black, pydocstyle |
| `test` | `inv test` / `inv test.cov` | pytest, coverage |
| `dist` | `inv dist` | build |
| `xenon` | `inv lint --xenon`, `inv lint.radon` | xenon, radon, flake8-polyfill |

then:

```console
uv sync
source .venv/bin/activate
```

### 2. Implement

Create `tasks.py` in project directory:

```python
"""Tasks for maintaining the project.

Execute 'invoke --list' for guidance on using Invoke
"""
from invoke import Collection

from invokelint import dist, lint, path, style, test

ns = Collection()
ns.add_collection(dist)
ns.add_collection(lint)
ns.add_collection(path)
ns.add_collection(style)
ns.add_collection(test)
```

Commands may be explicitly place with a different name than they were originally given via a name kwarg (or the 2nd regular arg):

```python
ns.add_collection(lint, 'namespace-you-wish')
```

See: [Constructing namespaces — Invoke documentation]

### 3. Check installation

```console
inv --list
```

### 4. Setup target package

This package reuses `setuptools` settings for package discovery for linting, formatting, and measuring coverage. You can check which package are discovered by `setuptools` and your project's settings, by following command:

```console
$ inv path
Setuptools detected packages: ['invokelint', 'invokelint.path']
Root packages: ['invokelint']
Setuptools detected Python modules: ['setup', 'tasks']
Existing test packages: ['tests']
Python file or directories to lint: ['invokelint', 'setup.py', 'tasks.py', 'tests']
Python file or directories to lint excluding test packages: ['invokelint', 'setup.py', 'tasks.py']
```

If result is not your expected, follow official documentation of `setuptools` to configure `pyproject.toml` (recommended), `setup.cfg`, or `setup.py`.

See: [Package Discovery and Namespace Packages - setuptools latest documentation]

### 5. Set up CI/CD workflows

This package provides reusable GitHub Actions workflows. Create the following files in `.github/workflows/`:

**`.github/workflows/test.yml`** — runs tests and linters on push/PR to `main`:

```yaml
name: Test
on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main
permissions:
  contents: read
jobs:
  call-workflow-test:
    uses: yukihiko-shinoda/reusable-workflow-invoke-lint-test/.github/workflows/workflow.yml@v1
    with:
      support-python-versions: "[ '3.14', '3.13', '3.12', '3.11', '3.10' ]"
  call-workflow-lint:
    uses: yukihiko-shinoda/reusable-workflow-invoke-lint-lint/.github/workflows/workflow.yml@v1
```

**`.github/workflows/qlty.yml`** — uploads coverage to [Qlty] on push to `main`:

```yaml
on:
  push:
    branches:
      - main
# For OIDC token exchange with Qlty:
# - Configuring OpenID Connect in cloud providers - GitHub Docs
#   https://docs.github.com/en/actions/how-tos/secure-your-work/security-harden-deployments/oidc-in-cloud-providers#adding-permissions-settings
permissions:
  contents: read
  id-token: write
jobs:
  analyze:
    uses: yukihiko-shinoda/reusable-workflow-invoke-lint-qlty/.github/workflows/workflow.yml@v1
    permissions:
      contents: read
      id-token: write
```

**`.github/workflows/deploy.yml`** — publishes to PyPI on version tag push (`v*.*.*`):

```yaml
on:
  push:
    tags:
      - 'v[0-9]+.[0-9]+.[0-9]+'
permissions:
  contents: read
jobs:
  call-workflow:
    uses: yukihiko-shinoda/reusable-workflow-invoke-lint-deploy/.github/workflows/workflow.yml@v1
    secrets:
      pypi_password: ${{ secrets.pypi_password }}
```

Check the respective repositories for the latest commit hashes if you want to use them for lock:

- [reusable-workflow-invoke-lint-test]
- [reusable-workflow-invoke-lint-lint]
- [reusable-workflow-invoke-lint-qlty]
- [reusable-workflow-invoke-lint-deploy]

<!-- markdownlint-disable no-trailing-punctuation -->
## How do I...
<!-- markdownlint-enable no-trailing-punctuation -->

### Suppress [`B101: assert_used`] in Bandit and [`assert (S101)`] in Ruff only in test files?

Set below configuration in `pyproject.toml`:

```toml
[tool.bandit.assert_used]
skips = ["tests/*"]

[tool.ruff.lint.per-file-ignores]
"tests/*" = ["S101"]
```

Note that invoke-lint executes [Bandit] with option `--configfile=pyproject.toml`, so upper configuration will be applied.

See: [Configuration — Bandit documentation]

## Credits

This package was created with [Cookiecutter] and the [yukihiko-shinoda/cookiecutter-pypackage] project template.

[Cookiecutter]: https://github.com/audreyr/cookiecutter
[yukihiko-shinoda/cookiecutter-pypackage]: https://github.com/audreyr/cookiecutter-pypackage
[Invoke]: https://pypi.org/project/invoke/
[dependency management tools]: https://packaging.python.org/en/latest/tutorials/managing-dependencies/
[uv]: https://pypi.org/project/uv/
[Ruff]: https://pypi.org/project/ruff/
[Bandit]: https://pypi.org/project/bandit/
[Cohesion]: https://pypi.org/project/cohesion/
[dodgy]: https://pypi.org/project/dodgy/
[Flake8]: https://pypi.org/project/flake8/
[pydocstyle]: https://pypi.org/project/pydocstyle/
[Xenon]: https://pypi.org/project/xenon/
[Pylint]: https://pypi.org/project/pylint/
[mypy]: https://pypi.org/project/mypy/
[Semgrep]: https://pypi.org/project/semgrep/
[radon]: https://pypi.org/project/radon/
[docformatter]: https://pypi.org/project/docformatter/
[isort]: https://pypi.org/project/isort/
[autoflake]: https://pypi.org/project/autoflake/
[Black]: https://pypi.org/project/black/
[pytest]: https://pypi.org/project/pytest/
[How to mark test functions with attributes — pytest documentation]: https://docs.pytest.org/en/latest/how-to/mark.html
[Working with custom markers — pytest documentation]: https://docs.pytest.org/en/latest/example/markers.html
[Coverage.py]: https://pypi.org/project/coverage/
[build]: https://pypi.org/project/build/
[Building and Distributing Packages with Setuptools - setuptools latest documentation]: https://setuptools.pypa.io/en/latest/setuptools.html
[Package Discovery and Namespace Packages - setuptools latest documentation]: https://setuptools.pypa.io/en/latest/userguide/package_discovery.html
[Constructing namespaces — Invoke documentation]: https://docs.pyinvoke.org/en/latest/concepts/namespaces.html#nesting-collections
[`B101: assert_used`]: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
[`assert (S101)`]: https://docs.astral.sh/ruff/rules/assert/
[Configuration — Bandit documentation]: https://bandit.readthedocs.io/en/latest/config.html#scanning-behavior
[Qlty]: https://qlty.sh
[reusable-workflow-invoke-lint-test]: https://github.com/yukihiko-shinoda/reusable-workflow-invoke-lint-test
[reusable-workflow-invoke-lint-lint]: https://github.com/yukihiko-shinoda/reusable-workflow-invoke-lint-lint
[reusable-workflow-invoke-lint-qlty]: https://github.com/yukihiko-shinoda/reusable-workflow-invoke-lint-qlty
[reusable-workflow-invoke-lint-deploy]: https://github.com/yukihiko-shinoda/reusable-workflow-invoke-lint-deploy
[pip extras]: https://pip.pypa.io/en/stable/cli/pip_install/#extras
