Skip to content

Commit

Permalink
fix: remove base58 dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
vberlier committed Feb 11, 2022
1 parent 5b05865 commit f649ff6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 23 deletions.
17 changes: 11 additions & 6 deletions beet/toolchain/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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+)|(\[\])")
Expand Down Expand Up @@ -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:
Expand Down
17 changes: 1 addition & 16 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down

0 comments on commit f649ff6

Please sign in to comment.