-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpackage_list.py
More file actions
51 lines (42 loc) · 1.44 KB
/
package_list.py
File metadata and controls
51 lines (42 loc) · 1.44 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
from __future__ import annotations
import sys
from pathlib import Path
import networkx as nx
from deploy.config import Config
from deploy.package import Package
class PackageList:
def __init__(
self,
configpath: Path,
config: Config,
*,
prefix: Path,
check_existence: bool = True,
) -> None:
self.prefix: Path = prefix.resolve()
self.storepath: Path = self.prefix / ".store"
self.config: Config = config
buildmap = {x.name: x for x in config.packages}
self.storepath.mkdir(parents=True, exist_ok=True)
graph: nx.DiGraph[str] = nx.DiGraph()
for package in config.packages:
graph.add_node(package.name)
for dep in package.depends:
graph.add_edge(dep, package.name)
self.packages: dict[str, Package] = {}
for node in nx.topological_sort(graph):
build = buildmap[node]
self.packages[node] = Package(
configpath,
self.storepath,
build,
[self.packages[x] for x in build.depends],
)
if check_existence:
self._check_existence()
def _check_existence(self) -> None:
for pkg in self.packages.values():
if not pkg.out.is_dir():
sys.exit(
f"{pkg.out} doesn't exist. Are you sure that '{pkg.fullname}' is installed?"
)