Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/specify_cli/integrations/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -841,5 +841,8 @@ def tools(self) -> List[Dict[str, Any]]:

def get_hash(self) -> str:
"""SHA-256 hash of the descriptor file."""
h = hashlib.sha256()
with open(self.path, "rb") as fh:
return f"sha256:{hashlib.sha256(fh.read()).hexdigest()}"
for chunk in iter(lambda: fh.read(8192), b""):
h.update(chunk)
Comment thread
Quratulain-bilal marked this conversation as resolved.
return f"sha256:{h.hexdigest()}"
5 changes: 4 additions & 1 deletion src/specify_cli/presets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,11 @@ def tags(self) -> List[str]:

def get_hash(self) -> str:
"""Calculate SHA256 hash of manifest file."""
h = hashlib.sha256()
with open(self.path, 'rb') as f:
return f"sha256:{hashlib.sha256(f.read()).hexdigest()}"
for chunk in iter(lambda: f.read(8192), b""):
h.update(chunk)
Comment thread
Quratulain-bilal marked this conversation as resolved.
return f"sha256:{h.hexdigest()}"


class PresetRegistry:
Expand Down
4 changes: 4 additions & 0 deletions tests/integrations/test_integration_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,10 @@ def test_get_hash(self, tmp_path):
desc = IntegrationDescriptor(p)
h = desc.get_hash()
assert h.startswith("sha256:")
import hashlib
content = p.read_bytes()
expected = f"sha256:{hashlib.sha256(content).hexdigest()}"
assert h == expected

def test_tools_accessor(self, tmp_path):
data = {**VALID_DESCRIPTOR, "requires": {
Expand Down
5 changes: 4 additions & 1 deletion tests/test_presets.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,10 @@ def test_get_hash(self, pack_dir):
manifest = PresetManifest(pack_dir / "preset.yml")
hash_val = manifest.get_hash()
assert hash_val.startswith("sha256:")
assert len(hash_val) > 10
import hashlib
content = (pack_dir / "preset.yml").read_bytes()
expected = f"sha256:{hashlib.sha256(content).hexdigest()}"
assert hash_val == expected

def test_multiple_templates(self, temp_dir, valid_pack_data):
"""Test pack with multiple templates of different types."""
Expand Down