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

WenjieDu / PyPOTS / 4845620836

pending completion
4845620836

Pull #77

github

GitHub
Merge fd7b05c7e into 39b2bbebd
Pull Request #77: Fix dependency error in daily testing

3112 of 3668 relevant lines covered (84.84%)

0.85 hits per line

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

59.18
/pypots/cli/env.py
1
"""
1✔
2
CLI tools to help initialize environments for running and developing PyPOTS.
3
"""
4

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

8
try:
1✔
9
    # here try importing all dependencies in the scope `basic` defined in `setup.cfg`
10
    import torch
1✔
11

12
    # import numpy
13
    # import sklearn
14
    # import pandas
15
    # import tensorboard
16
    # import scipy
17
    # import h5py
18
    # import tsdb
19
    # import pycorruptor
20
except ImportError:
×
21
    raise ImportError(
×
22
        "Torch not installed. Using this tool supposes that you've already installed `pypots` "
23
        "with at least the scope of `basic` dependencies."
24
    )
25

26
from argparse import ArgumentParser, Namespace
1✔
27

28
from setuptools.config import read_configuration
1✔
29

30
from pypots.cli.base import BaseCommand
1✔
31
from pypots.utils.logging import logger
1✔
32

33

34
def env_command_factory(args: Namespace):
1✔
35
    return EnvCommand(
1✔
36
        args.install,
37
        args.tool,
38
    )
39

40

41
class EnvCommand(BaseCommand):
1✔
42
    """CLI tools helping users and developer setup python environments for running and developing PyPOTS.
1✔
43

44
    Notes
45
    -----
46
    Using this tool supposes that you've already installed `pypots` with at least the scope of `basic` dependencies.
47
    Please refer to file setup.cfg in PyPOTS project's root dir for definitions of different dependency scopes.
48

49
    Examples
50
    --------
51
    $ pypots-cli env --scope full --tool pip
52
    $ pypots-cli env --scope full --tool pip
53
    $ pypots-cli env --scope dev --tool conda -n
54
    """
55

56
    @staticmethod
1✔
57
    def register_subcommand(parser: ArgumentParser):
1✔
58
        sub_parser = parser.add_parser(
×
59
            "env",
60
            help="CLI tools helping users and developer setup python environments for running and developing PyPOTS",
61
            allow_abbrev=True,
62
        )
63

64
        sub_parser.add_argument(
×
65
            "--install",
66
            dest="install",
67
            type=str,
68
            required=True,
69
            choices=["dev", "full", "doc", "test", "optional"],
70
            help="Install specified dependencies in the current python environment",
71
        )
72
        sub_parser.add_argument(
×
73
            "--tool",
74
            dest="tool",
75
            type=str,
76
            required=True,
77
            choices=["conda", "pip"],
78
            help="Setup the environment with pip or conda, have to be specific",
79
        )
80

81
        sub_parser.set_defaults(func=env_command_factory)
×
82

83
    def __init__(
1✔
84
        self,
85
        install: bool,
86
        tool: str,
87
    ):
88
        self._install = install
1✔
89
        self._tool = tool
1✔
90

91
    def checkup(self):
1✔
92
        """Run some checks on the arguments to avoid error usages"""
93
        self.check_if_under_root_dir(strict=True)
1✔
94

95
    def run(self):
1✔
96
        """Execute the given command."""
97
        # run checks first
98
        self.checkup()
1✔
99

100
        setup_cfg = read_configuration("setup.cfg")
1✔
101

102
        logger.info(
1✔
103
            f"Installing the dependencies in scope `{self._install}` for you..."
104
        )
105

106
        if self._tool == "conda":
1✔
107
            assert (
1✔
108
                self.execute_command("which conda").returncode == 0
109
            ), "Conda not installed, cannot set --tool=conda, please check your conda."
110

111
            self.execute_command(
×
112
                "conda install pyg pytorch-scatter pytorch-sparse -c pyg"
113
            )
114

115
            if self._install != "optional":
×
116
                dependencies = ""
×
117
                for i in setup_cfg["options"]["extras_require"][self._install]:
×
118
                    dependencies += f"'{i}' "
×
119

120
                if "torch-geometric" in dependencies:
×
121
                    dependencies = dependencies.replace("'torch-geometric'", "")
×
122
                    dependencies = dependencies.replace("'torch-scatter'", "")
×
123
                    dependencies = dependencies.replace("'torch-sparse'", "")
×
124

125
                conda_comm = f"conda install {dependencies} -c conda-forge"
×
126
                self.execute_command(conda_comm)
×
127

128
        else:  # self._tool == "pip"
129
            torch_version = torch.__version__
1✔
130

131
            if not (torch.cuda.is_available() and torch.cuda.device_count() > 0):
1✔
132
                if "cpu" not in torch_version:
1✔
133
                    torch_version = torch_version + "+cpu"
1✔
134

135
            self.execute_command(
1✔
136
                f"python -m pip install -e '.[optional]' -f https://data.pyg.org/whl/torch-{torch_version}.html"
137
            )
138

139
            if self._install != "optional":
×
140
                self.execute_command(f"pip install -e '.[{self._install}]'")
×
141
        logger.info("Installation finished. Enjoy your play with PyPOTS! Bye ;-)")
×
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