sagemath/sage

Replace use of `sage.misc.package.PackageNotFoundError` (2); lazy_import: Add keyword argument 'feature'

mkoeppe opened this issue · 19 comments

This helps with the modularization of sagelib.

We demonstrate its use by simplifying:

  • sage.groups.braid (which depends on the optional library libbraiding via sage.libs.libbraiding). Actually a standard package
  • sage.sat.solvers.cryptominisat, .picosat
  • sage.matrix.matrix_space (meataxe)
  • sage.graphs.graph (tdlib, mcqd)

This simplification helps eliminate the use of sage.misc.package.PackageNotFoundError. See #30607.

CC: @kiwifb @jhpalmieri @slel @seblabbe @dcoudert

Component: refactoring

Author: Matthias Koeppe

Branch: e1f6624

Reviewer: David Coudert

Issue created by migration from https://trac.sagemath.org/ticket/30616

Branch pushed to git repo; I updated commit sha1. New commits:

fdc62f7src/sage/sat/solvers/cryptominisat.py: Use lazy_import with feature instead of try/except
30613c8src/sage/sat/solvers/picosat.py: Use lazy_import with feature instead of try/except

Description changed:

--- 
+++ 
@@ -1,5 +1,7 @@
 This helps with the modularization of sagelib.
 
-We demonstrate its use by simplifying `sage.groups.braid` (which depends on the optional library `libbraiding` via `sage.libs.libbraiding`).
+We demonstrate its use by simplifying:
+- `sage.groups.braid` (which depends on the optional library `libbraiding` via `sage.libs.libbraiding`). Actually a standard package
+- `sage.sat.solvers.cryptominisat`, `.picosat`
+- `sage.matrix.matrix_space` (`meataxe`)
 
-

Author: Matthias Koeppe

Description changed:

--- 
+++ 
@@ -4,4 +4,10 @@
 - `sage.groups.braid` (which depends on the optional library `libbraiding` via `sage.libs.libbraiding`). Actually a standard package
 - `sage.sat.solvers.cryptominisat`, `.picosat`
 - `sage.matrix.matrix_space` (`meataxe`)
+- `sage.graphs.graph` (`tdlib`, `mcqd`)
 
+This simplification helps eliminate the use of `sage.misc.package.PackageNotFoundError`.  See #30607.
+
+
+
+

Changed commit from 30613c8 to e1f6624

Branch pushed to git repo; I updated commit sha1. New commits:

f2b5a1cGraph.treewidth: Fix up logic in algorithm selection
e1f6624Graph.{treewidth,clique_maximum,clique_number}: Use features instead of sage.misc.package.PackageNotFoundError
comment:8

I tried before and after installing tdlib, mcqd, cryptominisat, pycosat (not obvious to know that its picosat), meataxe. Note that libbraiding was already installed (is it standard now ?). It's working well.

However, we have several pyflakes errors (see patchbot)

src/sage/graphs/graph.py:6419:20 undefined name 'mcqd'
src/sage/graphs/graph.py:6517:24 undefined name 'mcqd'

src/sage/groups/braid.py:82:1 'sage.misc.package.PackageNotFoundError' imported but unused
src/sage/groups/braid.py:1080:13 undefined name 'rightnormalform'
src/sage/groups/braid.py:1096:13 undefined name 'centralizer'
src/sage/groups/braid.py:1115:13 undefined name 'supersummitset'
src/sage/groups/braid.py:1138:13 undefined name 'greatestcommondivisor'
src/sage/groups/braid.py:1158:13 undefined name 'leastcommonmultiple'
src/sage/groups/braid.py:1183:13 undefined name 'conjugatingbraid'
src/sage/groups/braid.py:1208:13 undefined name 'conjugatingbraid'
src/sage/groups/braid.py:1236:15 undefined name 'ultrasummitset'
src/sage/groups/braid.py:1261:16 undefined name 'thurston_type'
src/sage/groups/braid.py:1326:24 undefined name 'rigidity'
src/sage/groups/braid.py:1358:15 undefined name 'sliding_circuits'

src/sage/matrix/matrix_space.py:287:24 undefined name 'Matrix_gfpn_dense'

src/sage/sat/solvers/cryptominisat.py:72:24 undefined name 'Solver'

src/sage/sat/solvers/picosat.py:63:23 undefined name 'solve'
slel commented
comment:9

Replying to @dcoudert:

Note that libbraiding was already installed (is it standard now ?).

Yes, see build/pkgs/libbraiding/type which you can either
check with this command:

$ cat build/pkgs/libbraiding/type
standard

or by viewing that file online:

This happened in

  • #25705 Make libhomfly and libbraiding standard packages

which was merged in Sage 8.4.beta0.

comment:10

Thanks.

Can we do something for the pyflakes issues or is it the prize to pay for lazy import ?

comment:11

Unfortunately that's the prize to pay...

Reviewer: David Coudert

comment:12

So then.

comment:13

Thank you!

comment:14

Replying to @mkoeppe:

Unfortunately that's the price to pay...

Follow-up: #30647 - Make lazy_import more friendly to pyflakes and other static checkers

kliem commented
comment:16

I'm going to add the missing documentation on #30587.

kliem commented

Changed commit from e1f6624 to none