Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
cli.py56 linesDownload Raw Back to cli
1import re
2import sys
3
4import chromadb_rust_bindings
5import requests
6from packaging.version import parse
7
8import chromadb
9
10
11def build_cli_args(**kwargs):
12    args = []
13    for key, value in kwargs.items():
14        if isinstance(value, bool):
15            if value:
16                args.append(f"--{key}")
17        elif value is not None:
18            args.extend([f"--{key}", str(value)])
19    return args
20
21
22def update():
23    try:
24        url = f"https://api.github.com/repos/chroma-core/chroma/releases"
25        response = requests.get(url)
26        response.raise_for_status()
27        releases = response.json()
28
29        version_pattern = re.compile(r'^\d+\.\d+\.\d+$')
30        numeric_releases = [r["tag_name"] for r in releases if version_pattern.fullmatch(r["tag_name"])]
31
32        if not numeric_releases:
33            print("Couldn't fetch the latest Chroma version")
34            return
35
36        latest = max(numeric_releases, key=parse)
37        if latest == chromadb.__version__:
38            print("Your Chroma version is up-to-date")
39            return
40
41        print(
42            f"A new version of Chroma is available!\nIf you're using pip, run 'pip install --upgrade chromadb' to upgrade to version {latest}")
43
44    except Exception as e:
45        print("Couldn't fetch the latest Chroma version")
46
47
48def app():
49    args = sys.argv
50    if ["chroma", "update"] in args:
51        update()
52        return
53    try:
54        chromadb_rust_bindings.cli(args)
55    except KeyboardInterrupt:
56        pass
codekingpro/portable-devtools · Team Ai