Skip to main content

No project description provided

Project description

Ondivi (Only diff violations)

wemake-python-styleguide PyPI version CI status Lines of code Hits-of-Code

Tired of 10,000 lint errors blocking your team from adopting code quality tools? Ondivi lets you enforce coding standards ONLY on new changes, making linter adoption possible in any legacy project.

This tool works with any linter or static code analyzer, including but not limited to:

Adopting Linters in Legacy Code

The Problem:

  • Your 200K LOC project has 5,000+ lint violations
  • Enforcing linters would block all development
  • Technical debt keeps accumulating

The Solution with Ondivi:

  1. Run your linter as usual: flake8 .
  2. Pipe to ondivi: flake8 . | ondivi --baseline=main
  3. CI fails ONLY if new changes introduce violations
  4. Old violations are ignored (for now)

Result: Clean new code, legacy gradually refactored.

Prerequisites:

Installation

pip install ondivi

Usage

Ensure you are in the root directory of your Git repository.

Run the script:

flake8 script.py | ondivi
# with ruff:
ruff check file.py --output-format=concise | ondivi

or:

flake8 script.py > violations.txt
ondivi --fromfile=violations.txt
$ ondivi --help
Usage: ondivi [OPTIONS]

  Ondivi (Only diff violations).

  Python script filtering coding violations, identified by static analysis,
  only for changed lines in a Git repo. Usage example:

  flake8 script.py | ondivi

Options:
  --baseline TEXT    Commit or branch which will contain legacy code. Program
                     filter out violations on baseline (default: "master")
  --fromfile TEXT    Path to file with violations. Expected "utf-8" encoding
  --format TEXT      Template for parsing linter messages. The template should
                     include the following named parts:

                     {filename}   The name of the file with the error/warning
                     {line_num}   The line number with the error/warning
                     (integer)

                     Example usage:

                     --format "{filename}:{line_num:d}{other}"

                     In this example, the linter message

                     "src/app_types/listable.py:23:1: UP035 Import from
                     collections.abc instead: Sequence"

                     will be recognized and parsed into the following
                     components:

                      - filename: "src/app_types/listable.py"
                      - line_num: 23
                      - other: :1: "UP035 Import from collections.abc instead:
                      Sequence"

                     Ensure that the template matches the format of the
                     messages generated by your linter.
                     (default: "{filename}:{line_num:d}{other}")
  --only-violations  Show only violations
  --help             Show this message and exit.

How it works

The script parses the Git diff output to identify the changed lines in each file.

It then filters the given coding violations to include only those violations that correspond to the changed lines.

flakeheaven and flakehell are not supported because they rely on internal flake8 API, which can lead to compatibility issues as flake8 evolves. In contrast, ondivi uses only the text output of violations and the state of Git repository, making it more robust and easier to maintain.

Flake8 on file:

$ flake8 file.py
file.py:3:1: E302 expected 2 blank lines, found 1
file.py:9:1: E302 expected 2 blank lines, found 1
file.py:10:121: E501 line too long (123 > 120 characters)
file.py:14:1: E305 expected 2 blank lines after class or function definition, found 1

Example of changes:

 from dataclasses import dataclass

 @dataclass
 class User(object):

     name: str
     age: int

 def greet(user: User):
     print('Long string in initial commit ################################################################################')
     print(f'Hello, {user.name}!')
+    print('Long string in new commit ################################################################################')

 if __name__ == '__main__':
     greet(User(345, 23))
+    greet(User('Bob', '23'))

By git diff we see, that two new lines were appended (12 and 16):

Ondivi filters out violations and shows only one for line 12:

$ flake8 script.py | ondivi
file.py:12:80: E501 line too long (119 > 79 characters)

License

This project is licensed under the MIT License. See the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ondivi-0.7.3.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ondivi-0.7.3-py3-none-any.whl (13.6 kB view details)

Uploaded Python 3

File details

Details for the file ondivi-0.7.3.tar.gz.

File metadata

  • Download URL: ondivi-0.7.3.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.13.1 Linux/6.11.0-1018-azure

File hashes

Hashes for ondivi-0.7.3.tar.gz
Algorithm Hash digest
SHA256 8a54ab5e1baf32d5e38d8f4d921e8edd9b692b57fa64ff17f917a46ac23dd4dc
MD5 594a6f298a4f7e90b8011467b79085d0
BLAKE2b-256 f03966deaa0e780adac8953bdf1e141a4bdf74a97e646050d1e3eda102456b57

See more details on using hashes here.

File details

Details for the file ondivi-0.7.3-py3-none-any.whl.

File metadata

  • Download URL: ondivi-0.7.3-py3-none-any.whl
  • Upload date:
  • Size: 13.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.13.1 Linux/6.11.0-1018-azure

File hashes

Hashes for ondivi-0.7.3-py3-none-any.whl
Algorithm Hash digest
SHA256 20e5b213e238ba91528b1842c22fe7ddb2884a7187344a767708b4936ced0e96
MD5 6818a31c5ead372501448515a62de7ef
BLAKE2b-256 484ee669c3b2bcf40e5158795b3d4092d96b9298653a080ccd45ef141dcaa116

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page