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
  • Loading branch information
schopin-pro committed Jul 10, 2023
1 parent 5786812 commit f032dd5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 43 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 requirement 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
44 changes: 1 addition & 43 deletions apport/packaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,49 +13,7 @@
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")
from platform import freedesktop_os_release


class PackageInfo:
Expand Down

0 comments on commit f032dd5

Please sign in to comment.