Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[tool.pytest.ini_options]
filterwarnings = [
"error",
"ignore::DeprecationWarning",
'ignore:distro\..*\(\) is deprecated and will be removed in a future version.*',
]
71 changes: 66 additions & 5 deletions src/distro/distro.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,9 +546,21 @@ def distro_release_info() -> Dict[str, str]:

def uname_info() -> Dict[str, str]:
"""
.. deprecated:: 1.10.0

:func:`distro.uname_info()` is deprecated and will be removed in a
future version. Please use :func:`os.uname()` or :func:`platform.uname()`
instead.

Return a dictionary containing key-value pairs for the information items
from the distro release file data source of the current OS distribution.
"""
warnings.warn(
"distro.uname_info() is deprecated and will be removed in a future version. "
"Please use os.uname() or platform.uname() instead.",
DeprecationWarning,
stacklevel=2,
)
return _distro.uname_info()


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

def uname_attr(attribute: str) -> str:
"""
.. deprecated:: 1.10.0

:func:`distro.uname_attr()` is deprecated and will be removed in a
future version. Please use :func:`os.uname()` or :func:`platform.uname()`
instead.

Return a single named information item from the distro release file
data source of the current OS distribution.

Expand All @@ -624,6 +642,12 @@ def uname_attr(attribute: str) -> str:
* (string): Value of the information item, if the item exists.
The empty string, if the item does not exist.
"""
warnings.warn(
"distro.uname_attr() is deprecated and will be removed in a future version. "
"Please use os.uname() or platform.uname() instead.",
DeprecationWarning,
stacklevel=2,
)
return _distro.uname_attr(attribute)


Expand Down Expand Up @@ -853,7 +877,7 @@ def normalize(distro_id: str, table: Dict[str, str]) -> str:
if distro_id:
return normalize(distro_id, NORMALIZED_DISTRO_ID)

distro_id = self.uname_attr("id")
distro_id = self._uname_attr("id")
if distro_id:
return normalize(distro_id, NORMALIZED_DISTRO_ID)

Expand All @@ -869,14 +893,14 @@ def name(self, pretty: bool = False) -> str:
self.os_release_attr("name")
or self.lsb_release_attr("distributor_id")
or self.distro_release_attr("name")
or self.uname_attr("name")
or self._uname_attr("name")
)
if pretty:
name = self.os_release_attr("pretty_name") or self.lsb_release_attr(
"description"
)
if not name:
name = self.distro_release_attr("name") or self.uname_attr("name")
name = self.distro_release_attr("name") or self._uname_attr("name")
version = self.version(pretty=True)
if version:
name = f"{name} {version}"
Expand All @@ -898,9 +922,9 @@ def version(self, pretty: bool = False, best: bool = False) -> str:
self._parse_distro_release_content(
self.lsb_release_attr("description")
).get("version_id", ""),
self.uname_attr("release"),
self._uname_attr("release"),
]
if self.uname_attr("id").startswith("aix"):
if self._uname_attr("id").startswith("aix"):
# On AIX platforms, prefer oslevel command output.
versions.insert(0, self.oslevel_info())
elif self.id() == "debian" or "debian" in self.like().split():
Expand Down Expand Up @@ -1042,11 +1066,25 @@ def distro_release_info(self) -> Dict[str, str]:

def uname_info(self) -> Dict[str, str]:
"""
.. deprecated:: 1.10.0

:func:`LinuxDistribution.uname_info()` is deprecated and will be removed
in a future version. Please use :func:`os.uname()` or
:func:`platform.uname()` instead.

Return a dictionary containing key-value pairs for the information
items from the uname command data source of the OS distribution.

For details, see :func:`distro.uname_info`.
"""
warnings.warn(
(
"LinuxDistribution.uname_info() is deprecated and will be removed in a"
" future version. Please use os.uname() or platform.uname() instead."
),
DeprecationWarning,
stacklevel=2,
)
return self._uname_info

def oslevel_info(self) -> str:
Expand Down Expand Up @@ -1083,6 +1121,29 @@ def distro_release_attr(self, attribute: str) -> str:
return self._distro_release_info.get(attribute, "")

def uname_attr(self, attribute: str) -> str:
"""
.. deprecated:: 1.10.0

:func:`LinuxDistribution.uname_attr()` is deprecated and will be removed in
a future version. Please use :func:`os.uname()` or :func:`platform.uname()`
instead.

Return a single named information item from the uname command
output data source of the OS distribution.

For details, see :func:`distro.uname_attr`.
"""
warnings.warn(
(
"LinuxDistribution.uname_attr() is deprecated and will be removed in a"
" future version. Please use os.uname() or platform.uname() instead."
),
DeprecationWarning,
stacklevel=2,
)
return self._uname_attr(attribute)

def _uname_attr(self, attribute: str) -> str:
"""
Return a single named information item from the uname command
output data source of the OS distribution.
Expand Down
18 changes: 9 additions & 9 deletions tests/test_distro.py
Original file line number Diff line number Diff line change
Expand Up @@ -798,9 +798,9 @@ def test_dontincludeuname(self) -> None:

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

assert self.distro.uname_attr("id") == ""
assert self.distro.uname_attr("name") == ""
assert self.distro.uname_attr("release") == ""
assert self.distro._uname_attr("id") == ""
assert self.distro._uname_attr("name") == ""
assert self.distro._uname_attr("release") == ""

def test_unknowndistro_release(self) -> None:
self._setup_for_distro(os.path.join(TESTDISTROS, "distro", "unknowndistro"))
Expand All @@ -824,17 +824,17 @@ def test_bad_uname(self) -> None:
self._setup_for_distro(os.path.join(TESTDISTROS, "distro", "baduname"))
self.distro = distro.LinuxDistribution()

assert self.distro.uname_attr("id") == ""
assert self.distro.uname_attr("name") == ""
assert self.distro.uname_attr("release") == ""
assert self.distro._uname_attr("id") == ""
assert self.distro._uname_attr("name") == ""
assert self.distro._uname_attr("release") == ""

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

assert self.distro.uname_attr("id") == ""
assert self.distro.uname_attr("name") == ""
assert self.distro.uname_attr("release") == ""
assert self.distro._uname_attr("id") == ""
assert self.distro._uname_attr("name") == ""
assert self.distro._uname_attr("release") == ""

def test_usrlibosreleaseonly(self) -> None:
self._setup_for_distro(
Expand Down