diff --git a/Lib/sysconfig/__init__.py b/Lib/sysconfig/__init__.py index 0657e458806e9b..0f1674dae787d1 100644 --- a/Lib/sysconfig/__init__.py +++ b/Lib/sysconfig/__init__.py @@ -755,6 +755,8 @@ def get_platform(): osname, release, machine = _osx_support.get_platform_osx( get_config_vars(), osname, release, machine) + elif osname == "freebsd": + release = release.partition('-')[0] return '-'.join(map(str, filter(None, (osname, release, machine)))) diff --git a/Lib/test/test_sysconfig.py b/Lib/test/test_sysconfig.py index 6b90f2960672b6..3c67d04f175531 100644 --- a/Lib/test/test_sysconfig.py +++ b/Lib/test/test_sysconfig.py @@ -390,6 +390,16 @@ def test_get_platform(self): '#1 Tue Jan 9 20:35:43 UTC 2018', machine)) self.assertEqual(get_platform(), f'android-9-{abi}') + # FreeBSD + os.name = 'posix' + sys.platform = 'freebsd' + self._set_uname(( + 'FreeBSD', 'localhost', '15.1-RELEASE-p4', + 'FreeBSD 15.1-RELEASE-p4 releng/15.1-n283627-e38a7085f3a8 GENERIC', + 'amd64' + )) + self.assertEqual(get_platform(), 'freebsd-15.1-amd64') + # XXX more platforms to tests here @unittest.skipIf(is_wasi, "Incompatible with WASI mapdir and OOT builds") diff --git a/Misc/NEWS.d/next/Library/2026-10-16-16-44-15.gh-issue-159550.mrjZIG.rst b/Misc/NEWS.d/next/Library/2026-10-16-16-44-15.gh-issue-159550.mrjZIG.rst new file mode 100644 index 00000000000000..fc6170bed1b2b1 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-10-16-16-44-15.gh-issue-159550.mrjZIG.rst @@ -0,0 +1 @@ +On FreeBSD, :func:`sysconfig.get_platform` now omits the branch and patch level.