Skip to content

Commit

Permalink
Drop Python < 3.10 support
Browse files Browse the repository at this point in the history
Python 3.10 is the default in Jammy, while Debian Bookworm has 3.11.
Since we dropped CI for older releases, we need to remove compatibility
code that won't be exercised in the tests.
  • Loading branch information
schopin-pro authored and bdrung committed Jul 10, 2023
1 parent ddf1764 commit 0ba290f
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 51 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ Please see https://wiki.ubuntu.com/Apport for more details and further links.
The files in [doc/](./doc/) document particular details such as package hooks,
crash database configuration, or the internal data format.

Platform requirements
---------------------

The absolute minimum requirements for your distribution are Python 3.10 or
above. Depending on which features you want enabled, various Python packages
also need to be available.

TODO: document the Python dependencies

Temporarily enabling apport
===========================

Expand Down
47 changes: 2 additions & 45 deletions apport/packaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,53 +9,10 @@
# option) any later version. See http://www.gnu.org/copyleft/gpl.html for
# the full text of the license.

import platform
import re
import subprocess
import sys
import typing

try:
from platform import freedesktop_os_release
except ImportError: # Python < 3.10

def _parse_os_release(*os_release_files: str) -> typing.Dict[str, str]:
"""Parse os-release and return a parameter dictionary.
This function will behave identical to
platform.freedesktop_os_release() from Python >= 3.10, if
called with ("/etc/os-release", "/usr/lib/os-release").
See http://www.freedesktop.org/software/systemd/man/os-release.html
for specification of the file format.
"""
# These fields are mandatory fields with well-known defaults
# in practice all Linux distributions override NAME, ID, and
# PRETTY_NAME.
ret = {"NAME": "Linux", "ID": "linux", "PRETTY_NAME": "Linux"}

errno = None
for filename in os_release_files:
try:
with open(filename, encoding="utf-8") as release_file:
regex = re.compile("^([\\w]+)=(?:'|\")?(.*?)(?:'|\")?$")
for line in release_file:
match = regex.match(line.strip())
if match:
# Shell special characters ("$", quotes, backslash,
# backtick) are escaped with backslashes
ret[match.group(1)] = re.sub(
r'\\([$"\'\\`])', r"\1", match.group(2)
)
break
except OSError as error:
errno = error.errno
else:
raise OSError(errno, f"Unable to read files {', '.join(os_release_files)}")

return ret

def freedesktop_os_release() -> typing.Dict[str, str]:
return _parse_os_release("/etc/os-release", "/usr/lib/os-release")


class PackageInfo:
Expand Down Expand Up @@ -379,7 +336,7 @@ def get_os_version(self):
return self._os_version

try:
info = freedesktop_os_release()
info = platform.freedesktop_os_release()
name = self._sanitize_operating_system_name(info["NAME"])
version = info.get("VERSION_ID")
if name and version:
Expand Down
5 changes: 3 additions & 2 deletions apport/packaging_impl/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import importlib
import os
import platform

from apport.packaging import PackageInfo, freedesktop_os_release
from apport.packaging import PackageInfo


def determine_packaging_implementation() -> str:
"""Determine the packaging implementation for the host."""
info = freedesktop_os_release()
info = platform.freedesktop_os_release()
assert info is not None
ids = set([info["ID"]]) | set(info.get("ID_LIKE", "").split(" "))
if "debian" in ids:
Expand Down
5 changes: 3 additions & 2 deletions apport/packaging_impl/apt_dpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import logging
import os
import pickle
import platform
import shutil
import stat
import subprocess
Expand All @@ -40,7 +41,7 @@
import aptsources.sourceslist

import apport.logging
from apport.packaging import PackageInfo, freedesktop_os_release
from apport.packaging import PackageInfo


class __AptDpkgPackageInfo(PackageInfo):
Expand Down Expand Up @@ -1761,7 +1762,7 @@ def get_distro_codename(self):
"""Get "lsb_release -sc", cache the result."""
if self._distro_codename is None:
try:
info = freedesktop_os_release()
info = platform.freedesktop_os_release()
self._distro_codename = info["VERSION_CODENAME"]
except (KeyError, OSError):
# Fall back to query lsb_release
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_packaging_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


class TestPackagingImpl(unittest.TestCase):
@unittest.mock.patch("apport.packaging_impl.freedesktop_os_release")
@unittest.mock.patch("platform.freedesktop_os_release")
def test_determine_ubuntu(self, os_release_mock):
os_release_mock.return_value = {
"PRETTY_NAME": "Ubuntu 22.04.1 LTS",
Expand All @@ -21,7 +21,7 @@ def test_determine_ubuntu(self, os_release_mock):
self.assertEqual(determine_packaging_implementation(), "apt_dpkg")
os_release_mock.assert_called_once_with()

@unittest.mock.patch("apport.packaging_impl.freedesktop_os_release")
@unittest.mock.patch("platform.freedesktop_os_release")
def test_determine_debian_unstable(self, os_release_mock):
os_release_mock.return_value = {
"PRETTY_NAME": "Debian GNU/Linux bookworm/sid",
Expand Down

0 comments on commit 0ba290f

Please sign in to comment.