delphi-code 0.1.0__tar.gz → 0.1.1__tar.gz
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.
- {delphi_code-0.1.0 → delphi_code-0.1.1}/PKG-INFO +1 -1
- {delphi_code-0.1.0 → delphi_code-0.1.1}/delphi_code/download.py +4 -0
- {delphi_code-0.1.0 → delphi_code-0.1.1}/delphi_code/model.py +7 -1
- {delphi_code-0.1.0 → delphi_code-0.1.1}/delphi_code/setup.py +3 -3
- {delphi_code-0.1.0 → delphi_code-0.1.1}/delphi_code.egg-info/PKG-INFO +1 -1
- {delphi_code-0.1.0 → delphi_code-0.1.1}/pyproject.toml +1 -1
- delphi_code-0.1.1/tests/test_model_defaults.py +41 -0
- {delphi_code-0.1.0 → delphi_code-0.1.1}/tests/test_setup.py +7 -0
- delphi_code-0.1.0/tests/test_model_defaults.py +0 -20
- {delphi_code-0.1.0 → delphi_code-0.1.1}/LICENSE +0 -0
- {delphi_code-0.1.0 → delphi_code-0.1.1}/README.md +0 -0
- {delphi_code-0.1.0 → delphi_code-0.1.1}/THIRD_PARTY_NOTICES.md +0 -0
- {delphi_code-0.1.0 → delphi_code-0.1.1}/delphi_code/__init__.py +0 -0
- {delphi_code-0.1.0 → delphi_code-0.1.1}/delphi_code/__main__.py +0 -0
- {delphi_code-0.1.0 → delphi_code-0.1.1}/delphi_code/cli.py +0 -0
- {delphi_code-0.1.0 → delphi_code-0.1.1}/delphi_code/files.py +0 -0
- {delphi_code-0.1.0 → delphi_code-0.1.1}/delphi_code/indexing.py +0 -0
- {delphi_code-0.1.0 → delphi_code-0.1.1}/delphi_code/model_provenance.json +0 -0
- {delphi_code-0.1.0 → delphi_code-0.1.1}/delphi_code/paths.py +0 -0
- {delphi_code-0.1.0 → delphi_code-0.1.1}/delphi_code.egg-info/SOURCES.txt +0 -0
- {delphi_code-0.1.0 → delphi_code-0.1.1}/delphi_code.egg-info/dependency_links.txt +0 -0
- {delphi_code-0.1.0 → delphi_code-0.1.1}/delphi_code.egg-info/entry_points.txt +0 -0
- {delphi_code-0.1.0 → delphi_code-0.1.1}/delphi_code.egg-info/requires.txt +0 -0
- {delphi_code-0.1.0 → delphi_code-0.1.1}/delphi_code.egg-info/top_level.txt +0 -0
- {delphi_code-0.1.0 → delphi_code-0.1.1}/setup.cfg +0 -0
- {delphi_code-0.1.0 → delphi_code-0.1.1}/tests/test_cross_project.py +0 -0
- {delphi_code-0.1.0 → delphi_code-0.1.1}/tests/test_index_directory.py +0 -0
- {delphi_code-0.1.0 → delphi_code-0.1.1}/tests/test_project_names.py +0 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import json
|
|
2
|
+
import logging
|
|
2
3
|
from pathlib import Path
|
|
3
4
|
import ssl
|
|
4
5
|
import sys
|
|
@@ -8,6 +9,9 @@ from urllib.request import urlopen
|
|
|
8
9
|
def main():
|
|
9
10
|
from huggingface_hub import snapshot_download
|
|
10
11
|
|
|
12
|
+
# The Hub nags anonymous clients to set HF_TOKEN; the pinned public model needs none.
|
|
13
|
+
logging.getLogger("huggingface_hub.utils._http").addFilter(lambda record: "HF_TOKEN" not in record.getMessage())
|
|
14
|
+
|
|
11
15
|
manifest = json.loads(Path(__file__).with_name("model_provenance.json").read_text())
|
|
12
16
|
destination = Path(sys.argv[1])
|
|
13
17
|
snapshot_download(
|
|
@@ -4,6 +4,12 @@ import shlex
|
|
|
4
4
|
from pathlib import Path
|
|
5
5
|
|
|
6
6
|
|
|
7
|
+
def incidental(relative):
|
|
8
|
+
# Files that travel with the model but never affect embeddings: documentation, provenance,
|
|
9
|
+
# and dotfile metadata left by the OS or downloader (.DS_Store, ._*, .cache).
|
|
10
|
+
return relative.name in {"README.md", "LICENSE", "provenance.json"} or any(part.startswith(".") for part in relative.parts)
|
|
11
|
+
|
|
12
|
+
|
|
7
13
|
class Failure(Exception):
|
|
8
14
|
def __init__(self, code, message, exit_code=3):
|
|
9
15
|
super().__init__(message)
|
|
@@ -32,7 +38,7 @@ def inspect_model(value):
|
|
|
32
38
|
digest = hashlib.sha256()
|
|
33
39
|
for path in sorted(root.rglob("*")):
|
|
34
40
|
relative = path.relative_to(root)
|
|
35
|
-
if
|
|
41
|
+
if incidental(relative):
|
|
36
42
|
continue
|
|
37
43
|
if path.is_file():
|
|
38
44
|
digest.update(relative.as_posix().encode() + b"\0")
|
|
@@ -10,7 +10,7 @@ import subprocess
|
|
|
10
10
|
import sys
|
|
11
11
|
import tempfile
|
|
12
12
|
|
|
13
|
-
from .model import Failure
|
|
13
|
+
from .model import Failure, incidental
|
|
14
14
|
from .paths import index_root
|
|
15
15
|
|
|
16
16
|
|
|
@@ -26,7 +26,7 @@ def verify_assets(root):
|
|
|
26
26
|
raise Failure("model_invalid", f"Model asset checksum mismatch: {path}")
|
|
27
27
|
allowed = set(manifest["sha256"]) | {"provenance.json"}
|
|
28
28
|
for path in root.rglob("*"):
|
|
29
|
-
if
|
|
29
|
+
if not incidental(path.relative_to(root)) and path.is_file() and path.relative_to(root).as_posix() not in allowed:
|
|
30
30
|
raise Failure("model_invalid", f"Unexpected model asset: {path}")
|
|
31
31
|
return manifest
|
|
32
32
|
|
|
@@ -78,7 +78,7 @@ def provision(args):
|
|
|
78
78
|
staged = Path(temporary) / "model"
|
|
79
79
|
if source:
|
|
80
80
|
verify_assets(source)
|
|
81
|
-
shutil.copytree(source, staged, ignore=shutil.ignore_patterns("
|
|
81
|
+
shutil.copytree(source, staged, ignore=shutil.ignore_patterns(".*"))
|
|
82
82
|
else:
|
|
83
83
|
staged.mkdir()
|
|
84
84
|
print("Downloading the pinned MiniLM model…", file=sys.stderr)
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
import sys
|
|
4
|
+
import unittest
|
|
5
|
+
from unittest.mock import patch
|
|
6
|
+
|
|
7
|
+
from delphi_code.cli import arguments
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class ModelDefaults(unittest.TestCase):
|
|
11
|
+
def test_override_precedence(self):
|
|
12
|
+
with patch.dict(os.environ, {"DELPHI_CODE_MODEL": "/configured/model"}):
|
|
13
|
+
with patch.object(sys, "argv", ["delphi-code", "index"]):
|
|
14
|
+
self.assertEqual(arguments().model, "/configured/model")
|
|
15
|
+
with patch.object(sys, "argv", ["delphi-code", "index", "--model", "/explicit/model"]):
|
|
16
|
+
self.assertEqual(arguments().model, "/explicit/model")
|
|
17
|
+
|
|
18
|
+
def test_cli_uses_default_without_environment(self):
|
|
19
|
+
with patch.dict(os.environ, {}, clear=True), patch("delphi_code.cli.model_directory", return_value=Path("/local/default")), patch.object(sys, "argv", ["delphi-code", "search", "query"]):
|
|
20
|
+
self.assertEqual(arguments().model, Path("/local/default"))
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class ModelIdentity(unittest.TestCase):
|
|
24
|
+
def test_incidental_files_do_not_change_identity(self):
|
|
25
|
+
import json
|
|
26
|
+
import tempfile
|
|
27
|
+
|
|
28
|
+
from delphi_code.model import inspect_model
|
|
29
|
+
|
|
30
|
+
with tempfile.TemporaryDirectory() as temporary:
|
|
31
|
+
root = Path(temporary)
|
|
32
|
+
(root / "modules.json").write_text(json.dumps([{"type": "sentence_transformers.models.Normalize", "path": ""}]))
|
|
33
|
+
(root / "model.safetensors").write_bytes(b"weights")
|
|
34
|
+
_, before = inspect_model(root)
|
|
35
|
+
(root / ".DS_Store").write_bytes(b"finder")
|
|
36
|
+
(root / "._model.safetensors").write_bytes(b"resource fork")
|
|
37
|
+
(root / "README.md").write_text("model card")
|
|
38
|
+
(root / "LICENSE").write_text("license")
|
|
39
|
+
self.assertEqual(inspect_model(root)[1], before)
|
|
40
|
+
(root / "model.safetensors").write_bytes(b"changed")
|
|
41
|
+
self.assertNotEqual(inspect_model(root)[1], before)
|
|
@@ -96,6 +96,13 @@ class Setup(unittest.TestCase):
|
|
|
96
96
|
with self.assertRaises(Failure):
|
|
97
97
|
verify_assets(self.source)
|
|
98
98
|
|
|
99
|
+
def test_os_metadata_accepted(self):
|
|
100
|
+
(self.source / ".DS_Store").write_bytes(b"finder")
|
|
101
|
+
verify_assets(self.source)
|
|
102
|
+
(self.source / "stray.bin").write_bytes(b"extra")
|
|
103
|
+
with self.assertRaisesRegex(Failure, "Unexpected model asset"):
|
|
104
|
+
verify_assets(self.source)
|
|
105
|
+
|
|
99
106
|
def test_import_keeps_network_guard(self):
|
|
100
107
|
with self.assertRaisesRegex(RuntimeError, "Offline policy"):
|
|
101
108
|
socket.getaddrinfo("example.com", 443)
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import os
|
|
2
|
-
from pathlib import Path
|
|
3
|
-
import sys
|
|
4
|
-
import unittest
|
|
5
|
-
from unittest.mock import patch
|
|
6
|
-
|
|
7
|
-
from delphi_code.cli import arguments
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
class ModelDefaults(unittest.TestCase):
|
|
11
|
-
def test_override_precedence(self):
|
|
12
|
-
with patch.dict(os.environ, {"DELPHI_CODE_MODEL": "/configured/model"}):
|
|
13
|
-
with patch.object(sys, "argv", ["delphi-code", "index"]):
|
|
14
|
-
self.assertEqual(arguments().model, "/configured/model")
|
|
15
|
-
with patch.object(sys, "argv", ["delphi-code", "index", "--model", "/explicit/model"]):
|
|
16
|
-
self.assertEqual(arguments().model, "/explicit/model")
|
|
17
|
-
|
|
18
|
-
def test_cli_uses_default_without_environment(self):
|
|
19
|
-
with patch.dict(os.environ, {}, clear=True), patch("delphi_code.cli.model_directory", return_value=Path("/local/default")), patch.object(sys, "argv", ["delphi-code", "search", "query"]):
|
|
20
|
-
self.assertEqual(arguments().model, Path("/local/default"))
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|