Skip to content

Commit 1650c1a

Browse files
author
Release Manager
committed
Trac #31333: sage.env.sage_include_directories: Remove hard dependency on numpy
(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. URL: https://trac.sagemath.org/31333 Reported by: mkoeppe Ticket author(s): Matthias Koeppe Reviewer(s): François Bissey
2 parents 265cd13 + 4550eb6 commit 1650c1a

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/sage/env.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ def _get_shared_lib_path(*libnames: str) -> Optional[str]:
317317
GAP_SO = var("GAP_SO", _get_shared_lib_path("gap", ""))
318318

319319
# post process
320-
if ' ' in DOT_SAGE:
320+
if DOT_SAGE is not None and ' ' in DOT_SAGE:
321321
if UNAME[:6] == 'CYGWIN':
322322
# on windows/cygwin it is typical for the home directory
323323
# to have a space in it. Fortunately, users also have
@@ -378,14 +378,18 @@ def sage_include_directories(use_sources=False):
378378
sage: any(os.path.isfile(os.path.join(d, file)) for d in dirs)
379379
True
380380
"""
381-
import numpy
382381
import distutils.sysconfig
383382

384383
TOP = SAGE_SRC if use_sources else SAGE_LIB
385384

386-
return [TOP,
387-
distutils.sysconfig.get_python_inc(),
388-
numpy.get_include()]
385+
dirs = [TOP,
386+
distutils.sysconfig.get_python_inc()]
387+
try:
388+
import numpy
389+
dirs.append(numpy.get_include())
390+
except ModuleNotFoundError:
391+
pass
392+
return dirs
389393

390394
def get_cblas_pc_module_name() -> str:
391395
"""

0 commit comments

Comments
 (0)