-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstallpackages.py
More file actions
executable file
·67 lines (49 loc) · 1.98 KB
/
installpackages.py
File metadata and controls
executable file
·67 lines (49 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env python3
# Obtained from https://github.com/agurwicz/scripts.
import os
from _basescript import BaseScript
class InstallPackages(BaseScript):
@property
def _description(self):
return 'Installs and upgrades packages in Python environment.'
@property
def _variables_to_check(self):
return ['python_environments_path', 'python_relative_path']
def parse_arguments(self):
self._argument_parser.add_argument(
'packages',
help='list of packages to install and upgrade (accepts versions with \"package==version\")',
type=lambda packages: packages.split(',')
)
self._argument_parser.add_argument(
'-e', '--environment',
help='name of the environment to install in (default: currently active environment)',
type=self.existing_environment
)
self._argument_parser.add_argument(
'-a', '--activate',
help='activate the environment after creation',
action='store_true'
)
return super().parse_arguments()
def run(self):
if self._arguments.activate and self._arguments.environment is None:
raise Exception('Must pass environment to activate.')
python_path = os.path.join(
self._variables.python_environments_path,
self._arguments.environment,
self._variables.python_relative_path
) if self._arguments.environment is not None else 'python'
self.run_command(
command=python_path,
parameters=('-m', 'pip', 'install', '--upgrade', '--no-cache-dir', *self._arguments.packages),
show_output=True
)
if self._arguments.activate:
self.run_script(
script_name='_activateenv',
parameters=(self._arguments.environment, '--spawn-shell'),
show_output=True
)
if __name__ == '__main__':
InstallPackages()