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

WenjieDu / PyPOTS / 12015168636

25 Nov 2024 05:10PM UTC coverage: 84.286% (-0.02%) from 84.307%
12015168636

push

github

web-flow
Update docs for CSAI (#549)

12047 of 14293 relevant lines covered (84.29%)

4.94 hits per line

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

81.08
/pypots/cli/env.py
1
"""
3✔
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: BSD-3-Clause
7

8
try:
6✔
9
    import torch
6✔
10

11
    # import numpy
12
    # import sklearn
13
    # import pandas
14
    # import tensorboard
15
    # import scipy
16
    # import h5py
17
    # import tsdb
18
    # import pygrinder
19
except ImportError:
×
20
    raise ImportError(
×
21
        "Torch not installed. Using this tool supposes that you've already installed `pypots` "
22
        "with at least basic dependencies in requirements/requirements.txt in PyPOTS project's root dir."
23
    )
24

25
from argparse import ArgumentParser, Namespace
6✔
26

27
from .base import BaseCommand
6✔
28
from ..utils.logging import logger
6✔
29

30

31
def env_command_factory(args: Namespace):
6✔
32
    return EnvCommand(
6✔
33
        args.install,
34
        args.tool,
35
    )
36

37

38
class EnvCommand(BaseCommand):
6✔
39
    """CLI tools helping users and developer setup python environments for running and developing PyPOTS.
3✔
40

41
    Notes
42
    -----
43
    Using this tool supposes that you've already installed `pypots` with at least basic dependencies.
44
    Please refer to file requirements/requirements.txt in PyPOTS project's root dir for references.
45

46
    Examples
47
    --------
48
    $ pypots-cli env --scope full --tool pip
49
    $ pypots-cli env --scope full --tool pip
50
    $ pypots-cli env --scope dev --tool conda -n
51
    """
52

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

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

78
        sub_parser.set_defaults(func=env_command_factory)
×
79

80
    def __init__(
6✔
81
        self,
82
        install: bool,
83
        tool: str,
84
    ):
85
        self._install = install
6✔
86
        self._tool = tool
6✔
87

88
    def checkup(self):
6✔
89
        """Run some checks on the arguments to avoid error usages"""
90
        self.check_if_under_root_dir(strict=True)
6✔
91

92
    def run(self):
6✔
93
        """Execute the given command."""
94
        # run checks first
95
        self.checkup()
6✔
96

97
        logger.info(f"Installing the dependencies in scope `{self._install}` for you...")
6✔
98

99
        if self._tool == "conda":
6✔
100
            assert (
6✔
101
                self.execute_command("which conda").returncode == 0
102
            ), "Conda not installed, cannot set --tool=conda, please check your conda."
103

104
            self.execute_command("conda install pyg pytorch-scatter pytorch-sparse -c pyg")
2✔
105

106
        else:  # self._tool == "pip"
107
            torch_version = torch.__version__
6✔
108

109
            if not (torch.cuda.is_available() and torch.cuda.device_count() > 0):
6✔
110
                if "cpu" not in torch_version:
6✔
111
                    torch_version = torch_version + "+cpu"
4✔
112

113
            self.execute_command(
6✔
114
                f"python -m pip install -e '.[optional]' -f https://data.pyg.org/whl/torch-{torch_version}.html"
115
            )
116

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