forked from fetchai/cosmpy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install_packages.py
executable file
·61 lines (51 loc) · 1.93 KB
/
install_packages.py
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# ------------------------------------------------------------------------------
#
# Copyright 2018-2022 Fetch.AI Limited
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# ------------------------------------------------------------------------------
"""The install packages script"""
import re
import subprocess
import sys
from pathlib import Path
from typing import List
from tomlkit import loads as loads_toml
def _load_groups():
data = loads_toml(Path("pyproject.toml").read_text())
return list(data["tool"]["poetry"]["group"].keys())
def _load_dependencies() -> List[str]:
groups = ",".join(_load_groups())
text = subprocess.check_output(
f"poetry export --with {groups}", shell=True, text=True
)
text = text.replace("\\\n", " ")
lines = text.splitlines()
lines = [i.split(" ")[0] for i in lines]
return lines
RE = re.compile("(.*)[=><]")
if __name__ == "__main__":
packages = sys.argv[1:]
requirements = _load_dependencies()
to_install = []
for package in packages:
for requirement in requirements:
if re.match(f"^{package}([<>=].*)?$", requirement):
to_install.append(requirement.strip())
if not to_install:
raise ValueError("No packages found to install")
print("installing", ", ".join(to_install))
subprocess.check_call([sys.executable, "-m", "pip", "install", *to_install])