summaryrefslogtreecommitdiff
path: root/dev-python/jaraco-context/files/jaraco-context-3.0.0-useless-deps.patch
blob: 3b69581ab2b5dc38a7a0d3e1fc61d739071aacc7 (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
From e3a1f344c296f9d6193f4bf2ac1e0cdafcddce0e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= <mgorny@gentoo.org>
Date: Mon, 20 Jul 2020 18:11:31 +0200
Subject: [PATCH] Make jaraco.apt & yg.lockfile imports optional

Handle missing jaraco.apt & yg.lockfile modules more gracefully,
delaying the error until dependency_context is actually used.  These
two modules are only used by the dependency_context, and this context
can only work on apt-based systems, so there is no point in forcing
the extraneous dependencies on systems that do not use apt where
jaraco.context is being installed for other context managers.
---
 jaraco/context.py | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/jaraco/context.py b/jaraco/context.py
index 0b5b1bc..13dfdf6 100644
--- a/jaraco/context.py
+++ b/jaraco/context.py
@@ -13,8 +13,15 @@ try:
 except Exception:
     import contextlib as contextlib2
 
-import jaraco.apt
-import yg.lockfile
+try:
+    import jaraco.apt as apt
+except ImportError:
+    apt = None
+
+try:
+    import yg.lockfile
+except ImportError:
+    yg = None
 
 
 __metaclass__ = type
@@ -131,6 +138,12 @@ def dependency_context(package_names, aggressively_remove=False):
     """
     installed_packages = []
     log = logging.getLogger(__name__)
+    if apt is None:
+        log.error("jaraco.apt not found installed")
+        raise ImportError("jaraco.apt not found installed")
+    if yg is None:
+        log.error("yg.lockfile not found installed")
+        raise ImportError("yg.lockfile not found installed")
     try:
         if not package_names:
             logging.debug('No packages requested')
@@ -144,7 +157,7 @@ def dependency_context(package_names, aggressively_remove=False):
                 stderr=subprocess.STDOUT,
             )
             log.debug('Aptitude output:\n%s', output)
-            installed_packages = jaraco.apt.parse_new_packages(
+            installed_packages = apt.parse_new_packages(
                 output, include_automatic=aggressively_remove
             )
             if not installed_packages:
-- 
2.27.0