Skip to content

Commit 323c75e

Browse files
authored
Merge pull request #63 from nexB/add-new-system-markers
Add-new-system-markers
2 parents 24d436c + b5a26aa commit 323c75e

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

CHANGELOG.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
Release notes
22
=============
33

4+
Version 31.1.0 - (2024-05-15)
5+
------------------------------
6+
7+
- Add ``on_macos_arm64`` and ``on_ubuntu_22`` markers to ``commoncode.system``.
8+
9+
410
Version 31.0.3 - (2023-08-25)
511
------------------------------
612

src/commoncode/system.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,49 @@ def is_on_macos_14_or_higher():
7171
del is_on_macos_14_or_higher
7272

7373

74+
def is_on_macos_arm64():
75+
"""
76+
Return True if the current OS is macOS running on Apple Silicon.
77+
"""
78+
import platform
79+
return on_mac and platform.machine() == 'arm64'
80+
81+
82+
on_macos_arm64 = is_on_macos_arm64()
83+
84+
del is_on_macos_arm64
85+
86+
87+
def get_etc_os_release_info(os_release_path='/etc/os-release'):
88+
"""
89+
Return a dictionary of key-value pairs from /etc/os-release
90+
"""
91+
os_release_data = {}
92+
with open(os_release_path) as f:
93+
for line in f:
94+
split_line = line.split('=')
95+
if not split_line:
96+
continue
97+
k = split_line[0].strip()
98+
v = split_line[-1].strip()
99+
os_release_data[k] = v
100+
return os_release_data
101+
102+
103+
def is_on_ubuntu_22():
104+
"""
105+
Return True if the current OS is Ubuntu 22.XX.
106+
"""
107+
if not on_linux:
108+
return False
109+
os_release_info = get_etc_os_release_info()
110+
return os_release_info['ID'] == 'ubuntu' and '22' in os_release_info['VERSION_ID']
111+
112+
on_ubuntu_22 = is_on_ubuntu_22()
113+
114+
del is_on_ubuntu_22
115+
116+
74117
def has_case_sensitive_fs():
75118
"""
76119
Return True if the current FS is case sensitive.

0 commit comments

Comments
 (0)