Hi,
I usually run my binaries putting a symlink to them in a directory somewhere in my PATH (let's say /home/.local/bin, but it can be anything, really).
When doing this with miner, however, it won't work:
$ ln -s <base>/contrib/signet/miner /tmp/miner
$ /tmp/miner --help
Traceback (most recent call last):
File "/tmp/miner", line 25, in <module>
from test_framework.blocktools import WITNESS_COMMITMENT_HEADER, script_BIP34_coinbase_height # noqa: E402
ModuleNotFoundError: No module named 'test_framework'
The reason is that, when computing the absolute path to the directory containing miner, links are not followed. This would work if it included an invocation to realpath(), for example:
diff --git a/contrib/signet/miner b/contrib/signet/miner
--- a/contrib/signet/miner
+++ b/contrib/signet/miner
@@ -18,7 +18,7 @@ import subprocess
from binascii import unhexlify
from io import BytesIO
-PATH_BASE_CONTRIB_SIGNET = os.path.abspath(os.path.dirname(__file__))
+PATH_BASE_CONTRIB_SIGNET = os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
PATH_BASE_TEST_FUNCTIONAL = os.path.join(PATH_BASE_CONTRIB_SIGNET, "..", "..", "test", "functional")
sys.path.insert(0, PATH_BASE_TEST_FUNCTIONAL)
On my copy, I also called abspath() when computing the final value for PATH_BASE_TEST_FUNCTIONAL, but that's just a question of taste, because I prefer <base>/test/functional instead of <base>/contrib/signet/../../test/functional in my include path (it's more explicit to debug if something goes wrong).
The final version would be:
diff --git a/contrib/signet/miner b/contrib/signet/miner
--- a/contrib/signet/miner
+++ b/contrib/signet/miner
@@ -18,8 +18,8 @@ import subprocess
from binascii import unhexlify
from io import BytesIO
-PATH_BASE_CONTRIB_SIGNET = os.path.abspath(os.path.dirname(__file__))
-PATH_BASE_TEST_FUNCTIONAL = os.path.join(PATH_BASE_CONTRIB_SIGNET, "..", "..", "test", "functional")
+PATH_BASE_CONTRIB_SIGNET = os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
+PATH_BASE_TEST_FUNCTIONAL = os.path.abspath(os.path.join(PATH_BASE_CONTRIB_SIGNET, "..", "..", "test", "functional"))
sys.path.insert(0, PATH_BASE_TEST_FUNCTIONAL)
from test_framework.blocktools import WITNESS_COMMITMENT_HEADER, script_BIP34_coinbase_height # noqa: E402
From my experience with other Python projects, there should not be any undesired side effects, but I am not the expert here.
Do you think supporting this use case makes sense?
Thanks!