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:
0$ ln -s <base>/contrib/signet/miner /tmp/miner
1$ /tmp/miner --help
2Traceback (most recent call last):
3 File "/tmp/miner", line 25, in <module>
4 from test_framework.blocktools import WITNESS_COMMITMENT_HEADER, script_BIP34_coinbase_height # noqa: E402
5ModuleNotFoundError: 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:
0diff --git a/contrib/signet/miner b/contrib/signet/miner
1--- a/contrib/signet/miner
2+++ b/contrib/signet/miner
3@@ -18,7 +18,7 @@ import subprocess
4 from binascii import unhexlify
5 from io import BytesIO
6
7-PATH_BASE_CONTRIB_SIGNET = os.path.abspath(os.path.dirname(__file__))
8+PATH_BASE_CONTRIB_SIGNET = os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
9 PATH_BASE_TEST_FUNCTIONAL = os.path.join(PATH_BASE_CONTRIB_SIGNET, "..", "..", "test", "functional")
10 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:
0diff --git a/contrib/signet/miner b/contrib/signet/miner
1--- a/contrib/signet/miner
2+++ b/contrib/signet/miner
3@@ -18,8 +18,8 @@ import subprocess
4 from binascii import unhexlify
5 from io import BytesIO
6
7-PATH_BASE_CONTRIB_SIGNET = os.path.abspath(os.path.dirname(__file__))
8-PATH_BASE_TEST_FUNCTIONAL = os.path.join(PATH_BASE_CONTRIB_SIGNET, "..", "..", "test", "functional")
9+PATH_BASE_CONTRIB_SIGNET = os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
10+PATH_BASE_TEST_FUNCTIONAL = os.path.abspath(os.path.join(PATH_BASE_CONTRIB_SIGNET, "..", "..", "test", "functional"))
11 sys.path.insert(0, PATH_BASE_TEST_FUNCTIONAL)
12
13 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!