Skip to content

Commit 1fec59b

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.11.0, in order to allow API removals in the future (e.g. distro v2). > closes #322
1 parent 7ce285c commit 1fec59b

File tree

2 files changed

+69
-14
lines changed

2 files changed

+69
-14
lines changed

src/distro/distro.py

+60-5
Original file line numberDiff line numberDiff line change
@@ -546,9 +546,19 @@ def distro_release_info() -> Dict[str, str]:
546546

547547
def uname_info() -> Dict[str, str]:
548548
"""
549+
.. deprecated:: 1.11.0
550+
551+
:func:`distro.uname_info()` is deprecated and will be removed in a
552+
future version.
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+
DeprecationWarning,
560+
stacklevel=2,
561+
)
552562
return _distro.uname_info()
553563

554564

@@ -612,6 +622,11 @@ def distro_release_attr(attribute: str) -> str:
612622

613623
def uname_attr(attribute: str) -> str:
614624
"""
625+
.. deprecated:: 1.11.0
626+
627+
:func:`distro.uname_attr()` is deprecated and will be removed in a
628+
future version.
629+
615630
Return a single named information item from the distro release file
616631
data source of the current OS distribution.
617632
@@ -624,6 +639,11 @@ def uname_attr(attribute: str) -> str:
624639
* (string): Value of the information item, if the item exists.
625640
The empty string, if the item does not exist.
626641
"""
642+
warnings.warn(
643+
"distro.uname_attr() is deprecated and will be removed in a future version.",
644+
DeprecationWarning,
645+
stacklevel=2,
646+
)
627647
return _distro.uname_attr(attribute)
628648

629649

@@ -853,7 +873,7 @@ def normalize(distro_id: str, table: Dict[str, str]) -> str:
853873
if distro_id:
854874
return normalize(distro_id, NORMALIZED_DISTRO_ID)
855875

856-
distro_id = self.uname_attr("id")
876+
distro_id = self._uname_attr("id")
857877
if distro_id:
858878
return normalize(distro_id, NORMALIZED_DISTRO_ID)
859879

@@ -869,14 +889,14 @@ def name(self, pretty: bool = False) -> str:
869889
self.os_release_attr("name")
870890
or self.lsb_release_attr("distributor_id")
871891
or self.distro_release_attr("name")
872-
or self.uname_attr("name")
892+
or self._uname_attr("name")
873893
)
874894
if pretty:
875895
name = self.os_release_attr("pretty_name") or self.lsb_release_attr(
876896
"description"
877897
)
878898
if not name:
879-
name = self.distro_release_attr("name") or self.uname_attr("name")
899+
name = self.distro_release_attr("name") or self._uname_attr("name")
880900
version = self.version(pretty=True)
881901
if version:
882902
name = f"{name} {version}"
@@ -898,9 +918,9 @@ def version(self, pretty: bool = False, best: bool = False) -> str:
898918
self._parse_distro_release_content(
899919
self.lsb_release_attr("description")
900920
).get("version_id", ""),
901-
self.uname_attr("release"),
921+
self._uname_attr("release"),
902922
]
903-
if self.uname_attr("id").startswith("aix"):
923+
if self._uname_attr("id").startswith("aix"):
904924
# On AIX platforms, prefer oslevel command output.
905925
versions.insert(0, self.oslevel_info())
906926
elif self.id() == "debian" or "debian" in self.like().split():
@@ -1042,11 +1062,24 @@ def distro_release_info(self) -> Dict[str, str]:
10421062

10431063
def uname_info(self) -> Dict[str, str]:
10441064
"""
1065+
.. deprecated:: 1.11.0
1066+
1067+
:func:`LinuxDistribution.uname_info()` is deprecated and will be removed
1068+
in a future version.
1069+
10451070
Return a dictionary containing key-value pairs for the information
10461071
items from the uname command data source of the OS distribution.
10471072
10481073
For details, see :func:`distro.uname_info`.
10491074
"""
1075+
warnings.warn(
1076+
(
1077+
"LinuxDistribution.uname_info() is deprecated and will be removed in a"
1078+
" future version."
1079+
),
1080+
DeprecationWarning,
1081+
stacklevel=2,
1082+
)
10501083
return self._uname_info
10511084

10521085
def oslevel_info(self) -> str:
@@ -1083,6 +1116,28 @@ def distro_release_attr(self, attribute: str) -> str:
10831116
return self._distro_release_info.get(attribute, "")
10841117

10851118
def uname_attr(self, attribute: str) -> str:
1119+
"""
1120+
.. deprecated:: 1.11.0
1121+
1122+
:func:`LinuxDistribution.uname_attr()` is deprecated and will be removed in
1123+
a future version.
1124+
1125+
Return a single named information item from the uname command
1126+
output data source of the OS distribution.
1127+
1128+
For details, see :func:`distro.uname_attr`.
1129+
"""
1130+
warnings.warn(
1131+
(
1132+
"LinuxDistribution.uname_attr() is deprecated and will be removed in a"
1133+
" future version."
1134+
),
1135+
DeprecationWarning,
1136+
stacklevel=2,
1137+
)
1138+
return self._uname_attr(attribute)
1139+
1140+
def _uname_attr(self, attribute: str) -> str:
10861141
"""
10871142
Return a single named information item from the uname command
10881143
output data source of the OS distribution.

tests/test_distro.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -779,9 +779,9 @@ def test_dontincludeuname(self) -> None:
779779

780780
self.distro = distro.LinuxDistribution(include_uname=False)
781781

782-
assert self.distro.uname_attr("id") == ""
783-
assert self.distro.uname_attr("name") == ""
784-
assert self.distro.uname_attr("release") == ""
782+
assert self.distro._uname_attr("id") == ""
783+
assert self.distro._uname_attr("name") == ""
784+
assert self.distro._uname_attr("release") == ""
785785

786786
def test_unknowndistro_release(self) -> None:
787787
self._setup_for_distro(os.path.join(TESTDISTROS, "distro", "unknowndistro"))
@@ -805,17 +805,17 @@ def test_bad_uname(self) -> None:
805805
self._setup_for_distro(os.path.join(TESTDISTROS, "distro", "baduname"))
806806
self.distro = distro.LinuxDistribution()
807807

808-
assert self.distro.uname_attr("id") == ""
809-
assert self.distro.uname_attr("name") == ""
810-
assert self.distro.uname_attr("release") == ""
808+
assert self.distro._uname_attr("id") == ""
809+
assert self.distro._uname_attr("name") == ""
810+
assert self.distro._uname_attr("release") == ""
811811

812812
def test_empty_uname(self) -> None:
813813
self._setup_for_distro(os.path.join(TESTDISTROS, "distro", "emptyuname"))
814814
self.distro = distro.LinuxDistribution()
815815

816-
assert self.distro.uname_attr("id") == ""
817-
assert self.distro.uname_attr("name") == ""
818-
assert self.distro.uname_attr("release") == ""
816+
assert self.distro._uname_attr("id") == ""
817+
assert self.distro._uname_attr("name") == ""
818+
assert self.distro._uname_attr("release") == ""
819819

820820
def test_usrlibosreleaseonly(self) -> None:
821821
self._setup_for_distro(

0 commit comments

Comments
 (0)