mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-11-29 20:45:11 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
90b4fc8550 |
@@ -16,7 +16,7 @@ pytestmark = pytest.mark.unit
|
|||||||
|
|
||||||
def test_is_hex_and_stable() -> None:
|
def test_is_hex_and_stable() -> None:
|
||||||
first = code_hash()
|
first = code_hash()
|
||||||
assert len(first) == 40
|
assert len(first) == 32
|
||||||
assert int(first, 16) >= 0
|
assert int(first, 16) >= 0
|
||||||
assert first == code_hash()
|
assert first == code_hash()
|
||||||
|
|
||||||
|
|||||||
@@ -16,13 +16,12 @@ def _raise(error: OSError) -> None:
|
|||||||
|
|
||||||
def code_files() -> list[str]:
|
def code_files() -> list[str]:
|
||||||
"""Framework source paths relative to the package root, in a platform-stable order."""
|
"""Framework source paths relative to the package root, in a platform-stable order."""
|
||||||
pkg = str(_PKG)
|
|
||||||
rels = ["__main__.py"]
|
rels = ["__main__.py"]
|
||||||
for name in _CODE_DIRS:
|
for name in _CODE_DIRS:
|
||||||
for root, dirs, files in os.walk(os.path.join(pkg, name), onerror=_raise):
|
for root, dirs, files in os.walk(_PKG / name, onerror=_raise):
|
||||||
dirs[:] = [d for d in dirs if d != "__pycache__"]
|
dirs[:] = [d for d in dirs if d != "__pycache__"]
|
||||||
rel = os.path.relpath(root, pkg).replace(os.sep, "/")
|
rel = os.path.relpath(root, _PKG)
|
||||||
rels.extend(f"{rel}/{f}" for f in files if f.endswith(".py"))
|
rels.extend(os.path.join(rel, f).replace(os.sep, "/") for f in files if f.endswith(".py"))
|
||||||
return sorted(rels)
|
return sorted(rels)
|
||||||
|
|
||||||
|
|
||||||
@@ -31,19 +30,17 @@ def code_hash(
|
|||||||
read: Optional[Callable[[str], bytes]] = None,
|
read: Optional[Callable[[str], bytes]] = None,
|
||||||
) -> str:
|
) -> str:
|
||||||
"""
|
"""
|
||||||
sha1 of the framework source. Two installs on the same version differ here if their code does.
|
md5 of the framework source. Identifies the running code, not the release it claims to be.
|
||||||
|
|
||||||
Pass `files` and `read` to digest a different byte source, such as blobs from git history
|
Pass `files` and `read` to digest a different byte source, such as blobs from git history
|
||||||
(see tools/resolve_code_hash.py). Returns "" when the source cannot be read.
|
(see tools/resolve_code_hash.py). Returns "" when the source cannot be read.
|
||||||
"""
|
"""
|
||||||
if read is None:
|
if read is None:
|
||||||
pkg = str(_PKG)
|
|
||||||
|
|
||||||
def read(rel: str) -> bytes:
|
def read(rel: str) -> bytes:
|
||||||
with open(os.path.join(pkg, rel), "rb") as fh:
|
return (_PKG / rel).read_bytes()
|
||||||
return fh.read()
|
|
||||||
|
|
||||||
digest = hashlib.sha1(usedforsecurity=False)
|
digest = hashlib.md5(usedforsecurity=False)
|
||||||
try:
|
try:
|
||||||
for rel in code_files() if files is None else files:
|
for rel in code_files() if files is None else files:
|
||||||
digest.update(rel.encode())
|
digest.update(rel.encode())
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ def main(version: bool, debug: bool) -> None:
|
|||||||
r" ▀▀▀ ▀▀ █▪ ▀▀▀▀ ▀▀▀ · ▀ ▀ ·▀▀▀ ·▀ ▀.▀▀▀ ▀▀▀ ",
|
r" ▀▀▀ ▀▀ █▪ ▀▀▀▀ ▀▀▀ · ▀ ▀ ·▀▀▀ ·▀ ▀.▀▀▀ ▀▀▀ ",
|
||||||
style="ascii.art",
|
style="ascii.art",
|
||||||
),
|
),
|
||||||
f"v [repr.number]{__version__}[/]{f' ({__code_hash__})' if __code_hash__ else ''}"
|
f"v [repr.number]{__version__}[/]{f' (code hash {__code_hash__})' if __code_hash__ else ''}"
|
||||||
f" - © 2025-{datetime.now().year} - github.com/unshackle-dl/unshackle",
|
f" - © 2025-{datetime.now().year} - github.com/unshackle-dl/unshackle",
|
||||||
),
|
),
|
||||||
(1, 11, 1, 10),
|
(1, 11, 1, 10),
|
||||||
|
|||||||
Reference in New Issue
Block a user