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

WenjieDu / PyPOTS / 25331811247

04 May 2026 04:57PM UTC coverage: 79.827% (-0.004%) from 79.831%
25331811247

push

github

web-flow
Apply Ruff as the code formatter and linter (#854)

108 of 149 new or added lines in 33 files covered. (72.48%)

20 existing lines in 12 files now uncovered.

16561 of 20746 relevant lines covered (79.83%)

1.6 hits per line

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

79.55
/pypots/cli/dev.py
1
"""
2
CLI tools to help the development team build PyPOTS.
3
"""
4

5
# Created by Wenjie Du <wenjay.du@gmail.com>
6
# License: BSD-3-Clause
7

8
import os
2✔
9
import shutil
2✔
10

11
import click
2✔
12

13
from .base import execute_command, check_if_under_root_dir
2✔
14

15
IMPORT_ERROR_MESSAGE = (
2✔
16
    "`pypots-cli dev` command is for PyPOTS developers to run tests easily. "
17
    "Therefore, you need a complete PyPOTS development environment. However, you are missing some dependencies. "
18
    "Please refer to https://github.com/WenjieDu/PyPOTS/blob/main/environment-dev.yml for dependency details. "
19
)
20

21

22
@click.command(name="dev", help="CLI tools helping develop PyPOTS code")
2✔
23
@click.option(
2✔
24
    "--build",
25
    is_flag=True,
26
    help="Build PyPOTS into a wheel and package the source code into a .tar.gz file for distribution",
27
)
28
@click.option(
2✔
29
    "-c",
30
    "--cleanup",
31
    is_flag=True,
32
    help="Delete all caches and building files",
33
)
34
@click.option(
2✔
35
    "--run_tests",
36
    "--run-tests",
37
    is_flag=True,
38
    help="Run all test cases",
39
)
40
@click.option(
2✔
41
    "-k",
42
    "k",
43
    default=None,
44
    type=str,
45
    help="The -k option of pytest. Description of -k option in pytest: "
46
    "only run tests which match the given substring expression. An expression is a python evaluatable "
47
    "expression where all names are substring-matched against test names and their parent classes. "
48
    "Example: -k 'test_method or test_other' matches all test functions and classes whose name contains "
49
    "'test_method' or 'test_other', while -k 'not test_method' matches those that don't contain "
50
    "'test_method' in their names. -k 'not test_method and not test_other' will eliminate the matches. "
51
    "Additionally keywords are matched to classes and functions containing extra names in their "
52
    "'extra_keyword_matches' set, as well as functions which have names assigned directly to them. The "
53
    "matching is case-insensitive.",
54
)
55
@click.option(
2✔
56
    "--show-coverage",
57
    "--show_coverage",
58
    is_flag=True,
59
    help="Show the code coverage report after running tests",
60
)
61
@click.option(
2✔
62
    "--lint-code",
63
    "--lint_code",
64
    is_flag=True,
65
    help="Run Black and Flake8 to lint code",
66
)
67
def dev(build, cleanup, run_tests, k, show_coverage, lint_code):
2✔
68
    """Execute the dev command."""
69
    from ..utils.logging import logger
2✔
70

71
    # run checks
72
    check_if_under_root_dir(strict=True)
2✔
73

74
    if k is not None:
2✔
75
        assert run_tests, (
2✔
76
            "Argument `-k` should combine the use of `--run_tests`. Try `pypots-cli dev --run_tests -k your_pattern`"
77
        )
78

79
    if show_coverage:
2✔
80
        assert run_tests, (
×
81
            "Argument `--show_coverage` should combine the use of `--run_tests`. "
82
            "Try `pypots-cli dev --run_tests --show_coverage`"
83
        )
84

85
    if cleanup:
2✔
86
        assert not run_tests and not lint_code, (
2✔
87
            "Argument `--cleanup` should be used alone. Try `pypots-cli dev --cleanup`"
88
        )
89

90
    try:
2✔
91
        if cleanup:
2✔
92
            shutil.rmtree("build", ignore_errors=True)
2✔
93
            shutil.rmtree("dist", ignore_errors=True)
2✔
94
            shutil.rmtree("pypots.egg-info", ignore_errors=True)
2✔
95
        elif build:
2✔
96
            execute_command("python -m build")
2✔
97
        elif run_tests:
2✔
98
            pytest_command = f"pytest -k {k}" if k is not None else "pytest"
2✔
99
            command_to_run_test = f"coverage run -m {pytest_command}" if show_coverage else pytest_command
2✔
100
            execute_command(command_to_run_test)
2✔
101
            if show_coverage and os.path.exists(".coverage"):
×
102
                execute_command("coverage report -m")
×
103
        elif lint_code:
×
NEW
104
            logger.info("Reformatting with Ruff...")
×
NEW
105
            execute_command("ruff format .")
×
NEW
106
            logger.info("Linting with Ruff...")
×
NEW
107
            execute_command("ruff check .")
×
108
    except ImportError:
2✔
109
        raise ImportError(IMPORT_ERROR_MESSAGE)
×
110
    except Exception as e:
2✔
111
        raise e
2✔
112
    finally:
113
        shutil.rmtree(".pytest_cache", ignore_errors=True)
2✔
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

© 2026 Coveralls, Inc