diff --git a/README.SUSE b/README.SUSE new file mode 100644 index 0000000..33f03c5 --- /dev/null +++ b/README.SUSE @@ -0,0 +1,2 @@ +Additional functionality for these tools can be gained by installing python3-networkx. This pulls in many dependencies and is +not needed for most people, therefor it's not required or recommended due to the size of the required dependencies diff --git a/make_networkx_optional.patch b/make_networkx_optional.patch new file mode 100644 index 0000000..de1116b --- /dev/null +++ b/make_networkx_optional.patch @@ -0,0 +1,87 @@ +From 716a1d9e1db6701c0b310dd7e10dc4a10656da0f Mon Sep 17 00:00:00 2001 +From: Chris PeBenito +Date: Tue, 14 Dec 2021 14:24:20 -0500 +Subject: [PATCH] Make NetworkX optional. + +The CLI tools get installed to most distros, but sedta and seinfoflow are +not typically used or separated into a different package. This will allow +seinfo, sesearch, and sediff to function if NetworkX is missing, since they +don't require it. + +Signed-off-by: Chris PeBenito +--- + setools/dta.py | 18 ++++++++++++++---- + setools/infoflow.py | 17 +++++++++++++---- + 2 files changed, 27 insertions(+), 8 deletions(-) + +Index: setools/setools/dta.py +=================================================================== +--- setools.orig/setools/dta.py ++++ setools/setools/dta.py +@@ -24,8 +24,11 @@ from collections import defaultdict + from contextlib import suppress + from typing import DefaultDict, Iterable, List, NamedTuple, Optional, Union + +-import networkx as nx +-from networkx.exception import NetworkXError, NetworkXNoPath, NodeNotFound ++try: ++ import networkx as nx ++ from networkx.exception import NetworkXError, NetworkXNoPath, NodeNotFound ++except ImportError: ++ logging.getLogger(__name__).debug("NetworkX failed to import.") + + from .descriptors import EdgeAttrDict, EdgeAttrList + from .policyrep import AnyTERule, SELinuxPolicy, TERuletype, Type +@@ -87,8 +90,15 @@ class DomainTransitionAnalysis: + self.reverse = reverse + self.rebuildgraph = True + self.rebuildsubgraph = True +- self.G = nx.DiGraph() +- self.subG = self.G.copy() ++ ++ try: ++ self.G = nx.DiGraph() ++ self.subG = self.G.copy() ++ except NameError: ++ self.log.critical("NetworkX is not available. This is " ++ "requried for Domain Transition Analysis.") ++ self.log.critical("This is typically in the python3-networkx package.") ++ raise + + @property + def reverse(self) -> bool: +Index: setools/setools/infoflow.py +=================================================================== +--- setools.orig/setools/infoflow.py ++++ setools/setools/infoflow.py +@@ -21,8 +21,11 @@ import logging + from contextlib import suppress + from typing import cast, Iterable, List, Mapping, Optional, Union + +-import networkx as nx +-from networkx.exception import NetworkXError, NetworkXNoPath, NodeNotFound ++try: ++ import networkx as nx ++ from networkx.exception import NetworkXError, NetworkXNoPath, NodeNotFound ++except ImportError: ++ logging.getLogger(__name__).debug("NetworkX failed to import.") + + from .descriptors import EdgeAttrIntMax, EdgeAttrList + from .permmap import PermissionMap +@@ -68,8 +71,14 @@ class InfoFlowAnalysis: + self.rebuildgraph = True + self.rebuildsubgraph = True + +- self.G = nx.DiGraph() +- self.subG = self.G.copy() ++ try: ++ self.G = nx.DiGraph() ++ self.subG = self.G.copy() ++ except NameError: ++ self.log.critical("NetworkX is not available. This is " ++ "requried for Information Flow Analysis.") ++ self.log.critical("This is typically in the python3-networkx package.") ++ raise + + @property + def min_weight(self) -> int: diff --git a/setools.changes b/setools.changes index 87fcbe4..3558ca7 100644 --- a/setools.changes +++ b/setools.changes @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Fri Sep 2 09:24:56 UTC 2022 - Johannes Segitz + +- Added README.SUSE and drop recommend for python3-networkx altogether + (bsc#1202676) + ------------------------------------------------------------------- Tue Feb 22 09:13:19 UTC 2022 - Shung-Hsi Yu diff --git a/setools.spec b/setools.spec index 38c9f2b..cfaffd9 100644 --- a/setools.spec +++ b/setools.spec @@ -33,6 +33,7 @@ Summary: Policy analysis tools for SELinux License: GPL-2.0-only Group: System/Management Source: https://github.com/SELinuxProject/setools/releases/download/%{version}/%{name}-%{version}.tar.bz2 +Source2: README.SUSE # PATCH-FIX-UPSTREAM https://github.com/SELinuxProject/setools/pull/68 Patch1: make-networkx-optional.patch BuildRequires: fdupes @@ -75,7 +76,6 @@ Summary: Python bindings for SELinux policy analysis License: LGPL-2.0-only Group: Development/Languages/Python Requires: python3 >= 3.4 -Recommends: python3-networkx Obsoletes: python-setools < %{version}-%{release} Provides: python-setools = %{version}-%{release} %if "%{python3_primary_provider}" != "python3" @@ -112,12 +112,15 @@ This package includes the following graphical tools: %install %python_install +install -m 644 -D %{SOURCE2} %{buildroot}%{_docdir}/%{name}/README.SUSE %fdupes -s %{buildroot}%{python3_sitearch} %files -n %{python3_primary_provider}-setools %defattr(-,root,root,-) %{python3_sitearch}/setools %{python3_sitearch}/setools-%{version}*-info +%dir %{_docdir}/%{name}/ +%{_docdir}/%{name}/* %files console %defattr(-,root,root,-)