From d05255625bf1dcce9a3a0623a3e830ad41246b84 Mon Sep 17 00:00:00 2001 From: Dmitri Bogomolov <4glitch@gmail.com> Date: Sun, 31 Jan 2021 22:23:55 +0200 Subject: [PATCH] Universal pathmagic returns app dir; activated in setup for python3 --- setup.py | 3 +++ src/bitmessagemain.py | 9 +++++---- src/pathmagic.py | 10 ++++++++++ 3 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 src/pathmagic.py diff --git a/setup.py b/setup.py index 570a4224..05e34e06 100644 --- a/setup.py +++ b/setup.py @@ -48,6 +48,9 @@ class InstallCmd(install): def unittest_discover(): """Explicit test suite creation""" + if sys.hexversion >= 0x3000000: + from pybitmessage import pathmagic + pathmagic.setup() return unittest.TestLoader().discover('pybitmessage.tests') diff --git a/src/bitmessagemain.py b/src/bitmessagemain.py index 95a631b7..29eaf13e 100755 --- a/src/bitmessagemain.py +++ b/src/bitmessagemain.py @@ -12,10 +12,11 @@ The PyBitmessage startup script import os import sys -app_dir = os.path.dirname(os.path.abspath(__file__)) -os.chdir(app_dir) -sys.path.insert(0, app_dir) - +try: + import pathmagic +except ImportError: + from pybitmessage import pathmagic +app_dir = pathmagic.setup() import depends depends.check_dependencies() diff --git a/src/pathmagic.py b/src/pathmagic.py new file mode 100644 index 00000000..3f32c0c1 --- /dev/null +++ b/src/pathmagic.py @@ -0,0 +1,10 @@ +import os +import sys + + +def setup(): + """Add path to this file to sys.path""" + app_dir = os.path.dirname(os.path.abspath(__file__)) + os.chdir(app_dir) + sys.path.insert(0, app_dir) + return app_dir