diff --git a/beet/toolchain/utils.py b/beet/toolchain/utils.py index e3b5c7ea..9cdd56be 100644 --- a/beet/toolchain/utils.py +++ b/beet/toolchain/utils.py @@ -13,18 +13,16 @@ import json import re -import struct from traceback import format_exception -from typing import Any, Callable, Literal, Mapping, Sequence +from typing import Any, Callable, List, Literal, Mapping, Sequence -from base58 import b58encode from pydantic import ValidationError FNV_32_INIT = 0x811C9DC5 FNV_64_INIT = 0xCBF29CE484222325 FNV_32_PRIME = 0x01000193 FNV_64_PRIME = 0x100000001B3 -HASH_ALPHABET = b"123456789abcdefghijkmnopqrstuvwxyz" +HASH_ALPHABET = "123456789abcdefghijkmnopqrstuvwxyz" OPTION_KEY_REGEX = re.compile(r"(\w+)|(\[\])") @@ -60,8 +58,15 @@ def stable_int_hash(value: Any, size: Literal[32, 64] = 64) -> int: def stable_hash(value: Any, short: bool = False) -> str: result = stable_int_hash(value, size=32 if short else 64) - fmt = ">I" if short else ">Q" - return b58encode(struct.pack(fmt, result), HASH_ALPHABET).decode() + return encode_with_alphabet(result, HASH_ALPHABET) + + +def encode_with_alphabet(value: int, alphabet: str) -> str: + indices: List[int] = [] + while value: + value, i = divmod(value, len(alphabet)) + indices.append(i) + return "".join(alphabet[i] for i in reversed(indices)) def format_exc(exc: BaseException) -> str: diff --git a/poetry.lock b/poetry.lock index 101df87f..7bbaafdf 100644 --- a/poetry.lock +++ b/poetry.lock @@ -88,17 +88,6 @@ category = "dev" optional = false python-versions = "*" -[[package]] -name = "base58" -version = "2.1.1" -description = "Base58 and Base58Check implementation." -category = "main" -optional = false -python-versions = ">=3.5" - -[package.extras] -tests = ["mypy", "PyHamcrest (>=2.0.2)", "pytest (>=4.6)", "pytest-benchmark", "pytest-cov", "pytest-flake8"] - [[package]] name = "beautifulsoup4" version = "4.10.0" @@ -1908,7 +1897,7 @@ image = ["Pillow"] [metadata] lock-version = "1.1" python-versions = "^3.8" -content-hash = "0ca7dae82376e15a599b05a76c365ae4624d325c6147e9b920caabaf922a2237" +content-hash = "5e10ae4f1a72b3823c836b06ccd4507b47151ab3963e3688eebed26c25c230c8" [metadata.files] alabaster = [ @@ -1952,10 +1941,6 @@ backcall = [ {file = "backcall-0.2.0-py2.py3-none-any.whl", hash = "sha256:fbbce6a29f263178a1f7915c1940bde0ec2b2a967566fe1c65c1dfb7422bd255"}, {file = "backcall-0.2.0.tar.gz", hash = "sha256:5cbdbf27be5e7cfadb448baf0aa95508f91f2bbc6c6437cd9cd06e2a4c215e1e"}, ] -base58 = [ - {file = "base58-2.1.1-py3-none-any.whl", hash = "sha256:11a36f4d3ce51dfc1043f3218591ac4eb1ceb172919cebe05b52a5bcc8d245c2"}, - {file = "base58-2.1.1.tar.gz", hash = "sha256:c5d0cb3f5b6e81e8e35da5754388ddcc6d0d14b6c6a132cb93d69ed580a7278c"}, -] beautifulsoup4 = [ {file = "beautifulsoup4-4.10.0-py3-none-any.whl", hash = "sha256:9a315ce70049920ea4572a4055bc4bd700c940521d36fc858205ad4fcde149bf"}, {file = "beautifulsoup4-4.10.0.tar.gz", hash = "sha256:c23ad23c521d818955a4151a67d81580319d4bf548d3d49f4223ae041ff98891"}, diff --git a/pyproject.toml b/pyproject.toml index 6fe2f8b2..6d73b2a2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,7 +29,6 @@ pydantic = "^1.9.0" click = "^8.0.1" click-help-colors = "^0.9.1" Jinja2 = "^3.0.1" -base58 = "^2.1.0" toml = "^0.10.2" PyYAML = ">=5.4.1,<7.0.0" Pillow = {version = "*", optional = true}