Skip to content
This repository was archived by the owner on Jan 30, 2023. It is now read-only.

Commit e1f6624

Browse files
author
Matthias Koeppe
committed
Graph.{treewidth,clique_maximum,clique_number}: Use features instead of sage.misc.package.PackageNotFoundError
1 parent f2b5a1c commit e1f6624

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

src/sage/graphs/graph.py

+7-12
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,10 @@
424424
from sage.misc.rest_index_of_methods import doc_index, gen_thematic_rest_table_index
425425
from sage.graphs.views import EdgesView
426426

427+
from sage.misc.lazy_import import lazy_import
428+
from sage.features import PythonModule
429+
lazy_import('sage.graphs.mcqd', ['mcqd'],
430+
feature=PythonModule('sage.graphs.mcqd', spkg='mcqd'))
427431

428432
class Graph(GenericGraph):
429433
r"""
@@ -2718,8 +2722,9 @@ def treewidth(self, k=None, certificate=False, algorithm=None):
27182722
# TDLIB
27192723
if algorithm == 'tdlib':
27202724
if not tdlib_found:
2721-
from sage.misc.package import PackageNotFoundError
2722-
raise PackageNotFoundError("tdlib")
2725+
from sage.features import FeatureNotPresentError
2726+
raise FeatureNotPresentError(PythonModule('sage.graphs.graph_decompositions.tdlib',
2727+
spkg='tdlib'))
27232728

27242729
T = tdlib.treedecomposition_exact(g, -1 if k is None else k)
27252730
width = tdlib.get_width(T)
@@ -6411,11 +6416,6 @@ def clique_maximum(self, algorithm="Cliquer", solver=None, verbose=0):
64116416
elif algorithm == "MILP":
64126417
return self.complement().independent_set(algorithm=algorithm, solver=solver, verbosity=verbose)
64136418
elif algorithm == "mcqd":
6414-
try:
6415-
from sage.graphs.mcqd import mcqd
6416-
except ImportError:
6417-
from sage.misc.package import PackageNotFoundError
6418-
raise PackageNotFoundError("mcqd")
64196419
return mcqd(self)
64206420
else:
64216421
raise NotImplementedError("Only 'MILP', 'Cliquer' and 'mcqd' are supported.")
@@ -6514,11 +6514,6 @@ def clique_number(self, algorithm="Cliquer", cliques=None, solver=None, verbose=
65146514
elif algorithm == "MILP":
65156515
return len(self.complement().independent_set(algorithm=algorithm, solver=solver, verbosity=verbose))
65166516
elif algorithm == "mcqd":
6517-
try:
6518-
from sage.graphs.mcqd import mcqd
6519-
except ImportError:
6520-
from sage.misc.package import PackageNotFoundError
6521-
raise PackageNotFoundError("mcqd")
65226517
return len(mcqd(self))
65236518
else:
65246519
raise NotImplementedError("Only 'networkx' 'MILP' 'Cliquer' and 'mcqd' are supported.")

0 commit comments

Comments
 (0)