Skip to content

Commit e1fb9c3

Browse files
committed
Deprecates uname_attr and uname_info public methods
distro as well as LinuxDistribution `uname_attr` and `uname_info` public methods are based on `_parse_uname_content` function which purposely ignores release information part from `uname -rs` command output on Linux platforms. This makes it specially designed for distro internals, and shouldn't be publicly available as stable API. We'll deprecate these methods in v1.10.0, in order to allow API removals in the future (e.g. distro v2). Developers are notified to rather use `os.uname` or `platform.uname` API from Python standard library. > closes #322
1 parent 20d8b9d commit e1fb9c3

File tree

2 files changed

+75
-14
lines changed

2 files changed

+75
-14
lines changed

src/distro/distro.py

Lines changed: 66 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -546,9 +546,21 @@ def distro_release_info() -> Dict[str, str]:
546546

547547
def uname_info() -> Dict[str, str]:
548548
"""
549+
.. deprecated:: 1.10.0
550+
551+
:func:`distro.uname_info()` is deprecated and will be removed in a
552+
future version. Please use :func:`os.uname()` or :func:`platform.uname()`
553+
instead.
554+
549555
Return a dictionary containing key-value pairs for the information items
550556
from the distro release file data source of the current OS distribution.
551557
"""
558+
warnings.warn(
559+
"distro.uname_info() is deprecated and will be removed in a future version. "
560+
"Please use os.uname() or platform.uname() instead.",
561+
DeprecationWarning,
562+
stacklevel=2,
563+
)
552564
return _distro.uname_info()
553565

554566

@@ -612,6 +624,12 @@ def distro_release_attr(attribute: str) -> str:
612624

613625
def uname_attr(attribute: str) -> str:
614626
"""
627+
.. deprecated:: 1.10.0
628+
629+
:func:`distro.uname_attr()` is deprecated and will be removed in a
630+
future version. Please use :func:`os.uname()` or :func:`platform.uname()`
631+
instead.
632+
615633
Return a single named information item from the distro release file
616634
data source of the current OS distribution.
617635
@@ -624,6 +642,12 @@ def uname_attr(attribute: str) -> str:
624642
* (string): Value of the information item, if the item exists.
625643
The empty string, if the item does not exist.
626644
"""
645+
warnings.warn(
646+
"distro.uname_attr() is deprecated and will be removed in a future version. "
647+
"Please use os.uname() or platform.uname() instead.",
648+
DeprecationWarning,
649+
stacklevel=2,
650+
)
627651
return _distro.uname_attr(attribute)
628652

629653

@@ -853,7 +877,7 @@ def normalize(distro_id: str, table: Dict[str, str]) -> str:
853877
if distro_id:
854878
return normalize(distro_id, NORMALIZED_DISTRO_ID)
855879

856-
distro_id = self.uname_attr("id")
880+
distro_id = self._uname_attr("id")
857881
if distro_id:
858882
return normalize(distro_id, NORMALIZED_DISTRO_ID)
859883

@@ -869,14 +893,14 @@ def name(self, pretty: bool = False) -> str:
869893
self.os_release_attr("name")
870894
or self.lsb_release_attr("distributor_id")
871895
or self.distro_release_attr("name")
872-
or self.uname_attr("name")
896+
or self._uname_attr("name")
873897
)
874898
if pretty:
875899
name = self.os_release_attr("pretty_name") or self.lsb_release_attr(
876900
"description"
877901
)
878902
if not name:
879-
name = self.distro_release_attr("name") or self.uname_attr("name")
903+
name = self.distro_release_attr("name") or self._uname_attr("name")
880904
version = self.version(pretty=True)
881905
if version:
882906
name = f"{name} {version}"
@@ -898,9 +922,9 @@ def version(self, pretty: bool = False, best: bool = False) -> str:
898922
self._parse_distro_release_content(
899923
self.lsb_release_attr("description")
900924
).get("version_id", ""),
901-
self.uname_attr("release"),
925+
self._uname_attr("release"),
902926
]
903-
if self.uname_attr("id").startswith("aix"):
927+
if self._uname_attr("id").startswith("aix"):
904928
# On AIX platforms, prefer oslevel command output.
905929
versions.insert(0, self.oslevel_info())
906930
elif self.id() == "debian" or "debian" in self.like().split():
@@ -1042,11 +1066,25 @@ def distro_release_info(self) -> Dict[str, str]:
10421066

10431067
def uname_info(self) -> Dict[str, str]:
10441068
"""
1069+
.. deprecated:: 1.10.0
1070+
1071+
:func:`LinuxDistribution.uname_info()` is deprecated and will be removed
1072+
in a future version. Please use :func:`os.uname()` or :func:`platform.uname()`
1073+
instead.
1074+
10451075
Return a dictionary containing key-value pairs for the information
10461076
items from the uname command data source of the OS distribution.
10471077
10481078
For details, see :func:`distro.uname_info`.
10491079
"""
1080+
warnings.warn(
1081+
(
1082+
"LinuxDistribution.uname_info() is deprecated and will be removed in a"
1083+
" future version. Please use os.uname() or platform.uname() instead."
1084+
),
1085+
DeprecationWarning,
1086+
stacklevel=2,
1087+
)
10501088
return self._uname_info
10511089

10521090
def oslevel_info(self) -> str:
@@ -1083,6 +1121,29 @@ def distro_release_attr(self, attribute: str) -> str:
10831121
return self._distro_release_info.get(attribute, "")
10841122

10851123
def uname_attr(self, attribute: str) -> str:
1124+
"""
1125+
.. deprecated:: 1.10.0
1126+
1127+
:func:`LinuxDistribution.uname_attr()` is deprecated and will be removed in
1128+
a future version. Please use :func:`os.uname()` or :func:`platform.uname()`
1129+
instead.
1130+
1131+
Return a single named information item from the uname command
1132+
output data source of the OS distribution.
1133+
1134+
For details, see :func:`distro.uname_attr`.
1135+
"""
1136+
warnings.warn(
1137+
(
1138+
"LinuxDistribution.uname_attr() is deprecated and will be removed in a"
1139+
" future version. Please use os.uname() or platform.uname() instead."
1140+
),
1141+
DeprecationWarning,
1142+
stacklevel=2,
1143+
)
1144+
return self._uname_attr(attribute)
1145+
1146+
def _uname_attr(self, attribute: str) -> str:
10861147
"""
10871148
Return a single named information item from the uname command
10881149
output data source of the OS distribution.

tests/test_distro.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -798,9 +798,9 @@ def test_dontincludeuname(self) -> None:
798798

799799
self.distro = distro.LinuxDistribution(include_uname=False)
800800

801-
assert self.distro.uname_attr("id") == ""
802-
assert self.distro.uname_attr("name") == ""
803-
assert self.distro.uname_attr("release") == ""
801+
assert self.distro._uname_attr("id") == ""
802+
assert self.distro._uname_attr("name") == ""
803+
assert self.distro._uname_attr("release") == ""
804804

805805
def test_unknowndistro_release(self) -> None:
806806
self._setup_for_distro(os.path.join(TESTDISTROS, "distro", "unknowndistro"))
@@ -824,17 +824,17 @@ def test_bad_uname(self) -> None:
824824
self._setup_for_distro(os.path.join(TESTDISTROS, "distro", "baduname"))
825825
self.distro = distro.LinuxDistribution()
826826

827-
assert self.distro.uname_attr("id") == ""
828-
assert self.distro.uname_attr("name") == ""
829-
assert self.distro.uname_attr("release") == ""
827+
assert self.distro._uname_attr("id") == ""
828+
assert self.distro._uname_attr("name") == ""
829+
assert self.distro._uname_attr("release") == ""
830830

831831
def test_empty_uname(self) -> None:
832832
self._setup_for_distro(os.path.join(TESTDISTROS, "distro", "emptyuname"))
833833
self.distro = distro.LinuxDistribution()
834834

835-
assert self.distro.uname_attr("id") == ""
836-
assert self.distro.uname_attr("name") == ""
837-
assert self.distro.uname_attr("release") == ""
835+
assert self.distro._uname_attr("id") == ""
836+
assert self.distro._uname_attr("name") == ""
837+
assert self.distro._uname_attr("release") == ""
838838

839839
def test_usrlibosreleaseonly(self) -> None:
840840
self._setup_for_distro(

0 commit comments

Comments
 (0)