aboutsummaryrefslogtreecommitdiffstats
path: root/community/meld/python-3.8.patch
blob: 48fa0545d21682166a7c4fd6f5071e9575dfbbd0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
From 9cb590f9804a89d8914d0d7d6c89c336f6d86d86 Mon Sep 17 00:00:00 2001
From: Kai Willadsen <kai.willadsen@gmail.com>
Date: Mon, 6 May 2019 08:15:23 +1000
Subject: [PATCH] Update build helpers for Python 3.8 compatibility (#322)

The `linux_distribution` helper for the platform module has been removed
in Python 3.8, so we need an additional helper to check for the Debian-
style packaging layout.

Really this should be an `install_requires`, but moving our build
helpers to `setuptools` is a not-insignificant risk that I'd rather not
take when we're looking at moving to Meson.
---
 README.md             |  6 ++++++
 meld/build_helpers.py | 29 ++++++++++++++++++++++++-----
 2 files changed, 30 insertions(+), 5 deletions(-)

diff --git a/meld/build_helpers.py b/meld/build_helpers.py
index 5977b3cd..f9fb302b 100644
--- a/meld/build_helpers.py
+++ b/meld/build_helpers.py
@@ -31,6 +31,15 @@ import platform
 import sys
 from distutils.log import info
 
+try:
+    import distro
+except ImportError:
+    python_version = tuple(int(x) for x in platform.python_version_tuple())
+    if python_version >= (3, 8):
+        print(
+            'Missing build requirement "distro" Python module; '
+            'install paths may be incorrect', file=sys.stderr)
+
 
 def has_help(self):
     return "build_help" in self.distribution.cmdclass and os.name != 'nt'
@@ -404,11 +413,21 @@ class install(distutils.command.install.install):
 
     def finalize_options(self):
         special_cases = ('debian', 'ubuntu', 'linuxmint')
-        if (platform.system() == 'Linux' and
-                platform.linux_distribution()[0].lower() in special_cases):
-            # Maintain an explicit install-layout, but use deb by default
-            specified_layout = getattr(self, 'install_layout', None)
-            self.install_layout = specified_layout or 'deb'
+        if platform.system() == 'Linux':
+            # linux_distribution has been removed in Python 3.8; we require
+            # the third-party distro package for future handling.
+            try:
+                distribution = platform.linux_distribution()[0].lower()
+            except AttributeError:
+                try:
+                    distribution = distro.id()
+                except NameError:
+                    distribution = 'unknown'
+
+            if distribution in special_cases:
+                # Maintain an explicit install-layout, but use deb by default
+                specified_layout = getattr(self, 'install_layout', None)
+                self.install_layout = specified_layout or 'deb'
 
         distutils.command.install.install.finalize_options(self)
 
-- 
2.22.0