Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/periareon/rules_pylint

Bazel rules for the python linter, pylint.
https://github.com/periareon/rules_pylint

bazel bazel-rules pylint python python3

Last synced: 22 days ago
JSON representation

Bazel rules for the python linter, pylint.

Awesome Lists containing this project

README

        

# rules_pylint

## Overview

Rules for the Python linter [pylint][pl]

### Setup

To setup the rules for `pylint`, define a [py_pylint_toolchain](#py_pylint_toolchain) within your
project and register it within your workspace. For example say you have the following `BUILD.bazel`
file in the root of your workspace:

```python
load("@rules_pylint//python/pylint:defs.bzl", "py_pylint_toolchain")

py_pylint_toolchain(
name = "py_pylint_toolchain",
pylint = "@pip_deps//:pylint",
)

toolchain(
name = "toolchain",
toolchain = ":py_pylint_toolchain",
toolchain_type = "@rules_pylint//python/pylint:toolchain_type",
visibility = ["//visibility:public"],
)
```

You would then add the following to your `WORKSPACE.bazel` file.

```python
register_toolchains("//tools/pylint:toolchain")
```

In addition to this formatter, a check can be added to your build phase using the [py_pylint_aspect](#py_pylint_aspect)
aspect. Simply add the following to a `.bazelrc` file to enable this check.

```text
build --aspects=@rules_pylint//python/pylint:defs.bzl%py_pylint_aspect
build --output_groups=+py_pylint_checks
```

These rules use a global flag to determine the location of the configuration file to use with pylint. To wire up a custom
config file, simply add the following to your `.bazelrc` file

```text
build --@rules_pylint//python/pylint:config=//:pylintrc
```

Note the flag above assumes you have a `pylintrc` in the root of your repository.

It's recommended to only enable this aspect in your CI environment so formatting issues do not
impact user's ability to rapidly iterate on changes.

[pl]: https://pylint.pycqa.org/en/latest/

## Rules

- [py_pylint_aspect](#py_pylint_aspect)
- [py_pylint_test](#py_pylint_test)
- [py_pylint_toolchain](#py_pylint_toolchain)

---

---

## py_pylint_test


py_pylint_test(name, config, target)

A rule for running pylint on a Python target.

**ATTRIBUTES**

| Name | Description | Type | Mandatory | Default |
| :------------- | :------------- | :------------- | :------------- | :------------- |
| name | A unique name for this target. | Name | required | |
| config | The config file (pylintrc) containing pylint settings. | Label | optional | `"@rules_pylint//python/pylint:config"` |
| target | The target to run `pylint` on. | Label | required | |

## py_pylint_toolchain


py_pylint_toolchain(name, pylint)

A toolchain for the [pylint](https://pylint.readthedocs.io/en/stable/) formatter rules.

**ATTRIBUTES**

| Name | Description | Type | Mandatory | Default |
| :------------- | :------------- | :------------- | :------------- | :------------- |
| name | A unique name for this target. | Name | required | |
| pylint | The pylint `py_library` to use with the rules. | Label | required | |

## py_pylint_aspect


py_pylint_aspect(name)

An aspect for running pylint on targets with Python sources.

**ASPECT ATTRIBUTES**

**ATTRIBUTES**

| Name | Description | Type | Mandatory | Default |
| :------------- | :------------- | :------------- | :------------- | :------------- |
| name | A unique name for this target. | Name | required | |