sagemath/sage

sage.env.sage_include_directories: Remove hard dependency on numpy

Closed this issue · 21 comments

(extracted from and needed for #29865)

sage_include_directories returns the basic list of include directories for compiling extensions, not including directories obtained through pkgconfig etc. This basic list includes directories supplied by numpy. This is fine for the monolithic Sage library because numpy is a standard package; but in the course of modularization, we will have various distributions that do not need the dependency on numpy.
We use try/expect around the import and call to numpy.

CC: @kiwifb @tobiasdiez

Component: refactoring

Author: Matthias Koeppe

Branch/Commit: 4550eb6

Reviewer: François Bissey

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

Author: Matthias Koeppe

Commit: 19776a3

New commits:

19776a3sage.env.sage_include_directories: Do not fail if numpy cannot be imported

Description changed:

--- 
+++ 
@@ -1 +1 @@
-
+(extracted from #29865)

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

e16ba2dsrc/sage/doctest/control.py: Do not fail if sage.libs.arb cannot be imported

Changed commit from 19776a3 to e16ba2d

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

Changed commit from e16ba2d to 19776a3

comment:5

I think there should still be a log message if numpy couldn't be found, since otherwise errors further down the compile chain might be hard to track down.

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

4550eb6sage.env.sage_include_directories: Do not fail if numpy cannot be imported

Changed commit from 19776a3 to 4550eb6

Description changed:

--- 
+++ 
@@ -1 +1,2 @@
-(extracted from #29865)
+(extracted from and needed for #29865)
+
comment:9

The branch looks fine. Can the description be a bit more verbose on what this change will achieve? Obviously it makes the thing touched more resilient but for what purpose.

Description changed:

--- 
+++ 
@@ -1,2 +1,6 @@
 (extracted from and needed for #29865)
 
+`sage_include_directories` returns the basic list of include directories for compiling extensions, not including directories obtained through pkgconfig etc.  This basic list includes directories supplied by numpy. This is fine for the monolithic Sage library because `numpy` is a standard package; but in the course of modularization, we will have various distributions that do not need the dependency on numpy. 
+We use try/expect around the import and call to numpy.
+
+

Reviewer: François Bissey

comment:11

LGTM.

comment:12

Thanks!

comment:13
+    try:
+        import numpy
+        dirs.append(numpy.get_include())
+    except ModuleNotFoundError:
+        pass

Should this not better print an error message in case numpy is not found?

comment:14

No, the whole point of this ticket is that it's not an error.