Skip to content

Commit

Permalink
Merge pull request #63 from nexB/add-new-system-markers
Browse files Browse the repository at this point in the history
Add-new-system-markers
  • Loading branch information
JonoYang authored May 15, 2024
2 parents 24d436c + b5a26aa commit 323c75e
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Release notes
=============

Version 31.1.0 - (2024-05-15)
------------------------------

- Add ``on_macos_arm64`` and ``on_ubuntu_22`` markers to ``commoncode.system``.


Version 31.0.3 - (2023-08-25)
------------------------------

Expand Down
43 changes: 43 additions & 0 deletions src/commoncode/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,49 @@ def is_on_macos_14_or_higher():
del is_on_macos_14_or_higher


def is_on_macos_arm64():
"""
Return True if the current OS is macOS running on Apple Silicon.
"""
import platform
return on_mac and platform.machine() == 'arm64'


on_macos_arm64 = is_on_macos_arm64()

del is_on_macos_arm64


def get_etc_os_release_info(os_release_path='/etc/os-release'):
"""
Return a dictionary of key-value pairs from /etc/os-release
"""
os_release_data = {}
with open(os_release_path) as f:
for line in f:
split_line = line.split('=')
if not split_line:
continue
k = split_line[0].strip()
v = split_line[-1].strip()
os_release_data[k] = v
return os_release_data


def is_on_ubuntu_22():
"""
Return True if the current OS is Ubuntu 22.XX.
"""
if not on_linux:
return False
os_release_info = get_etc_os_release_info()
return os_release_info['ID'] == 'ubuntu' and '22' in os_release_info['VERSION_ID']

on_ubuntu_22 = is_on_ubuntu_22()

del is_on_ubuntu_22


def has_case_sensitive_fs():
"""
Return True if the current FS is case sensitive.
Expand Down

0 comments on commit 323c75e

Please sign in to comment.