Skip to content

Commit

Permalink
Got rid of imp rewriting of lib, plugins, and gui dirs
Browse files Browse the repository at this point in the history
Module `imp` is deprecated and will be removed in a future Python
version. So, rather than do the `imp` rewriting of the lib, gui, and
plugins directories, we renamed these directories to electroncash,
electroncash_gui, and electroncash_plugins to match the Python module
names.

All setup and packaging files have been updated such that Windows,
Linux AppImage, OSX, iOS and srcdist now build correctly using these new
directories.

Android has not been properly migrated over yet, but that will be coming
soon.

Also in this commit: updated Dockerfiles for Wine and Linux AppImage
builds since they grew stale and some package versions needed updating.

We also bumped the app version to 4.2.0 since this filesystem renaming
change can potentially be considedered a significant enough change, as
per semantic versioning.
  • Loading branch information
cculianu committed Oct 18, 2020
1 parent c4ecb02 commit 08269d1
Show file tree
Hide file tree
Showing 246 changed files with 109 additions and 145 deletions.
8 changes: 3 additions & 5 deletions .gitignore
Expand Up @@ -17,7 +17,9 @@ env/
bin/
/app.fil
tmp/
lib/*.so.0
electroncash/*.so.0
electroncash/*.dylib
contrib/osx/*.dylib

# tox files
.cache/
Expand All @@ -37,7 +39,3 @@ xcuserdata/
# mypy
.mypy_cache/

# Some people need to set up these symlinks to get their IDE completion working
electroncash
electroncash_gui
electroncash_plugins
6 changes: 3 additions & 3 deletions android/Dockerfile
Expand Up @@ -31,16 +31,16 @@ COPY android/build-requirements.txt android/
RUN wget -O - https://bootstrap.pypa.io/get-pip.py | python3.6 && \
pip3 install -r android/build-requirements.txt
COPY contrib/make_locale contrib/
COPY gui gui
COPY electroncash_gui electroncash_gui
COPY ios/ElectronCash/electroncash_gui/ios_native ios/ElectronCash/electroncash_gui/ios_native
COPY plugins plugins
COPY electroncash_plugins electroncash_plugins

# The app itself. Specifically check for the keystore, otherwise it'll build an APK with no
# certificates.
COPY android android
COPY android/keystore.jks android/
COPY contrib/deterministic-build contrib/deterministic-build
COPY lib lib
COPY electroncash electroncash

RUN echo "sdk.dir=$(pwd)/android-sdk" > android/local.properties
RUN cd android && ./gradlew app:assembleMainNetRelease
15 changes: 2 additions & 13 deletions android/app/build.gradle
Expand Up @@ -21,7 +21,7 @@ android {
targetSdkVersion 29

def ecVersion = null
file("$REPO_ROOT/lib/version.py").eachLine {
file("$REPO_ROOT/electroncash/version.py").eachLine {
def matcher = it =~ / *PACKAGE_VERSION *= *'([0-9.]+)'.*/
if (matcher.matches()) {
ecVersion = matcher.group(1)
Expand Down Expand Up @@ -59,7 +59,7 @@ android {
main {
python {
srcDir REPO_ROOT
include "lib/**" // In ../.. (renamed below)
include "electroncash/**" // In ../..
include("chaquopy/**", "electroncash_gui/**", // In src/main/python
"electroncash_plugins/**") //
exclude "**/*.po", "**/*.pot"
Expand Down Expand Up @@ -132,17 +132,6 @@ afterEvaluate {
}

for (variant in android.applicationVariants) {
// Rename directories to match package names, like package_dir does in setup.py.
def task = tasks.getByName("merge${variant.name.capitalize()}PythonSources")
def dstDir = task.destinationDir
task.doLast {
def src = "$dstDir/lib"
def dst = "$dstDir/electroncash"
if (! file(src).renameTo(dst)) {
throw new GradleException("Failed to rename $src to $dst")
}
}

tasks.getByName("generate${variant.name.capitalize()}Resources")
.dependsOn(stringsTask)
}
Expand Down
2 changes: 1 addition & 1 deletion android/app/generate_strings.py
Expand Up @@ -44,7 +44,7 @@ def main():
log("Running make_locale")
run([sys.executable, join(EC_ROOT, "contrib/make_locale")], check=True)

locale_dir = join(EC_ROOT, "lib/locale")
locale_dir = join(EC_ROOT, "electroncash/locale")
lang_strings = defaultdict(list)
for lang_region in [name for name in os.listdir(locale_dir)
if isdir(join(locale_dir, name)) and name != '__pycache__']:
Expand Down
2 changes: 1 addition & 1 deletion contrib/build-linux/appimage/_build.sh
Expand Up @@ -100,7 +100,7 @@ info "Preparing electrum-locale"
fail "Please install gettext"
fi
for i in ./locale/*; do
dir="$PROJECT_ROOT/lib/$i/LC_MESSAGES"
dir="$PROJECT_ROOT/electroncash/$i/LC_MESSAGES"
mkdir -p $dir
msgfmt --output-file="$dir/electron-cash.mo" "$i/electron-cash.po" || true
done
Expand Down
6 changes: 3 additions & 3 deletions contrib/build-wine/_build.sh
Expand Up @@ -182,9 +182,9 @@ prepare_wine() {

# libsecp256k1, libzbar & libusb
mkdir -p $WINEPREFIX/drive_c/tmp
cp "$here"/../../lib/*.dll $WINEPREFIX/drive_c/tmp/ || fail "Could not copy libraries to their destination"
cp "$here"/../../electroncash/*.dll $WINEPREFIX/drive_c/tmp/ || fail "Could not copy libraries to their destination"
cp libusb/libusb/.libs/libusb-1.0.dll $WINEPREFIX/drive_c/tmp/ || fail "Could not copy libusb to its destination"
cp "$here"/../../lib/tor/bin/tor.exe $WINEPREFIX/drive_c/tmp/ || fail "Could not copy tor.exe to its destination"
cp "$here"/../../electroncash/tor/bin/tor.exe $WINEPREFIX/drive_c/tmp/ || fail "Could not copy tor.exe to its destination"

info "Installing pyscard..."
wget -O $PYSCARD_FILENAME "$PYSCARD_URL"
Expand Down Expand Up @@ -234,7 +234,7 @@ build_the_app() {
find -exec touch -d '2000-11-11T11:11:11+00:00' {} +
popd # go back to $here

cp -r "$here"/../electrum-locale/locale $WINEPREFIX/drive_c/electroncash/lib/
cp -r "$here"/../electrum-locale/locale $WINEPREFIX/drive_c/electroncash/electroncash/

# Install frozen dependencies
info "Installing frozen dependencies ..."
Expand Down
60 changes: 29 additions & 31 deletions contrib/build-wine/deterministic.spec
Expand Up @@ -49,15 +49,15 @@ binaries += [b for b in collect_dynamic_libs('PyQt5') if 'qwindowsvista' in b[0]
binaries += [('C:/python*/Lib/site-packages/smartcard/scard/_scard.cp36-win32.pyd', '.')] # Satochip

datas = [
(home+'lib/currencies.json', 'electroncash'),
(home+'lib/servers.json', 'electroncash'),
(home+'lib/servers_testnet.json', 'electroncash'),
(home+'lib/servers_testnet4.json', 'electroncash'),
(home+'lib/servers_scalenet.json', 'electroncash'),
(home+'lib/wordlist/english.txt', 'electroncash/wordlist'),
(home+'lib/locale', 'electroncash/locale'),
(home+'gui/qt/data/ecsupplemental_win.ttf', 'electroncash_gui/qt/data'),
(home+'plugins', 'electroncash_plugins'),
(home+'electroncash/currencies.json', 'electroncash'),
(home+'electroncash/servers.json', 'electroncash'),
(home+'electroncash/servers_testnet.json', 'electroncash'),
(home+'electroncash/servers_testnet4.json', 'electroncash'),
(home+'electroncash/servers_scalenet.json', 'electroncash'),
(home+'electroncash/wordlist/english.txt', 'electroncash/wordlist'),
(home+'electroncash/locale', 'electroncash/locale'),
(home+'electroncash_gui/qt/data/ecsupplemental_win.ttf', 'electroncash_gui/qt/data'),
(home+'electroncash_plugins', 'electroncash_plugins'),
]
datas += collect_data_files('trezorlib')
datas += collect_data_files('btchip')
Expand All @@ -66,31 +66,29 @@ datas += collect_data_files('mnemonic') # wordlists used by keepkeylib from lib

# We don't put these files in to actually include them in the script but to make the Analysis method scan them for imports
a = Analysis([home+'electron-cash',
home+'gui/qt/main_window.py',
home+'gui/qt/qrreader/camera_dialog.py',
home+'gui/text.py',
home+'lib/util.py',
home+'lib/wallet.py',
home+'lib/simple_config.py',
home+'lib/bitcoin.py',
home+'lib/dnssec.py',
home+'lib/commands.py',
home+'lib/tor/controller.py',
home+'plugins/cosigner_pool/qt.py',
home+'plugins/email_requests/qt.py',
home+'plugins/trezor/clientbase.py',
home+'plugins/trezor/trezor.py',
home+'plugins/trezor/qt.py',
home+'plugins/keepkey/qt.py',
home+'plugins/ledger/qt.py',
home+'plugins/satochip/qt.py', # Satochip
home+'plugins/fusion/fusion.py', # CashFusion
home+'plugins/fusion/qt.py', # CashFusion
#home+'packages/requests/utils.py'
home+'electroncash_gui/qt/main_window.py',
home+'electroncash_gui/qt/qrreader/camera_dialog.py',
home+'electroncash_gui/text.py',
home+'electroncash/util.py',
home+'electroncash/wallet.py',
home+'electroncash/simple_config.py',
home+'electroncash/bitcoin.py',
home+'electroncash/dnssec.py',
home+'electroncash/commands.py',
home+'electroncash/tor/controller.py',
home+'electroncash_plugins/cosigner_pool/qt.py',
home+'electroncash_plugins/email_requests/qt.py',
home+'electroncash_plugins/trezor/clientbase.py',
home+'electroncash_plugins/trezor/trezor.py',
home+'electroncash_plugins/trezor/qt.py',
home+'electroncash_plugins/keepkey/qt.py',
home+'electroncash_plugins/ledger/qt.py',
home+'electroncash_plugins/satochip/qt.py', # Satochip
home+'electroncash_plugins/fusion/fusion.py', # CashFusion
home+'electroncash_plugins/fusion/qt.py', # CashFusion
],
binaries=binaries,
datas=datas,
#pathex=[home+'lib', home+'gui', home+'plugins'],
hiddenimports=hiddenimports,
hookspath=[])

Expand Down
2 changes: 1 addition & 1 deletion contrib/gen_icons.sh
Expand Up @@ -34,4 +34,4 @@ for icon in $RASTERIZE ; do
done

echo "Generating icons.py"
pyrcc5 icons.qrc -o gui/qt/icons.py
pyrcc5 icons.qrc -o electroncash_gui/qt/icons.py
14 changes: 7 additions & 7 deletions contrib/make_locale
Expand Up @@ -17,11 +17,11 @@ os.chdir('..')

code_directories = [
'android/app/src/main/python',
'gui',
'electroncash_gui',
'ios/ElectronCash/electroncash_gui', # ios/ElectronCash could contain duplicate files
# copied by make_ios_project.sh.
'lib',
'plugins',
'electroncash',
'electroncash_plugins',
]
file_types = ('*.py', '*.kv')

Expand All @@ -41,13 +41,13 @@ with open("app.fil", "w") as f:
print("Found {} files to translate".format(n))

# Generate fresh translation template
if not os.path.exists('lib/locale'):
os.mkdir('lib/locale')
cmd = 'xgettext -s --from-code UTF-8 --language Python --no-wrap -f app.fil --keyword=pgettext:1c,2 --keyword=npgettext:1c,2,3 -c --output=lib/locale/messages.pot'
if not os.path.exists('electroncash/locale'):
os.mkdir('electroncash/locale')
cmd = 'xgettext -s --from-code UTF-8 --language Python --no-wrap -f app.fil --keyword=pgettext:1c,2 --keyword=npgettext:1c,2,3 -c --output=electroncash/locale/messages.pot'
print('Generate template')
os.system(cmd)

os.chdir('lib')
os.chdir('electroncash')

crowdin_identifier = 'electron-cash'
crowdin_file_name = 'files[electron-cash-client/messages.pot]'
Expand Down
4 changes: 2 additions & 2 deletions contrib/make_secp
Expand Up @@ -32,6 +32,6 @@ make -j$WORKER_COUNT || fail "Could not build $pkgname"
make install || fail "Could not install $pkgname"
. "$here/$pkgname/dist/lib/libsecp256k1.la"
host_strip "$here/$pkgname/dist/lib/$dlname"
cp -fpv "$here/$pkgname/dist/lib/$dlname" "$here/../lib" || fail "Could not copy the $pkgname binary to its destination"
info "$dlname has been placed in the 'lib' folder."
cp -fpv "$here/$pkgname/dist/lib/$dlname" "$here/../electroncash/." || fail "Could not copy the $pkgname binary to its destination"
info "$dlname has been placed in the 'electroncash' folder."
popd
6 changes: 3 additions & 3 deletions contrib/make_tor
Expand Up @@ -47,8 +47,8 @@ if [ "$BUILD_TYPE" = "wine" ] ; then
binary="tor.exe"
fi
host_strip "$here/$pkgname/dist/bin/$binary"
mkdir -p "$here/../lib/tor/bin"
cp -fpv "$here/$pkgname/dist/bin/$binary" "$here/../lib/tor/bin" || fail "Could not copy the $pkgname binary to its destination"
mkdir -p "$here/../electroncash/tor/bin"
cp -fpv "$here/$pkgname/dist/bin/$binary" "$here/../electroncash/tor/bin/." || fail "Could not copy the $pkgname binary to its destination"
$SHA256_PROG "$here/$pkgname/dist/bin/$binary"
info "$binary has been placed in the 'lib' folder."
info "$binary has been placed in the 'electroncash' folder."
popd
4 changes: 2 additions & 2 deletions contrib/make_zbar
Expand Up @@ -39,6 +39,6 @@ make -j$WORKER_COUNT || fail "Could not build $pkgname"
make install || fail "Could not install $pkgname"
. "$here/$pkgname/dist/lib/libzbar.la"
host_strip "$here/$pkgname/dist/lib/$dlname"
cp -fpv "$here/$pkgname/dist/lib/$dlname" "$here/../lib" || fail "Could not copy the $pkgname binary to its destination"
info "$dlname has been placed in the 'lib' folder."
cp -fpv "$here/$pkgname/dist/lib/$dlname" "$here/../electroncash/." || fail "Could not copy the $pkgname binary to its destination"
info "$dlname has been placed in the 'electroncash' folder."
popd
2 changes: 1 addition & 1 deletion contrib/osx/make_osx
Expand Up @@ -266,7 +266,7 @@ if ((DARWIN_VER >= 18 && FORCE_MOJAVE_DARK)); then
fi

# Sign the Tor binary separately
DoCodeSignMaybe "tor binary" "dist/${PACKAGE}.app/Contents/Resources/electroncash/tor/bin/tor" "$APP_SIGN"
DoCodeSignMaybe "tor binary" "dist/${PACKAGE}.app/Contents/MacOS/electroncash/tor/bin/tor" "$APP_SIGN"
# Finally, codesign the whole thing
DoCodeSignMaybe ".app bundle" "dist/${PACKAGE}.app" "$APP_SIGN"

Expand Down
58 changes: 29 additions & 29 deletions contrib/osx/osx.spec
Expand Up @@ -28,14 +28,14 @@ hiddenimports += collect_submodules('satochip') # Satochip
hiddenimports += collect_submodules('smartcard') # Satochip

datas = [
(home+'lib/currencies.json', PYPKG),
(home+'lib/servers.json', PYPKG),
(home+'lib/servers_testnet.json', PYPKG),
(home+'lib/servers_testnet4.json', PYPKG),
(home+'lib/servers_scalenet.json', PYPKG),
(home+'lib/wordlist/english.txt', PYPKG + '/wordlist'),
(home+'lib/locale', PYPKG + '/locale'),
(home+'plugins', PYPKG + '_plugins'),
(home+'electroncash/currencies.json', PYPKG),
(home+'electroncash/servers.json', PYPKG),
(home+'electroncash/servers_testnet.json', PYPKG),
(home+'electroncash/servers_testnet4.json', PYPKG),
(home+'electroncash/servers_scalenet.json', PYPKG),
(home+'electroncash/wordlist/english.txt', PYPKG + '/wordlist'),
(home+'electroncash/locale', PYPKG + '/locale'),
(home+'electroncash_plugins', PYPKG + '_plugins'),
]
datas += collect_data_files('trezorlib')
datas += collect_data_files('btchip')
Expand All @@ -50,33 +50,33 @@ binaries += [(home + "contrib/osx/libsecp256k1.0.dylib", ".")]
# LibZBar for QR code scanning
binaries += [(home + "contrib/osx/libzbar.0.dylib", ".")]
# Add Tor binary
binaries += [(home + "lib/tor/bin/tor", ".")]
binaries += [(home + "electroncash/tor/bin/tor", "electroncash/tor/bin")]

# Workaround for "Retro Look":
binaries += [b for b in collect_dynamic_libs('PyQt5') if 'macstyle' in b[0]]

# We don't put these files in to actually include them in the script but to make the Analysis method scan them for imports
a = Analysis([home+MAIN_SCRIPT,
home+'gui/qt/main_window.py',
home+'gui/qt/qrreader/camera_dialog.py',
home+'gui/text.py',
home+'lib/util.py',
home+'lib/wallet.py',
home+'lib/simple_config.py',
home+'lib/bitcoin.py',
home+'lib/dnssec.py',
home+'lib/commands.py',
home+'lib/tor/controller.py',
home+'plugins/cosigner_pool/qt.py',
home+'plugins/email_requests/qt.py',
home+'plugins/trezor/clientbase.py',
home+'plugins/trezor/trezor.py',
home+'plugins/trezor/qt.py',
home+'plugins/keepkey/qt.py',
home+'plugins/ledger/qt.py',
home+'plugins/satochip/qt.py', # Satochip
home+'plugins/fusion/fusion.py', # CashFusion
home+'plugins/fusion/qt.py', # CashFusion
home+'electroncash_gui/qt/main_window.py',
home+'electroncash_gui/qt/qrreader/camera_dialog.py',
home+'electroncash_gui/text.py',
home+'electroncash/util.py',
home+'electroncash/wallet.py',
home+'electroncash/simple_config.py',
home+'electroncash/bitcoin.py',
home+'electroncash/dnssec.py',
home+'electroncash/commands.py',
home+'electroncash/tor/controller.py',
home+'electroncash_plugins/cosigner_pool/qt.py',
home+'electroncash_plugins/email_requests/qt.py',
home+'electroncash_plugins/trezor/clientbase.py',
home+'electroncash_plugins/trezor/trezor.py',
home+'electroncash_plugins/trezor/qt.py',
home+'electroncash_plugins/keepkey/qt.py',
home+'electroncash_plugins/ledger/qt.py',
home+'electroncash_plugins/satochip/qt.py', # Satochip
home+'electroncash_plugins/fusion/fusion.py', # CashFusion
home+'electroncash_plugins/fusion/qt.py', # CashFusion
],
binaries=binaries,
datas=datas,
Expand Down
4 changes: 2 additions & 2 deletions contrib/secp_HOWTO.md
Expand Up @@ -19,14 +19,14 @@ You have a few options:

- If on **Windows**, it's recommended you run one of the [release .exe files available here](https://www.electroncash.org/#download). The library is included in the `.exe`.
- If on **macOS**, it's recommended you install Electron Cash from the [release .dmg available here](https://www.electroncash.org/#download). The library is included in the `.app` bundle.
- For **Linux x86_64** (the most common architecture), the Electron Cash [release srcdist .tar.gz available here](https://www.electroncash.org/#download) should have the library pre-compiled and living in the `lib/` subfolder of the tarball. You can simply run Electron Cash "from source" (which, paradoxically, does include a compiled library embedded within it), and it should work.
- For **Linux x86_64** (the most common architecture), the Electron Cash [release srcdist .tar.gz available here](https://www.electroncash.org/#download) should have the library pre-compiled and living in the `electroncash/` subfolder of the tarball. You can simply run Electron Cash "from source" (which, paradoxically, does include a compiled library embedded within it), and it should work.
- For other architectures and/or Unixey OS's, or if running from *git head* then proceed to the sections below.

### If running from github head -- dev mode ;)

- `git clone` the latest git head from [https://github.com/Electron-Cash/Electron-Cash](https://github.com/Electron-Cash/Electron-Cash) (or `git pull` from master if you already have it cloned).
- run the script `contrib/make_secp`
- **Done!** If all goes well, `libsecp256k1` should low live alongside the Python files in the lib/ subfolder of Electron Cash. If not, make sure you have a C-compiler installed on the system as well as automake, and libtool installed and try again.
- **Done!** If all goes well, `libsecp256k1` should low live alongside the Python files in the `electroncash/` subfolder of Electron Cash. If not, make sure you have a C-compiler installed on the system as well as automake, and libtool installed and try again.

### If you are running from the "srcdist" (.tar.gz) but the provided .so file doesn't work...

Expand Down
9 changes: 2 additions & 7 deletions electron-cash
Expand Up @@ -26,7 +26,8 @@
# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import os, sys
import os
import sys

# Workaround for PyQt5 5.12.3
# see https://github.com/pyinstaller/pyinstaller/issues/4293
Expand Down Expand Up @@ -91,12 +92,6 @@ def check_imports():
if not is_android: # Avoid unnecessarily slowing down app startup.
check_imports()

# load local lib etc modules as electroncash*
if is_local:
import imp
imp.load_module('electroncash', *imp.find_module('lib'))
imp.load_module('electroncash_gui', *imp.find_module('gui'))
imp.load_module('electroncash_plugins', *imp.find_module('plugins'))

from electroncash import bitcoin, util
from electroncash import SimpleConfig, Network
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 08269d1

Please sign in to comment.