black-codeclimate


Nameblack-codeclimate JSON
Version 1.0.3 PyPI version JSON
download
home_pagehttps://github.com/steinuil/black-codeclimate
SummaryConvert black --diff output to a Code Climate report
upload_time2024-02-27 12:26:44
maintainer
docs_urlNone
authorsteinuil
requires_python>=3.8,<4.0
licenseMIT
keywords black codeclimate gitlab gitlab-ci code quality
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # `black-codeclimate`

[![PyPI version](https://badge.fury.io/py/black-codeclimate.svg)](https://badge.fury.io/py/black-codeclimate)

Convert the output of `black --diff` to a report conforming to the [Code Climate spec](https://github.com/codeclimate/platform/blob/master/spec/analyzers/SPEC.md).
It is made to be used in GitLab CI to generate a [Code Quality report](https://docs.gitlab.com/ee/ci/testing/code_quality.html), which will show a nice widget in merge requests listing the file and the lines affected by the reformatting.

`black-codeclimate` uses [unidiff](https://pypi.org/project/unidiff/) to parse a diff file and detect changes, and outputs a JSON array of Code Climate issue objects reporting the filename and line range of the change. In theory it could be used on any unified diff data, but I only tested it with `black --diff`'s output. Hit me up in the issues if you use it for anything else :)

## Usage

Pipe the output of `black --diff` into `black-codeclimate`:

```bash
black --diff src/ | black-codeclimate > black_report.json
```

Or specify a file to use as input:

```bash
black-codeclimate black.diff > black_report.json
```

You can also change the severity, description and check_name of the issues in the resulting report by specifying command line flags:

```bash
black-codeclimate --severity blocker --description "would reformat [black]" --check-name "black" black.diff > black_report.json
```

Run `black-codeclimate -h` to see a list of the available flags.

## Adding it to GitLab

Add this step to your `.gitlab-ci.yml` file:

```yaml
lint:black:
  stage: lint
  before_script:
    - # Install black and black-codeclimate...
  script:
    # --check fails the job if any inconsistent formatting is detected.
    - black --diff --check src/ > black.diff
  after_script:
    - black-codeclimate black.diff > black_report.json
  artifacts:
    reports:
      codequality: black_report.json
    when: always
```

This will upload the `black_report.json` as a GitLab Code Quality artifact. The lines that would be reformatted by `black` will show up as a [merge request widget](https://docs.gitlab.com/ee/ci/testing/code_quality.html#merge-request-widget).

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/steinuil/black-codeclimate",
    "name": "black-codeclimate",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8,<4.0",
    "maintainer_email": "",
    "keywords": "Black,CodeClimate,GitLab,GitLab-CI,Code Quality",
    "author": "steinuil",
    "author_email": "steenuil.owl@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/7a/1a/453564deb8a0849d9e9a02f79b3a11a37c9c82eae20837b23426dd942a0d/black_codeclimate-1.0.3.tar.gz",
    "platform": null,
    "description": "# `black-codeclimate`\n\n[![PyPI version](https://badge.fury.io/py/black-codeclimate.svg)](https://badge.fury.io/py/black-codeclimate)\n\nConvert the output of `black --diff` to a report conforming to the [Code Climate spec](https://github.com/codeclimate/platform/blob/master/spec/analyzers/SPEC.md).\nIt is made to be used in GitLab CI to generate a [Code Quality report](https://docs.gitlab.com/ee/ci/testing/code_quality.html), which will show a nice widget in merge requests listing the file and the lines affected by the reformatting.\n\n`black-codeclimate` uses [unidiff](https://pypi.org/project/unidiff/) to parse a diff file and detect changes, and outputs a JSON array of Code Climate issue objects reporting the filename and line range of the change. In theory it could be used on any unified diff data, but I only tested it with `black --diff`'s output. Hit me up in the issues if you use it for anything else :)\n\n## Usage\n\nPipe the output of `black --diff` into `black-codeclimate`:\n\n```bash\nblack --diff src/ | black-codeclimate > black_report.json\n```\n\nOr specify a file to use as input:\n\n```bash\nblack-codeclimate black.diff > black_report.json\n```\n\nYou can also change the severity, description and check_name of the issues in the resulting report by specifying command line flags:\n\n```bash\nblack-codeclimate --severity blocker --description \"would reformat [black]\" --check-name \"black\" black.diff > black_report.json\n```\n\nRun `black-codeclimate -h` to see a list of the available flags.\n\n## Adding it to GitLab\n\nAdd this step to your `.gitlab-ci.yml` file:\n\n```yaml\nlint:black:\n  stage: lint\n  before_script:\n    - # Install black and black-codeclimate...\n  script:\n    # --check fails the job if any inconsistent formatting is detected.\n    - black --diff --check src/ > black.diff\n  after_script:\n    - black-codeclimate black.diff > black_report.json\n  artifacts:\n    reports:\n      codequality: black_report.json\n    when: always\n```\n\nThis will upload the `black_report.json` as a GitLab Code Quality artifact. The lines that would be reformatted by `black` will show up as a [merge request widget](https://docs.gitlab.com/ee/ci/testing/code_quality.html#merge-request-widget).\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Convert black --diff output to a Code Climate report",
    "version": "1.0.3",
    "project_urls": {
        "Homepage": "https://github.com/steinuil/black-codeclimate",
        "Repository": "https://github.com/steinuil/black-codeclimate"
    },
    "split_keywords": [
        "black",
        "codeclimate",
        "gitlab",
        "gitlab-ci",
        "code quality"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "18d93eb2af0c8cf3e5020e894cf684f9f38b0ee592ff96b876b38c24be736935",
                "md5": "d63557d20ba6e94a33f0cb459b7e621c",
                "sha256": "d99caf76f4c53d4e0ec513f6bc2cf58cca7c977cef36bf57e8d5143b6aee7521"
            },
            "downloads": -1,
            "filename": "black_codeclimate-1.0.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d63557d20ba6e94a33f0cb459b7e621c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8,<4.0",
            "size": 5451,
            "upload_time": "2024-02-27T12:26:43",
            "upload_time_iso_8601": "2024-02-27T12:26:43.920731Z",
            "url": "https://files.pythonhosted.org/packages/18/d9/3eb2af0c8cf3e5020e894cf684f9f38b0ee592ff96b876b38c24be736935/black_codeclimate-1.0.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7a1a453564deb8a0849d9e9a02f79b3a11a37c9c82eae20837b23426dd942a0d",
                "md5": "69c202b61b711d2135bdc348369c41d4",
                "sha256": "1cccba9928561502349e5b6c2d6f69b9c3cdd2f8a54864068a4b281c432e5055"
            },
            "downloads": -1,
            "filename": "black_codeclimate-1.0.3.tar.gz",
            "has_sig": false,
            "md5_digest": "69c202b61b711d2135bdc348369c41d4",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8,<4.0",
            "size": 4257,
            "upload_time": "2024-02-27T12:26:44",
            "upload_time_iso_8601": "2024-02-27T12:26:44.949695Z",
            "url": "https://files.pythonhosted.org/packages/7a/1a/453564deb8a0849d9e9a02f79b3a11a37c9c82eae20837b23426dd942a0d/black_codeclimate-1.0.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-27 12:26:44",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "steinuil",
    "github_project": "black-codeclimate",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "black-codeclimate"
}
        
Elapsed time: 0.24145s