-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathbounds-from-nix.py
executable file
·40 lines (29 loc) · 1.19 KB
/
bounds-from-nix.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
#!/usr/bin/env python3
import json
import subprocess
from typing import Dict, Union
import toml
# Special cases that have download URLs.
SKIP = {"attention-kernels", "marlin-kernels", "moe-kernels"}
def is_optional(info: Union[str, Dict[str, str]]) -> bool:
return isinstance(info, dict) and "optional" in info and info["optional"]
if __name__ == "__main__":
with open("pyproject.toml") as f:
pyproject = toml.load(f)
nix_packages = json.loads(
subprocess.run(
["nix", "develop", ".#server", "--command", "pip", "list", "--format=json"],
stdout=subprocess.PIPE,
).stdout
)
nix_packages = {pkg["name"]: pkg["version"] for pkg in nix_packages}
packages = []
optional_packages = []
for package, info in pyproject["tool"]["poetry"]["dependencies"].items():
if package in nix_packages and package not in SKIP:
if is_optional(info):
optional_packages.append(f'"{package}@^{nix_packages[package]}"')
else:
packages.append(f'"{package}@^{nix_packages[package]}"')
print(f"poetry add {' '.join(packages)}")
print(f"poetry add --optional {' '.join(optional_packages)}")