text-generation-inference/server/bounds-from-nix.py
Daniël de Kok 2003d8be0c
Sync (most) server dependencies with Nix (#2782)
* Sync (most) server dependencies with Nix

Skipped most grpcio packages, because of protobuf version
incompatibility with the opentelemetry packages.

* Add a primitive script to generate Poetry commands to sync with Nix

This is not fully automated, since getting the Nix versions may be
unresolvable. However, it does take most of the work out of doing
this manually.

* Upgrade eetq ?

* Fmt.

---------

Co-authored-by: Nicolas Patry <patry.nicolas@protonmail.com>
2024-12-03 04:04:06 +01:00

41 lines
1.2 KiB
Python
Executable File

#!/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)}")