There are at least three ways to detect the operating system in Python3:
os.name
(https://docs.python.org/3.9/library/os.html#os.name)sys.platform
(https://docs.python.org/3.9/library/sys.html#sys.platform)platform.system()
(https://docs.python.org/3.9/library/platform.html#platform.system)
We are currently using all of them in functional tests (both in individual tests and shared test framework code), which seems a bit messy. This PR consolidates into using platform.system()
, as it appears to be one most consistent and easy to read (see also IRC discussion and table below). sys.platform
is inconsistent as it has the major version number encoded for BSD systems, which doesn’t make much sense for e.g. OpenBSD, where there is no concept of major versions, but instead the version is simply increased by 0.1 on each release.
Note that os.name
is still useful to detect whether we are running a POSIX system (see BitcoinTestFramework.skip_if_platform_not_posix
), so for this use-case it is kept as only exception. The following table shows values for common operating systems, found via
0$ python3 -c "import os; import sys; import platform; print(os.name, sys.platform, platform.system())"
OS | os.name | sys.platform | platform.system() |
---|---|---|---|
Linux 6.2.0 | posix | linux | Linux |
MacOS* | posix | darwin | Darwin |
OpenBSD 7.4 | posix | openbsd7 | OpenBSD |
Windows* | nt | win32 | Windows |
* = I neither have a MacOS nor a Windows machine available, so I extracted the values from documentation and our current code. Also I’m relying on CI for testing the relevant code-paths. Having reviewers to this this locally would be very appreciated, if this gets Concept ACKed.