enzyme-python-package 0.4.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- enzyme_python_package/__init__.py +157 -0
- enzyme_python_package-0.4.4.dist-info/METADATA +14 -0
- enzyme_python_package-0.4.4.dist-info/RECORD +6 -0
- enzyme_python_package-0.4.4.dist-info/WHEEL +5 -0
- enzyme_python_package-0.4.4.dist-info/entry_points.txt +2 -0
- enzyme_python_package-0.4.4.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"""enzyme-cli — pip-installable wrapper for the enzyme binary.
|
|
2
|
+
|
|
3
|
+
On first run (or `enzyme-cli install`), downloads the correct platform binary
|
|
4
|
+
and embedding model from GitHub releases. Subsequent calls proxy directly to
|
|
5
|
+
the binary.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import hashlib
|
|
11
|
+
import os
|
|
12
|
+
import platform
|
|
13
|
+
import stat
|
|
14
|
+
import subprocess
|
|
15
|
+
import sys
|
|
16
|
+
import tarfile
|
|
17
|
+
import tempfile
|
|
18
|
+
import urllib.request
|
|
19
|
+
|
|
20
|
+
REPO = "jshph/enzyme"
|
|
21
|
+
VERSION = "0.4.4"
|
|
22
|
+
|
|
23
|
+
# Where we store the binary and model
|
|
24
|
+
_DATA_DIR = os.path.join(os.path.expanduser("~"), ".enzyme-cli")
|
|
25
|
+
_BIN_PATH = os.path.join(_DATA_DIR, "enzyme")
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _detect_target() -> str:
|
|
29
|
+
"""Detect platform target string matching GitHub release asset names."""
|
|
30
|
+
system = platform.system()
|
|
31
|
+
machine = platform.machine()
|
|
32
|
+
|
|
33
|
+
if system == "Darwin" and machine == "arm64":
|
|
34
|
+
return "macos-arm64"
|
|
35
|
+
elif system == "Linux" and machine == "x86_64":
|
|
36
|
+
return "linux-x86_64"
|
|
37
|
+
elif system == "Linux" and machine in ("aarch64", "arm64"):
|
|
38
|
+
return "linux-arm64"
|
|
39
|
+
else:
|
|
40
|
+
raise RuntimeError(
|
|
41
|
+
f"Unsupported platform: {system}-{machine}. "
|
|
42
|
+
"Enzyme supports macOS arm64, Linux x86_64, and Linux arm64."
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def _download_url(url: str, dest: str) -> None:
|
|
47
|
+
"""Download a URL to a file path."""
|
|
48
|
+
print(f" Downloading {url.split('/')[-1]}...")
|
|
49
|
+
urllib.request.urlretrieve(url, dest)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def _verify_sha256(filepath: str, sha256_url: str) -> None:
|
|
53
|
+
"""Verify file against a .sha256 checksum URL."""
|
|
54
|
+
try:
|
|
55
|
+
with urllib.request.urlopen(sha256_url) as resp:
|
|
56
|
+
expected = resp.read().decode().strip().split()[0]
|
|
57
|
+
h = hashlib.sha256()
|
|
58
|
+
with open(filepath, "rb") as f:
|
|
59
|
+
for chunk in iter(lambda: f.read(8192), b""):
|
|
60
|
+
h.update(chunk)
|
|
61
|
+
actual = h.hexdigest()
|
|
62
|
+
if actual != expected:
|
|
63
|
+
raise RuntimeError(
|
|
64
|
+
f"SHA256 mismatch: expected {expected}, got {actual}"
|
|
65
|
+
)
|
|
66
|
+
except urllib.error.URLError:
|
|
67
|
+
# If checksum file unavailable, skip verification
|
|
68
|
+
pass
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def _is_installed() -> bool:
|
|
72
|
+
"""Check if the enzyme binary is installed and current."""
|
|
73
|
+
if not os.path.isfile(_BIN_PATH):
|
|
74
|
+
return False
|
|
75
|
+
# Check version
|
|
76
|
+
try:
|
|
77
|
+
result = subprocess.run(
|
|
78
|
+
[_BIN_PATH, "--version"],
|
|
79
|
+
capture_output=True, text=True, timeout=5,
|
|
80
|
+
)
|
|
81
|
+
return VERSION in result.stdout
|
|
82
|
+
except Exception:
|
|
83
|
+
return False
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def install() -> None:
|
|
87
|
+
"""Download and install the enzyme binary and embedding model."""
|
|
88
|
+
target = _detect_target()
|
|
89
|
+
base_url = f"https://github.com/{REPO}/releases/download/v{VERSION}"
|
|
90
|
+
asset = f"enzyme-{target}.tar.gz"
|
|
91
|
+
asset_url = f"{base_url}/{asset}"
|
|
92
|
+
sha256_url = f"{asset_url}.sha256"
|
|
93
|
+
|
|
94
|
+
os.makedirs(_DATA_DIR, exist_ok=True)
|
|
95
|
+
|
|
96
|
+
print(f"Installing enzyme {VERSION} ({target})...")
|
|
97
|
+
|
|
98
|
+
with tempfile.TemporaryDirectory() as tmpdir:
|
|
99
|
+
tarball = os.path.join(tmpdir, asset)
|
|
100
|
+
_download_url(asset_url, tarball)
|
|
101
|
+
_verify_sha256(tarball, sha256_url)
|
|
102
|
+
|
|
103
|
+
with tarfile.open(tarball, "r:gz") as tar:
|
|
104
|
+
tar.extractall(tmpdir)
|
|
105
|
+
|
|
106
|
+
# Move binary
|
|
107
|
+
src = os.path.join(tmpdir, "enzyme")
|
|
108
|
+
if not os.path.isfile(src):
|
|
109
|
+
raise RuntimeError(f"Binary not found in archive at {src}")
|
|
110
|
+
|
|
111
|
+
# Replace atomically
|
|
112
|
+
tmp_bin = _BIN_PATH + ".tmp"
|
|
113
|
+
with open(src, "rb") as sf, open(tmp_bin, "wb") as df:
|
|
114
|
+
df.write(sf.read())
|
|
115
|
+
os.chmod(tmp_bin, os.stat(tmp_bin).st_mode | stat.S_IEXEC)
|
|
116
|
+
os.replace(tmp_bin, _BIN_PATH)
|
|
117
|
+
|
|
118
|
+
# Copy bundled libs if present (Linux builds)
|
|
119
|
+
lib_dir = os.path.join(tmpdir, "lib")
|
|
120
|
+
if os.path.isdir(lib_dir):
|
|
121
|
+
dest_lib = os.path.join(_DATA_DIR, "lib")
|
|
122
|
+
os.makedirs(dest_lib, exist_ok=True)
|
|
123
|
+
for f in os.listdir(lib_dir):
|
|
124
|
+
src_f = os.path.join(lib_dir, f)
|
|
125
|
+
dst_f = os.path.join(dest_lib, f)
|
|
126
|
+
with open(src_f, "rb") as sf, open(dst_f, "wb") as df:
|
|
127
|
+
df.write(sf.read())
|
|
128
|
+
|
|
129
|
+
print(f" Binary installed to {_BIN_PATH}")
|
|
130
|
+
|
|
131
|
+
# Download embedding model
|
|
132
|
+
print(" Downloading embedding model (~52 MB)...")
|
|
133
|
+
subprocess.run(
|
|
134
|
+
[_BIN_PATH, "setup"],
|
|
135
|
+
timeout=120,
|
|
136
|
+
check=True,
|
|
137
|
+
)
|
|
138
|
+
print(" Done.")
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def main() -> None:
|
|
142
|
+
"""Entry point — install if needed, then proxy to the binary."""
|
|
143
|
+
# Handle explicit install command
|
|
144
|
+
if len(sys.argv) > 1 and sys.argv[1] == "install":
|
|
145
|
+
install()
|
|
146
|
+
return
|
|
147
|
+
|
|
148
|
+
# Auto-install on first run
|
|
149
|
+
if not _is_installed():
|
|
150
|
+
install()
|
|
151
|
+
|
|
152
|
+
# Proxy all args to the real binary
|
|
153
|
+
try:
|
|
154
|
+
result = subprocess.run([_BIN_PATH] + sys.argv[1:])
|
|
155
|
+
sys.exit(result.returncode)
|
|
156
|
+
except KeyboardInterrupt:
|
|
157
|
+
sys.exit(130)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: enzyme-python-package
|
|
3
|
+
Version: 0.4.4
|
|
4
|
+
Summary: Vault intelligence — concept graph and semantic search for markdown notes
|
|
5
|
+
Author: Joshua Pham
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://enzyme.garden
|
|
8
|
+
Project-URL: Repository, https://github.com/jshph/enzyme
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Operating System :: MacOS
|
|
12
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
13
|
+
Requires-Python: >=3.9
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
enzyme_python_package/__init__.py,sha256=wneVpqCyN0d1ghLErXH6xam0P4tdqxsawCgvIJE5NFk,4848
|
|
2
|
+
enzyme_python_package-0.4.4.dist-info/METADATA,sha256=D7cSPSipeF3uVPTSHYUcMgGRNF8et9_-pINQspgQC1Q,532
|
|
3
|
+
enzyme_python_package-0.4.4.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
4
|
+
enzyme_python_package-0.4.4.dist-info/entry_points.txt,sha256=Ub0fvqMy03RoTcDW0JPMHcO7zykvCkJJkgLczRvxN1Q,54
|
|
5
|
+
enzyme_python_package-0.4.4.dist-info/top_level.txt,sha256=5-0Hmvc5xki63Wpu9Ilddc9P5li-MRnsp3dokcwLk5A,22
|
|
6
|
+
enzyme_python_package-0.4.4.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
enzyme_python_package
|