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

WenjieDu / PyPOTS / 4755049409

pending completion
4755049409

push

github

GitHub
Merge pull request #63 from WenjieDu/dev

61 of 61 new or added lines in 5 files covered. (100.0%)

2832 of 3490 relevant lines covered (81.15%)

0.81 hits per line

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

0.0
/pypots/utils/commands/base.py
1
"""
2
The base class for PyPOTS CLI (command line interface).
3
"""
4

5
# Created by Wenjie Du <wenjay.du@gmail.com>
6
# License: GLP-v3
7

8

9
import os
×
10
import subprocess
×
11
import sys
×
12
from abc import ABC, abstractmethod
×
13
from argparse import ArgumentParser
×
14

15
from pypots.utils.logging import logger
×
16

17

18
class BaseCommand(ABC):
×
19
    @staticmethod
×
20
    @abstractmethod
×
21
    def register_subcommand(parser: ArgumentParser):
×
22
        raise NotImplementedError()
×
23

24
    @staticmethod
×
25
    def execute_command(command: str, verbose: bool = True):
×
26
        if verbose:
×
27
            exec_result = subprocess.Popen(
×
28
                command,
29
                stdin=subprocess.PIPE,
30
                close_fds=True,
31
                stderr=sys.stderr,
32
                stdout=sys.stdout,
33
                universal_newlines=True,
34
                shell=True,
35
                bufsize=1,
36
            )
37
            exec_result.communicate()
×
38
        else:
39
            exec_result = subprocess.run(
×
40
                command,
41
                text=True,
42
                stdout=subprocess.PIPE,
43
                stderr=subprocess.PIPE,
44
                shell=True,
45
            )
46
            if exec_result.returncode != 0:
×
47
                if len(exec_result.stderr) > 0:
×
48
                    logger.error(exec_result.stderr)
×
49
                if len(exec_result.stdout) > 0:
×
50
                    logger.error(exec_result.stdout)
×
51
                raise RuntimeError()
×
52
        return exec_result.returncode
×
53

54
    @staticmethod
×
55
    def check_if_under_root_dir(strict: bool = True):
×
56
        """ Check if under the root dir of PyPOTS project.
57

58
        Parameters
59
        ----------
60
        strict : bool, default = True,
61
            Whether to raise a RuntimeError if currently not under the root dir of PyPOTS project.
62

63
        Returns
64
        -------
65
        check_result : bool,
66
            Whether currently under the root dir of PyPOTS project.
67
        """
68
        all_files_under_current_dir = set(os.listdir("."))
×
69
        check_result = all_files_under_current_dir.issuperset(
×
70
            {
71
                ".github",
72
                "docs",
73
                "pypots",
74
                "tutorials",
75
                "setup.cfg",
76
                "setup.py",
77
            }
78
        )
79

80
        if strict:
×
81
            assert check_result, RuntimeError(
×
82
                "Command `pypots-cli dev` can only be run under the root directory of project PyPOTS, "
83
                f"but you're running it under the path {os.getcwd()}. Please make a check."
84
            )
85

86
        return check_result
×
87

88
    @abstractmethod
×
89
    def run(self):
×
90
        raise NotImplementedError()
×
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