• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

intel / mfd-code-quality / 19666991661

25 Nov 2025 10:51AM UTC coverage: 22.331% (-0.2%) from 22.529%
19666991661

Pull #17

github

web-flow
Merge a0d296676 into d461ab6f1
Pull Request #17: feat: UV venv support.

12 of 13 new or added lines in 1 file covered. (92.31%)

66 existing lines in 5 files now uncovered.

477 of 2136 relevant lines covered (22.33%)

0.89 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

86.15
/mfd_code_quality/code_standard/checks.py
1
# Copyright (C) 2025 Intel Corporation
2
# SPDX-License-Identifier: MIT
3
"""Code standards utilities."""
4✔
4

5
import logging
4✔
6
import sys
4✔
7
from subprocess import run
4✔
8

9
from .configure import delete_config_files, create_config_files
4✔
10
from ..utils import get_root_dir, set_up_logging, set_cwd
4✔
11

12
logger = logging.getLogger("mfd-code-quality.code_standard")
4✔
13

14

15
def _test_flake8() -> bool:
4✔
16
    """
17
    Run flake8 tests.
18

19
    :return: True if test completed successfully, False - otherwise.
20
    """
21
    flake_run_outcome = run((sys.executable, "-m", "flake8"), cwd=get_root_dir())
×
22
    return flake_run_outcome.returncode == 0
×
23

24

25
def _test_ruff_format() -> bool:
4✔
26
    """
27
    Run ruff format check.
28

29
    :return: True if there is nothing to format, False - otherwise.
30
    """
UNCOV
31
    logger.info("Checking 'ruff format --check'...")
×
UNCOV
32
    ruff_format_outcome = run(
×
33
        (sys.executable, "-m", "ruff", "format", "--check"), capture_output=True, text=True, cwd=get_root_dir()
34
    )
UNCOV
35
    logger.info(f"Output: {ruff_format_outcome.stdout.strip()}")
×
UNCOV
36
    return ruff_format_outcome.returncode == 0
×
37

38

39
def _test_ruff_check() -> bool:
4✔
40
    """
41
    Run ruff linter check.
42

43
    :return: True if ruff check did not find any issues, False - otherwise.
44
    """
45
    logger.info("Checking 'ruff check'...")
4✔
46
    ruff_run_outcome = run((sys.executable, "-m", "ruff", "check"), capture_output=True, text=True, cwd=get_root_dir())
4✔
47
    logger.info(f"Output: {ruff_run_outcome.stdout.strip()}")
4✔
48
    return ruff_run_outcome.returncode == 0
4✔
49

50

51
def _get_available_code_standard_module() -> str:
4✔
52
    """
53
    Get available code standard module which is installed in python.
54

55
    It will be either flake8 or ruff.
56

57
    :return: flake8 or ruff
58
    :raises Exception: When no code standard module is available
59
    """
60
    code_standard_modules = ["ruff", "flake8"]
4✔
61
    commands = [("uv", "pip", "list"), (sys.executable, "-m", "pip", "list")]
4✔
62
    for cmd in commands:
4✔
63
        try:
4✔
64
            pip_list = run(cmd, capture_output=True, text=True, cwd=get_root_dir())
4✔
65
        except Exception as e:  # noqa
4✔
66
            logger.debug(f"Error occurred while running {cmd}:\n{e}")
4✔
67
            continue
4✔
68

69
        if pip_list.returncode != 0:
4✔
NEW
70
            continue
×
71

72
        for code_standard_module in code_standard_modules:
4✔
73
            if f"{code_standard_module} " in pip_list.stdout:
4✔
74
                logger.info(f"{code_standard_module.capitalize()} will be used for code standard check.")
4✔
75
                return code_standard_module
4✔
76

77
    raise Exception("No code standard module is available! [flake8 or ruff]")
4✔
78

79

80
def _run_code_standard_tests(with_configs: bool = True) -> bool:
4✔
81
    """
82
    Run code standard tests.
83

84
    :param with_configs: Should we create configuration files before running checks.
85
    :return: True if all tests passed, False otherwise.
86
    """
87
    set_up_logging()
4✔
88
    set_cwd()
4✔
89
    code_standard_module = None
4✔
90
    try:
4✔
91
        results = []
4✔
92
        code_standard_module = _get_available_code_standard_module()
4✔
93
        if code_standard_module == "ruff":
4✔
94
            if with_configs:
4✔
95
                logger.debug("Prepare configuration files required for checks.")
4✔
96
                create_config_files()
4✔
97
            results.append(_test_ruff_format())
4✔
98
            results.append(_test_ruff_check())
4✔
99
        elif code_standard_module == "flake8":
×
100
            results.append(_test_flake8())
×
101

102
        return_val = all(results)
4✔
103
        if return_val:
4✔
104
            message = "Code standard check PASSED."
4✔
105
        else:
106
            if code_standard_module == "ruff":
4✔
107
                logger.info(
4✔
108
                    "Ruff check was called correctly, however check failed.\n"
109
                    "For fixing code standard call 'mfd-code-format' first.\n"
110
                    "If you want to see more details what is wrong, call 'ruff format --diff'.\n"
111
                )
112
            message = "Code standard check FAILED."
4✔
113
        logger.info(message)
4✔
114
    finally:
115
        if code_standard_module == "ruff" and with_configs:
4✔
116
            logger.debug("Delete configuration files.")
4✔
117
            delete_config_files()
4✔
118

119
    return return_val
4✔
120

121

122
def run_checks(with_configs: bool = True) -> None:
4✔
123
    """
124
    Run code standard tests.
125

126
    :param with_configs: Should we create configuration files before running checks.
127
    """
128
    return_val = _run_code_standard_tests(with_configs)
4✔
129

130
    sys.exit(0 if return_val else 1)
4✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc