Skip to content

Conversation

theStack
Copy link
Contributor

@theStack theStack commented Dec 8, 2023

There are at least three ways to detect the operating system in Python3:

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

$ 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.

@DrahtBot
Copy link
Contributor

DrahtBot commented Dec 8, 2023

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Code Coverage

For detailed information about the code coverage, see the test coverage report.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK kevkevinpal, hebasto, pablomartin4btc, achow101

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #29182 (test: randomize perturbed files excluding ldb by L0laL33tz)
  • #22729 (Make it possible to disable Tor binds and abort startup on bind failure by vasild)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@DrahtBot DrahtBot added the Tests label Dec 8, 2023
Rather than re-implementing these checks, we can use this test
framework's helper (introduced in commit
c934087, PR bitcoin#24358) called in a test's
`skip_test_if_missing_module` method instead.
@theStack theStack force-pushed the 202312-test-consolidate_os_detection_in_python branch from 7bdbd38 to 878d914 Compare December 8, 2023 17:16
@kevkevinpal
Copy link
Contributor

ACK 878d914


Ran this command to make sure we were not missing any, only seeing os.name show up for posix in test_framework.py

$ grep -nr "os\.name" ./test && grep -nr "sys\.platform" ./test

./test/functional/README.md:40:- Use `platform.system()` for detecting the running operating system and `os.name` to
./test/functional/test_framework/test_framework.py:918:        if os.name != 'posix':

I am running on MacOs 14.1.2 (23B92) and got the following from running the code provided

$ python3 -c "import os; import sys; import platform; print(os.name, sys.platform, platform.system())"

posix darwin Darwin

@hebasto
Copy link
Member

hebasto commented Dec 10, 2023

Concept ACK.

@hebasto
Copy link
Member

hebasto commented Dec 10, 2023

The following table shows values for common operating systems, found via

$ python3 -c "import os; import sys; import platform; print(os.name, sys.platform, platform.system())"
OS os.name sys.platform platform.system()
MacOS* posix darwin Darwin
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.

Confirming outputs for macOS and Windows.

Copy link
Member

@hebasto hebasto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 878d914, I have reviewed the code and it looks OK.

Copy link
Member

@pablomartin4btc pablomartin4btc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tACK 878d914

Tested on both Linux (Ubuntu 22.04 & WSL) and Windows.

As @kevkevinpal pointed it out, there's still usage of os.name in test_framework.py, not sure if you want to cover that as well.

@achow101
Copy link
Member

ACK 878d914

@achow101 achow101 merged commit bb6de1b into bitcoin:master Jan 11, 2024
@theStack theStack deleted the 202312-test-consolidate_os_detection_in_python branch January 11, 2024 17:17
@bitcoin bitcoin locked and limited conversation to collaborators Jan 10, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants