Skip to content

Commit dec174d

Browse files
Merge pull request #2 from lancedb/load-package-specs-from-env
udfs: resolve geneva/lancedb/pylance pins from installed versions
2 parents 73fce83 + c6d6f12 commit dec174d

6 files changed

Lines changed: 65 additions & 15 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""Resolve remote-runtime package pins from the installed environment.
2+
3+
The Geneva remote runtime installs a pinned set of pip packages into each
4+
worker's env. Rather than hardcoding versions in every UDF module — where they
5+
silently drift from what's actually installed locally — we read the installed
6+
version of each package and emit an exact ``name==X.Y.Z`` spec. This keeps the
7+
remote workers on the same versions the client resolved (via ``uv.lock``).
8+
9+
An environment variable override (``{PACKAGE}_PACKAGE_SPEC``, e.g.
10+
``GENEVA_PACKAGE_SPEC``) still wins verbatim, so a different build can be
11+
targeted on the workers without touching code.
12+
"""
13+
14+
from __future__ import annotations
15+
16+
import os
17+
from importlib.metadata import version
18+
19+
20+
def package_spec(package: str, *, env_var: str | None = None) -> str:
21+
"""Return ``package==<installed version>``, or an env override if set.
22+
23+
``env_var`` defaults to ``{PACKAGE}_PACKAGE_SPEC`` (uppercased package name).
24+
The override is returned exactly as given — it need not be an ``==`` pin.
25+
"""
26+
env_var = env_var or f"{package.upper()}_PACKAGE_SPEC"
27+
override = os.environ.get(env_var)
28+
if override:
29+
return override
30+
return f"{package}=={version(package)}"

geneva_examples/udfs/blip.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@
55
import os
66
import uuid
77

8+
from geneva_examples.core.package_specs import package_spec
9+
810
# Geneva remote runtime package pins (env-overridable for targeting other builds).
9-
GENEVA_PACKAGE_SPEC = os.environ.get("GENEVA_PACKAGE_SPEC", "geneva==0.13.0b18")
10-
LANCEDB_PACKAGE_SPEC = os.environ.get("LANCEDB_PACKAGE_SPEC", "lancedb==0.33.1b2")
11-
PYLANCE_PACKAGE_SPEC = os.environ.get("PYLANCE_PACKAGE_SPEC", "pylance==8.0.0b16")
11+
# geneva/lancedb/pylance track the installed versions so the workers match the
12+
# client's locked env; the rest stay exact-pinned for reproducible worker builds.
13+
GENEVA_PACKAGE_SPEC = package_spec("geneva")
14+
LANCEDB_PACKAGE_SPEC = package_spec("lancedb")
15+
PYLANCE_PACKAGE_SPEC = package_spec("pylance")
1216
PYARROW_PACKAGE_SPEC = os.environ.get("PYARROW_PACKAGE_SPEC", "pyarrow==23.0.0")
1317
PILLOW_PACKAGE_SPEC = os.environ.get("PILLOW_PACKAGE_SPEC", "pillow==12.2.0")
1418
TORCH_PACKAGE_SPEC = os.environ.get("TORCH_PACKAGE_SPEC", "torch==2.12.0")

geneva_examples/udfs/chunkers.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,14 @@
1919
import os
2020
import uuid
2121

22+
from geneva_examples.core.package_specs import package_spec
23+
2224
# Geneva remote runtime package pins (env-overridable for targeting other builds).
23-
GENEVA_PACKAGE_SPEC = os.environ.get("GENEVA_PACKAGE_SPEC", "geneva==0.13.0b18")
24-
LANCEDB_PACKAGE_SPEC = os.environ.get("LANCEDB_PACKAGE_SPEC", "lancedb==0.33.1b2")
25-
PYLANCE_PACKAGE_SPEC = os.environ.get("PYLANCE_PACKAGE_SPEC", "pylance==8.0.0b16")
25+
# geneva/lancedb/pylance track the installed versions so the workers match the
26+
# client's locked env; the rest stay exact-pinned for reproducible worker builds.
27+
GENEVA_PACKAGE_SPEC = package_spec("geneva")
28+
LANCEDB_PACKAGE_SPEC = package_spec("lancedb")
29+
PYLANCE_PACKAGE_SPEC = package_spec("pylance")
2630
PYARROW_PACKAGE_SPEC = os.environ.get("PYARROW_PACKAGE_SPEC", "pyarrow==23.0.0")
2731
PILLOW_PACKAGE_SPEC = os.environ.get("PILLOW_PACKAGE_SPEC", "pillow==12.2.0")
2832
AV_PACKAGE_SPEC = os.environ.get("AV_PACKAGE_SPEC", "av>=12,<14")

geneva_examples/udfs/clip.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@
66
import uuid
77
from collections.abc import Callable
88

9+
from geneva_examples.core.package_specs import package_spec
10+
911
# Geneva remote runtime package pins (env-overridable for targeting other builds).
10-
GENEVA_PACKAGE_SPEC = os.environ.get("GENEVA_PACKAGE_SPEC", "geneva==0.13.0b18")
11-
LANCEDB_PACKAGE_SPEC = os.environ.get("LANCEDB_PACKAGE_SPEC", "lancedb==0.33.1b2")
12-
PYLANCE_PACKAGE_SPEC = os.environ.get("PYLANCE_PACKAGE_SPEC", "pylance==8.0.0b16")
12+
# geneva/lancedb/pylance track the installed versions so the workers match the
13+
# client's locked env; the rest stay exact-pinned for reproducible worker builds.
14+
GENEVA_PACKAGE_SPEC = package_spec("geneva")
15+
LANCEDB_PACKAGE_SPEC = package_spec("lancedb")
16+
PYLANCE_PACKAGE_SPEC = package_spec("pylance")
1317
PYARROW_PACKAGE_SPEC = os.environ.get("PYARROW_PACKAGE_SPEC", "pyarrow==23.0.0")
1418
PILLOW_PACKAGE_SPEC = os.environ.get("PILLOW_PACKAGE_SPEC", "pillow==12.2.0")
1519
NUMPY_PACKAGE_SPEC = os.environ.get("NUMPY_PACKAGE_SPEC", "numpy==2.4.6")

geneva_examples/udfs/imageinfo.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@
55
import os
66
import uuid
77

8+
from geneva_examples.core.package_specs import package_spec
9+
810
# Geneva remote runtime package pins (env-overridable for targeting other builds).
9-
GENEVA_PACKAGE_SPEC = os.environ.get("GENEVA_PACKAGE_SPEC", "geneva==0.13.0b18")
10-
LANCEDB_PACKAGE_SPEC = os.environ.get("LANCEDB_PACKAGE_SPEC", "lancedb==0.33.1b2")
11-
PYLANCE_PACKAGE_SPEC = os.environ.get("PYLANCE_PACKAGE_SPEC", "pylance==8.0.0b16")
11+
# geneva/lancedb/pylance track the installed versions so the workers match the
12+
# client's locked env; the rest stay exact-pinned for reproducible worker builds.
13+
GENEVA_PACKAGE_SPEC = package_spec("geneva")
14+
LANCEDB_PACKAGE_SPEC = package_spec("lancedb")
15+
PYLANCE_PACKAGE_SPEC = package_spec("pylance")
1216
PYARROW_PACKAGE_SPEC = os.environ.get("PYARROW_PACKAGE_SPEC", "pyarrow==23.0.0")
1317
PILLOW_PACKAGE_SPEC = os.environ.get("PILLOW_PACKAGE_SPEC", "pillow==12.2.0")
1418

geneva_examples/udfs/openpose.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@
55
import os
66
import uuid
77

8+
from geneva_examples.core.package_specs import package_spec
9+
810
# Geneva remote runtime package pins (env-overridable for targeting other builds).
9-
GENEVA_PACKAGE_SPEC = os.environ.get("GENEVA_PACKAGE_SPEC", "geneva==0.13.0b18")
10-
LANCEDB_PACKAGE_SPEC = os.environ.get("LANCEDB_PACKAGE_SPEC", "lancedb==0.33.1b2")
11-
PYLANCE_PACKAGE_SPEC = os.environ.get("PYLANCE_PACKAGE_SPEC", "pylance==8.0.0b16")
11+
# geneva/lancedb/pylance track the installed versions so the workers match the
12+
# client's locked env; the rest stay exact-pinned for reproducible worker builds.
13+
GENEVA_PACKAGE_SPEC = package_spec("geneva")
14+
LANCEDB_PACKAGE_SPEC = package_spec("lancedb")
15+
PYLANCE_PACKAGE_SPEC = package_spec("pylance")
1216
PYARROW_PACKAGE_SPEC = os.environ.get("PYARROW_PACKAGE_SPEC", "pyarrow==23.0.0")
1317
PILLOW_PACKAGE_SPEC = os.environ.get("PILLOW_PACKAGE_SPEC", "pillow==12.2.0")
1418
NUMPY_PACKAGE_SPEC = os.environ.get("NUMPY_PACKAGE_SPEC", "numpy==2.4.6")

0 commit comments

Comments
 (0)