Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
448dbbb
Adds ruff check
kingbuzzman May 15, 2025
fe444b5
Fixes isort
kingbuzzman May 15, 2025
cedcff1
Adds tests
kingbuzzman May 15, 2025
d0336e3
.
kingbuzzman May 15, 2025
588255b
Adds docs
kingbuzzman May 15, 2025
3b100b0
oops
kingbuzzman May 16, 2025
439a6cf
Adds ruff linting and formatting
kingbuzzman May 16, 2025
d1cbd0b
format
kingbuzzman May 16, 2025
686e18f
.
kingbuzzman May 16, 2025
a633412
Update .git-blame-ignore-revs
kingbuzzman May 16, 2025
6144651
putting it all back
kingbuzzman May 16, 2025
191134e
isort
kingbuzzman May 16, 2025
5abe6a4
Merge branch 'dev/implement-ruff' of github.com:kingbuzzman/diff_cove…
kingbuzzman May 16, 2025
8171a16
.
kingbuzzman May 16, 2025
50f1db7
.
kingbuzzman May 16, 2025
76dd715
.
kingbuzzman May 16, 2025
effe406
Merge branch 'main' into feature/ruff
kingbuzzman May 18, 2025
617225c
Merge remote-tracking branch 'remote/main' into feature/ruff
kingbuzzman May 18, 2025
5451e3e
Merge remote-tracking branch 'origin/feature/ruff' into feature/ruff
kingbuzzman May 18, 2025
ddf7c7b
Merge branch 'feature/ruff' into dev/implement-ruff
kingbuzzman May 18, 2025
d5df82a
Min version should be our least required
kingbuzzman May 18, 2025
78dc75e
Merge remote-tracking branch 'remote/main' into dev/implement-ruff
kingbuzzman May 18, 2025
29abb57
.
kingbuzzman May 18, 2025
eb13b7d
.
kingbuzzman May 18, 2025
047a9a7
Improvements
kingbuzzman May 18, 2025
99f587d
More replacements..
kingbuzzman May 18, 2025
68dc06c
Merge remote-tracking branch 'origin/main' into dev/ruff-implementation
kingbuzzman May 18, 2025
1a3d77e
.
kingbuzzman May 18, 2025
2934d0b
Merge branch 'main' into dev/ruff-implementation
kingbuzzman May 18, 2025
dffcb7b
wip
kingbuzzman May 19, 2025
3b7d5a4
Merge branch 'main' into dev/ruff-implementation
kingbuzzman May 22, 2025
3db2722
Update diff_cover/git_diff.py
kingbuzzman Jun 3, 2025
b41aeb2
Merge branch 'main' into dev/ruff-implementation
kingbuzzman Jun 3, 2025
ba03bd6
Update diff_cover/diff_cover_tool.py
kingbuzzman Jun 3, 2025
bdb3018
.
kingbuzzman Jun 3, 2025
25a1272
.
kingbuzzman Jun 3, 2025
39de607
.
kingbuzzman Jun 3, 2025
ccc357c
Merge branch 'main' into dev/ruff-implementation
kingbuzzman Jun 11, 2025
67b1593
Merge branch 'main' into dev/ruff-implementation
kingbuzzman Jun 12, 2025
e179d5e
Merge branch 'Bachmann1234:main' into dev/ruff-implementation
kingbuzzman Jun 15, 2025
64bdc39
Merge branch 'Bachmann1234:main' into dev/ruff-implementation
kingbuzzman Jun 16, 2025
124a1fb
Update
kingbuzzman Jun 22, 2025
46c46c2
FINALLY fixes isort issue that was driving me up a tree
kingbuzzman Jun 22, 2025
ac6fdc9
.
kingbuzzman Jun 22, 2025
a6f1f82
Fixes tests
kingbuzzman Jun 22, 2025
7261669
.
kingbuzzman Jun 22, 2025
bb53e06
Fixes bug modifying GitPathTool object
kingbuzzman Jun 22, 2025
217f3af
.
kingbuzzman Jun 22, 2025
25af280
.
kingbuzzman Jun 22, 2025
66f22b2
.
kingbuzzman Jun 22, 2025
ed7c7d5
More fixes
kingbuzzman Jun 22, 2025
f5cce2b
Nicer
kingbuzzman Jun 22, 2025
eb257b8
.
kingbuzzman Jun 22, 2025
9886242
Merge branch 'main' into dev/ruff-implementation
kingbuzzman Jun 22, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions .flake8

This file was deleted.

5 changes: 5 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
# Migrate code style to Black
e1db83a447700237a96be7a9db4413fe5024d328
# Migrate code style to Ruff
# ########################################################################
# TODO: IMPORTANT replace this with the real commit once it's merged
# ########################################################################
d1cbd0bbfd80e19f7ab6231251389fadfd4b9b22
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ lib
lib64
__pycache__
.pytest_cache
.ruff_cache

# Installer logs
pip-log.txt
Expand All @@ -34,6 +35,7 @@ pip-log.txt
.tox
/coverage.xml
/report.html
htmlcov/

# Translations
*.mo
Expand Down
2 changes: 2 additions & 0 deletions diff_cover/command_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ def _ensure_unicode(text):
Ensures the text passed in becomes unicode
Args:
text (str|unicode)

Returns:
unicode

"""
if isinstance(text, bytes):
return text.decode(sys.getfilesystemencoding(), "replace")
Expand Down
9 changes: 6 additions & 3 deletions diff_cover/config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,16 @@ def parse(self):
return None

if not _HAS_TOML:
raise ParserError("No Toml lib installed")
msg = "No Toml lib installed"
raise ParserError(msg)

with open(self._file_name, "rb") as file_handle:
config = toml.load(file_handle)

config = config.get("tool", {}).get(self._section, {})
if not config:
raise ParserError(f"No 'tool.{self._section}' configuration available")
message = f"No 'tool.{self._section}' configuration available"
raise ParserError(message)
return config


Expand All @@ -67,7 +69,8 @@ def _parse_config_file(file_name, tool):
if config:
return config

raise ParserError(f"No config parser could handle {file_name}")
message = f"No config parser could handle {file_name}"
raise ParserError(message)


def get_config(parser, argv, defaults, tool):
Expand Down
20 changes: 12 additions & 8 deletions diff_cover/diff_cover_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import os
import sys
import warnings
import xml.etree.ElementTree as etree
import xml.etree.ElementTree as ET

from diff_cover import DESCRIPTION, VERSION
from diff_cover.config_parser import Tool, get_config
Expand Down Expand Up @@ -51,7 +51,7 @@
CONFIG_FILE_HELP = "The configuration file to use"
DIFF_FILE_HELP = "The diff file to use"

LOGGER = logging.getLogger(__name__)
logger = logging.getLogger(__name__)


def format_type(value):
Expand Down Expand Up @@ -228,7 +228,7 @@ def generate_coverage_report(
)

xml_roots = [
etree.parse(coverage_file)
ET.parse(coverage_file)
for coverage_file in coverage_files
if coverage_file.endswith(".xml")
]
Expand All @@ -238,7 +238,8 @@ def generate_coverage_report(
if not coverage_file.endswith(".xml")
]
if xml_roots and lcov_roots:
raise ValueError("Mixing LCov and XML reports is not supported yet")
msg = "Mixing LCov and XML reports is not supported yet"
raise ValueError(msg)
if xml_roots:
coverage = XmlCoverageReporter(xml_roots, src_roots, expand_coverage_report)
else:
Expand Down Expand Up @@ -294,7 +295,8 @@ def handle_old_format(description, argv):
)
warnings.warn(
"The --html-report option is deprecated. "
f"Use --format html:{known_args.html_report} instead."
f"Use --format html:{known_args.html_report} instead.",
stacklevel=1,
)
format_["html"] = known_args.html_report
if known_args.json_report:
Expand All @@ -304,7 +306,8 @@ def handle_old_format(description, argv):
)
warnings.warn(
"The --json-report option is deprecated. "
f"Use --format json:{known_args.json_report} instead."
f"Use --format json:{known_args.json_report} instead.",
stacklevel=1,
)
format_["json"] = known_args.json_report
if known_args.markdown_report:
Expand All @@ -314,7 +317,8 @@ def handle_old_format(description, argv):
)
warnings.warn(
"The --markdown-report option is deprecated. "
f"Use --format markdown:{known_args.markdown_report} instead."
f"Use --format markdown:{known_args.markdown_report} instead.",
stacklevel=1,
)
format_["markdown"] = known_args.markdown_report
if format_:
Expand Down Expand Up @@ -370,7 +374,7 @@ def main(argv=None, directory=None):

if percent_covered >= fail_under:
return 0
LOGGER.error("Failure. Coverage is below %i%%.", fail_under)
logger.error("Failure. Coverage is below %i%%.", fail_under)
return 1


Expand Down
110 changes: 50 additions & 60 deletions diff_cover/diff_quality_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io
import logging
import os
import pathlib
import sys

import pluggy
Expand Down Expand Up @@ -79,16 +80,15 @@
"shellcheck": shellcheck_driver,
}

VIOLATION_CMD_HELP = "Which code quality tool to use (%s)" % "/".join(
sorted(QUALITY_DRIVERS)
VIOLATION_CMD_HELP = "Which code quality tool to use ({})".format(
"/".join(sorted(QUALITY_DRIVERS))
)
INPUT_REPORTS_HELP = "Which violations reports to use"
OPTIONS_HELP = "Options to be passed to the violations tool"
INCLUDE_HELP = "Files to include (glob pattern)"
REPORT_ROOT_PATH_HELP = "The root path used to generate a report"


LOGGER = logging.getLogger(__name__)
logger = logging.getLogger(__name__)


def parse_quality_args(argv):
Expand Down Expand Up @@ -283,7 +283,6 @@ def main(argv=None, directory=None):
1 is an error
0 is successful run
"""

argv = argv or sys.argv
arg_dict = parse_quality_args(
handle_old_format(diff_cover.QUALITY_DESCRIPTION, argv[1:])
Expand Down Expand Up @@ -321,64 +320,55 @@ def main(argv=None, directory=None):
reporter_factory_fn = hookimpl.function
break

if reporter or driver or reporter_factory_fn:
input_reports = []
try:
for path in arg_dict["input_reports"]:
try:
input_reports.append(open(path, "rb"))
except OSError:
LOGGER.error("Could not load report '%s'", path)
return 1
if driver is not None:
# If we've been given pre-generated reports,
# try to open the files
if arg_dict["report_root_path"]:
driver.add_driver_args(
report_root_path=arg_dict["report_root_path"]
)

reporter = QualityReporter(driver, input_reports, user_options)
elif reporter_factory_fn:
reporter = reporter_factory_fn(
reports=input_reports, options=user_options
)

percent_passing = generate_quality_report(
reporter,
arg_dict["compare_branch"],
GitDiffTool(
arg_dict["diff_range_notation"], arg_dict["ignore_whitespace"]
),
report_formats=arg_dict["format"],
css_file=arg_dict["external_css_file"],
ignore_staged=arg_dict["ignore_staged"],
ignore_unstaged=arg_dict["ignore_unstaged"],
include_untracked=arg_dict["include_untracked"],
exclude=arg_dict["exclude"],
include=arg_dict["include"],
quiet=quiet,
)
if percent_passing >= fail_under:
return 0

LOGGER.error("Failure. Quality is below %i.", fail_under)
return 1

except ImportError:
LOGGER.error("Quality tool not installed: '%s'", tool)
return 1
except OSError as exc:
LOGGER.error("Failure: '%s'", str(exc))
return 1
# Close any reports we opened
finally:
for file_handle in input_reports:
file_handle.close()
if not (reporter or driver or reporter_factory_fn):
logger.error("Quality tool not recognized: '%s'", tool)
return 1

input_reports = []
try:
for path in arg_dict["input_reports"]:
if not pathlib.Path(path).exists():
logger.error("Could not load report '%s'", path)
return 1
input_reports.append(open(path, "rb"))
if driver is not None:
# If we've been given pre-generated reports,
# try to open the files
if arg_dict["report_root_path"]:
driver.add_driver_args(report_root_path=arg_dict["report_root_path"])

reporter = QualityReporter(driver, input_reports, user_options)
elif reporter_factory_fn:
reporter = reporter_factory_fn(reports=input_reports, options=user_options)

percent_passing = generate_quality_report(
reporter,
arg_dict["compare_branch"],
GitDiffTool(arg_dict["diff_range_notation"], arg_dict["ignore_whitespace"]),
report_formats=arg_dict["format"],
css_file=arg_dict["external_css_file"],
ignore_staged=arg_dict["ignore_staged"],
ignore_unstaged=arg_dict["ignore_unstaged"],
include_untracked=arg_dict["include_untracked"],
exclude=arg_dict["exclude"],
include=arg_dict["include"],
quiet=quiet,
)
if percent_passing >= fail_under:
return 0
except ImportError:
logger.exception("Quality tool not installed: '%s'", tool)
return 1
except OSError:
logger.exception("Failure")
return 1
else:
LOGGER.error("Quality tool not recognized: '%s'", tool)
logger.error("Failure. Quality is below %i.", fail_under)
return 1
# Close any reports we opened
finally:
for file_handle in input_reports:
file_handle.close()


if __name__ == "__main__":
Expand Down
Loading
Loading