Skip to content

Commit 3799a64

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 3799a64

File tree

2 files changed

+71
-14
lines changed

2 files changed

+71
-14
lines changed

src/distro/distro.py

Lines changed: 62 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -546,9 +546,20 @@ 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 `os.uname()` or `platform.uname()` instead.
553+
549554
Return a dictionary containing key-value pairs for the information items
550555
from the distro release file data source of the current OS distribution.
551556
"""
557+
warnings.warn(
558+
"distro.uname_info() is deprecated and will be removed in a future version. "
559+
"Please use os.uname() or platform.uname() instead.",
560+
DeprecationWarning,
561+
stacklevel=2,
562+
)
552563
return _distro.uname_info()
553564

554565

@@ -612,6 +623,11 @@ def distro_release_attr(attribute: str) -> str:
612623

613624
def uname_attr(attribute: str) -> str:
614625
"""
626+
.. deprecated:: 1.10.0
627+
628+
:func:`distro.uname_attr()` is deprecated and will be removed in a
629+
future version. Please use `os.uname()` or `platform.uname()` instead.
630+
615631
Return a single named information item from the distro release file
616632
data source of the current OS distribution.
617633
@@ -624,6 +640,12 @@ def uname_attr(attribute: str) -> str:
624640
* (string): Value of the information item, if the item exists.
625641
The empty string, if the item does not exist.
626642
"""
643+
warnings.warn(
644+
"distro.uname_attr() is deprecated and will be removed in a future version. "
645+
"Please use os.uname() or platform.uname() instead.",
646+
DeprecationWarning,
647+
stacklevel=2,
648+
)
627649
return _distro.uname_attr(attribute)
628650

629651

@@ -853,7 +875,7 @@ def normalize(distro_id: str, table: Dict[str, str]) -> str:
853875
if distro_id:
854876
return normalize(distro_id, NORMALIZED_DISTRO_ID)
855877

856-
distro_id = self.uname_attr("id")
878+
distro_id = self._uname_attr("id")
857879
if distro_id:
858880
return normalize(distro_id, NORMALIZED_DISTRO_ID)
859881

@@ -869,14 +891,14 @@ def name(self, pretty: bool = False) -> str:
869891
self.os_release_attr("name")
870892
or self.lsb_release_attr("distributor_id")
871893
or self.distro_release_attr("name")
872-
or self.uname_attr("name")
894+
or self._uname_attr("name")
873895
)
874896
if pretty:
875897
name = self.os_release_attr("pretty_name") or self.lsb_release_attr(
876898
"description"
877899
)
878900
if not name:
879-
name = self.distro_release_attr("name") or self.uname_attr("name")
901+
name = self.distro_release_attr("name") or self._uname_attr("name")
880902
version = self.version(pretty=True)
881903
if version:
882904
name = f"{name} {version}"
@@ -898,9 +920,9 @@ def version(self, pretty: bool = False, best: bool = False) -> str:
898920
self._parse_distro_release_content(
899921
self.lsb_release_attr("description")
900922
).get("version_id", ""),
901-
self.uname_attr("release"),
923+
self._uname_attr("release"),
902924
]
903-
if self.uname_attr("id").startswith("aix"):
925+
if self._uname_attr("id").startswith("aix"):
904926
# On AIX platforms, prefer oslevel command output.
905927
versions.insert(0, self.oslevel_info())
906928
elif self.id() == "debian" or "debian" in self.like().split():
@@ -1042,11 +1064,24 @@ def distro_release_info(self) -> Dict[str, str]:
10421064

10431065
def uname_info(self) -> Dict[str, str]:
10441066
"""
1067+
.. deprecated:: 1.10.0
1068+
1069+
:func:`LinuxDistribution.uname_info()` is deprecated and will be removed
1070+
in a future version. Please use `os.uname()` or `platform.uname()` instead.
1071+
10451072
Return a dictionary containing key-value pairs for the information
10461073
items from the uname command data source of the OS distribution.
10471074
10481075
For details, see :func:`distro.uname_info`.
10491076
"""
1077+
warnings.warn(
1078+
(
1079+
"LinuxDistribution.uname_info() is deprecated and will be removed in a"
1080+
" future version. Please use os.uname() or platform.uname() instead."
1081+
),
1082+
DeprecationWarning,
1083+
stacklevel=2,
1084+
)
10501085
return self._uname_info
10511086

10521087
def oslevel_info(self) -> str:
@@ -1083,6 +1118,28 @@ def distro_release_attr(self, attribute: str) -> str:
10831118
return self._distro_release_info.get(attribute, "")
10841119

10851120
def uname_attr(self, attribute: str) -> str:
1121+
"""
1122+
.. deprecated:: 1.10.0
1123+
1124+
:func:`LinuxDistribution.uname_attr()` is deprecated and will be removed in
1125+
a future version. Please use `os.uname()` or `platform.uname()` instead.
1126+
1127+
Return a single named information item from the uname command
1128+
output data source of the OS distribution.
1129+
1130+
For details, see :func:`distro.uname_attr`.
1131+
"""
1132+
warnings.warn(
1133+
(
1134+
"LinuxDistribution.uname_attr() is deprecated and will be removed in a"
1135+
" future version. Please use os.uname() or platform.uname() instead."
1136+
),
1137+
DeprecationWarning,
1138+
stacklevel=2,
1139+
)
1140+
return self._uname_attr(attribute)
1141+
1142+
def _uname_attr(self, attribute: str) -> str:
10861143
"""
10871144
Return a single named information item from the uname command
10881145
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)