Skip to content

Commit

Permalink
Merge pull request ethereum#216 from ethereum/binary_import_fix
Browse files Browse the repository at this point in the history
Fix binaries import for intl languages
  • Loading branch information
CarlBeek authored Sep 2, 2021
2 parents cda3025 + aba63e8 commit 1378131
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 18 deletions.
17 changes: 16 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ jobs:
export PYTHONHASHSEED=42
export CIRCLE_SHORT_SHA1=$(eval echo $CIRCLE_SHA1 | cut -c -7)
export BUILD_FILE_NAME=eth2deposit-cli-${CIRCLE_SHORT_SHA1}-linux-amd64;
export TEST_FOLDER_NAME=TMP_TEST_FOLDER
mkdir ${TEST_FOLDER_NAME}
cp -r ${BUILD_FILE_NAME} ${TEST_FOLDER_NAME}
cp test_binary_script.py ${TEST_FOLDER_NAME}
cd ${TEST_FOLDER_NAME}
python test_binary_script.py ./${BUILD_FILE_NAME};
- run:
name: Compress the file
Expand Down Expand Up @@ -166,7 +171,12 @@ jobs:
$PYTHONHASHSEED = 42
$CIRCLE_SHORT_SHA1 = $env:CIRCLE_SHA1.substring(0,7)
$BUILD_FILE_NAME = "eth2deposit-cli-" + $CIRCLE_SHORT_SHA1 + "-windows-amd64"
python test_binary_script.py .\${BUILD_FILE_NAME}
$TEST_FOLDER_NAME = "TMP_TEST_FOLDER"
mkdir ${TEST_FOLDER_NAME}
Copy-item ${BUILD_FILE_NAME} -destination ${TEST_FOLDER_NAME} -recurse
copy test_binary_script.py ${TEST_FOLDER_NAME}
cd ${TEST_FOLDER_NAME}
python test_binary_script.py ${BUILD_FILE_NAME}
- run:
name: Compress the file
command: |
Expand Down Expand Up @@ -207,6 +217,11 @@ jobs:
export PYTHONHASHSEED=42
export CIRCLE_SHORT_SHA1=$(eval echo $CIRCLE_SHA1 | cut -c -7)
export BUILD_FILE_NAME=eth2deposit-cli-${CIRCLE_SHORT_SHA1}-darwin-amd64;
export TEST_FOLDER_NAME=TMP_TEST_FOLDER
mkdir ${TEST_FOLDER_NAME}
cp -r ${BUILD_FILE_NAME} ${TEST_FOLDER_NAME}
cp test_binary_script.py ${TEST_FOLDER_NAME}
cd ${TEST_FOLDER_NAME}
python3 test_binary_script.py ./${BUILD_FILE_NAME};
- run:
name: Compress the file
Expand Down
2 changes: 1 addition & 1 deletion build_configs/macos/build.spec
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ a = Analysis(['../../eth2deposit/deposit.py'],
binaries=None,
datas=[
('../../eth2deposit/key_handling/key_derivation/word_lists/*.txt', './eth2deposit/key_handling/key_derivation/word_lists/'),
('../../eth2deposit/intl', './eth2deposit/intl',)
('../../eth2deposit/intl', './eth2deposit/intl'),
],
hiddenimports=[],
hookspath=[],
Expand Down
19 changes: 4 additions & 15 deletions eth2deposit/key_handling/key_derivation/mnemonic.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import sys
from unicodedata import normalize
from secrets import randbits
from typing import (
Expand All @@ -14,19 +13,9 @@
SHA256,
PBKDF2,
)


def _resource_path(relative_path: str) -> str:
"""
Get the absolute path to a resource in a manner friendly to PyInstaller.
PyInstaller creates a temp folder and stores path in _MEIPASS which this function swaps
into a resource path so it is avaible both when building binaries and running natively.
"""
try:
base_path = sys._MEIPASS # type: ignore
except Exception:
base_path = os.path.abspath(".")
return os.path.join(base_path, relative_path)
from eth2deposit.utils.file_handling import (
resource_path,
)


def _get_word_list(language: str, path: str) -> Sequence[str]:
Expand All @@ -35,7 +24,7 @@ def _get_word_list(language: str, path: str) -> Sequence[str]:
Ref: https://github.com/bitcoin/bips/blob/master/bip-0039/bip-0039-wordlists.md
"""
path = _resource_path(path)
path = resource_path(path)
dirty_list = open(os.path.join(path, '%s.txt' % language), encoding='utf-8').readlines()
return [word.replace('\n', '') for word in dirty_list]

Expand Down
15 changes: 15 additions & 0 deletions eth2deposit/utils/file_handling.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import os
import sys


def resource_path(relative_path: str) -> str:
"""
Get the absolute path to a resource in a manner friendly to PyInstaller.
PyInstaller creates a temp folder and stores path in _MEIPASS which this function swaps
into a resource path so it is available both when building binaries and running natively.
"""
try:
base_path = sys._MEIPASS # type: ignore
except Exception:
base_path = os.path.abspath(".")
return os.path.join(base_path, relative_path)
5 changes: 4 additions & 1 deletion eth2deposit/utils/intl.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
from eth2deposit.utils.constants import (
INTL_CONTENT_PATH,
)
from eth2deposit.utils.file_handling import (
resource_path,
)
from eth2deposit.exceptions import ValidationError


Expand Down Expand Up @@ -52,7 +55,7 @@ def load_text(params: List[str], file_path: str='', func: str='', lang: str='')
# Determine path to json text
file_path_list = os.path.normpath(file_path).split(os.path.sep)
rel_path_list = file_path_list[file_path_list.index('eth2deposit') + 1:]
json_path = os.path.join(INTL_CONTENT_PATH, lang, *rel_path_list)
json_path = resource_path(os.path.join(INTL_CONTENT_PATH, lang, *rel_path_list))

try:
# browse json until text is found
Expand Down

0 comments on commit 1378131

Please sign in to comment.