-
-
Notifications
You must be signed in to change notification settings - Fork 706
Fix include directories in editable installs #40765
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
9721552
Fix include directories in editable installs
tobiasdiez 5d1db07
Deprecate old sage_include_directories
tobiasdiez fb2f955
Make include dirs returns only existing directories, and fix include …
tobiasdiez 1353fa9
Remove usage of sage_include_directories
tobiasdiez 5a305d3
Merge remote-tracking branch 'upstream/develop' into fix-include-dir
tobiasdiez 72876f0
exit ./configure with correct exit code
dimpase 7d3c468
don't try to generate _conf.py from template (.in)
dimpase eb346cf
don't mention _conf.py(.in) in Makefile
dimpase 9568859
Remove numpy from get_include_dirs
tobiasdiez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,6 @@ | ||
| #! /bin/sh | ||
| cp conftest.py bak_conftest.py | ||
| ./real_configure $@ | ||
| realconf_result=$? | ||
| mv bak_conftest.py conftest.py | ||
| exit $realconf_result |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,149 @@ | ||
| # @configure_input@ | ||
| from pathlib import Path | ||
|
|
||
| import sage | ||
|
|
||
| VERSION = "@PACKAGE_VERSION@" | ||
|
|
||
| # The following must not be used during build to determine source or installation | ||
| # location of sagelib. See comments in SAGE_ROOT/src/Makefile.in | ||
| # These variables come first so that other substituted variable values can refer | ||
| # to it. | ||
| SAGE_LOCAL = "@prefix@" | ||
| SAGE_ROOT = "@SAGE_ROOT@" | ||
| SAGE_SHARE = "@SAGE_SHARE@" | ||
|
|
||
| # The semicolon-separated list of GAP root paths. This is the list of | ||
| # locations that are searched for GAP packages. This is passed directly | ||
| # to GAP via the -l flag. | ||
| GAP_ROOT_PATHS = "@GAP_ROOT_PATHS@".replace("${prefix}", SAGE_LOCAL) | ||
|
|
||
| # The path to the standalone maxima executable. | ||
| MAXIMA = "@SAGE_MAXIMA@".replace("${prefix}", SAGE_LOCAL) | ||
|
|
||
| # Set this to the empty string if your ECL can load maxima without | ||
| # further prodding. | ||
| MAXIMA_FAS = "@SAGE_MAXIMA_FAS@".replace("${prefix}", SAGE_LOCAL) | ||
| MAXIMA_SHARE = "@SAGE_MAXIMA_SHARE@".replace("${prefix}", SAGE_LOCAL) | ||
|
|
||
| # Delete this line if your ECL can load Kenzo without further prodding. | ||
| KENZO_FAS = "@SAGE_KENZO_FAS@".replace("${prefix}", SAGE_LOCAL) | ||
|
|
||
| NTL_INCDIR = "@NTL_INCDIR@" | ||
| NTL_LIBDIR = "@NTL_LIBDIR@" | ||
|
|
||
| # Path to the ecl-config script | ||
| ECL_CONFIG = "@SAGE_ECL_CONFIG@".replace("${prefix}", SAGE_LOCAL) | ||
|
|
||
| SAGE_NAUTY_BINS_PREFIX = "@SAGE_NAUTY_BINS_PREFIX@" | ||
|
|
||
| SAGE_ECMBIN = "@SAGE_ECMBIN@" | ||
|
|
||
| # Names or paths of the 4ti2 executables | ||
| FOURTITWO_HILBERT = "@FOURTITWO_HILBERT@" | ||
| FOURTITWO_MARKOV = "@FOURTITWO_MARKOV@" | ||
| FOURTITWO_GRAVER = "@FOURTITWO_GRAVER@" | ||
| FOURTITWO_ZSOLVE = "@FOURTITWO_ZSOLVE@" | ||
| FOURTITWO_QSOLVE = "@FOURTITWO_QSOLVE@" | ||
| FOURTITWO_RAYS = "@FOURTITWO_RAYS@" | ||
| FOURTITWO_PPI = "@FOURTITWO_PPI@" | ||
| FOURTITWO_CIRCUITS = "@FOURTITWO_CIRCUITS@" | ||
| FOURTITWO_GROEBNER = "@FOURTITWO_GROEBNER@" | ||
|
|
||
| # Colon-separated list of pkg-config modules to search for cblas functionality. | ||
| # We hard-code it here as cblas because configure (build/pkgs/openblas/spkg-configure.m4) | ||
| # always provides cblas.pc, if necessary by creating a facade pc file for a system BLAS. | ||
| CBLAS_PC_MODULES = "cblas" | ||
|
|
||
| # for sage_setup.setenv | ||
| SAGE_ARCHFLAGS = "@SAGE_ARCHFLAGS@" | ||
| SAGE_PKG_CONFIG_PATH = "@SAGE_PKG_CONFIG_PATH@".replace("$SAGE_LOCAL", SAGE_LOCAL) | ||
|
|
||
| # Used in sage.repl.ipython_kernel.install | ||
| MATHJAX_DIR = "@SAGE_MATHJAX_DIR@".replace("${prefix}", SAGE_LOCAL) | ||
| THREEJS_DIR = SAGE_LOCAL + "/share/threejs-sage" | ||
|
|
||
| # OpenMP flags, if available. | ||
| OPENMP_CFLAGS = "@OPENMP_CFLAGS@" | ||
| OPENMP_CXXFLAGS = "@OPENMP_CXXFLAGS@" | ||
|
|
||
| # Installation location of wheels. This is determined at configuration time | ||
| # and does not depend on the installation location of sage-conf. | ||
| SAGE_SPKG_WHEELS = ( | ||
| "@SAGE_VENV@".replace("${SAGE_LOCAL}", SAGE_LOCAL) + "/var/lib/sage/wheels" | ||
| ) | ||
|
|
||
|
|
||
| def is_editable_install() -> bool: | ||
| """ | ||
| Check whether this is an editable install of Sage. | ||
|
|
||
| EXAMPLES:: | ||
|
|
||
| sage: from sage.config import is_editable_install | ||
| sage: is_editable_install() | ||
| False | ||
| """ | ||
| # This function relies on the fact that meson-python sets up a custom | ||
| # loader for editable installs | ||
| # Alternatively, one could use the distribution metadata as in: | ||
| # https://github.com/scientific-python/spin/blob/89e581c7201d0f6597ffc92c3e84894f99fc133b/spin/cmds/meson.py#L39 | ||
| return type(sage.__loader__).__module__ == "_sagemath_editable_loader" | ||
|
|
||
|
|
||
| def get_editable_root() -> tuple[Path, Path] | None: | ||
| """ | ||
| Return the path to the Sage directory when using an editable | ||
| install. | ||
| Both the actual source directory and the build directory are returned, and are | ||
| guaranteed to exist. | ||
| If not using an editable install, or if the source/build directories do not | ||
| exist, return None. | ||
|
|
||
| EXAMPLES:: | ||
|
|
||
| sage: from sage.config import get_editable_root | ||
| sage: get_editable_root() | ||
| (WindowsPath('<path_to_sage>/sage'), WindowsPath('<path_to_sage>/sage/build/cp312')) | ||
| """ | ||
| if ( | ||
| not is_editable_install() | ||
| or r"@EDITABLE_SRC@" == "" | ||
| or r"@EDITABLE_BUILD@" == "" | ||
| ): | ||
| return None | ||
|
|
||
| src = Path(r"@EDITABLE_SRC@").resolve() | ||
| build = Path(r"@EDITABLE_BUILD@").resolve() | ||
| if src.is_dir() and build.is_dir(): | ||
| return src, build | ||
| return None | ||
|
|
||
|
|
||
| def get_include_dirs() -> list[Path]: | ||
| """ | ||
| Return a list of directories to be used as include directories | ||
| when compiling Cython extensions that depend on Sage. | ||
|
|
||
| Headers should be included with the prefix "sage/", e.g., | ||
| ``#include <sage/cpython/cython_metaclass.h>``. | ||
|
|
||
| EXAMPLES:: | ||
|
|
||
| sage: from sage.config import get_include_dirs | ||
| sage: dirs = get_include_dirs() | ||
| sage: dirs # random | ||
| [ | ||
| WindowsPath('<python>/site-packages'), | ||
| WindowsPath('<path_to_sage>/src'), | ||
| WindowsPath('<path_to_sage>/build/cp312/src'), | ||
| WindowsPath('<python>/site-packages/numpy/core/include') | ||
| ] | ||
| """ | ||
| dirs: list[Path] = [Path(dir).parent for dir in sage.__path__] | ||
| editable_root = get_editable_root() | ||
| if editable_root is not None: | ||
| # We return both the source and build directory, | ||
| # because some headers are generated in the build directory. | ||
| dirs.extend([root / "src" for root in editable_root]) | ||
| return [dir for dir in dirs if dir.is_dir()] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| from sage.config import get_include_dirs | ||
|
|
||
|
|
||
| def test_cython_metaclass_header_found(): | ||
| dirs = get_include_dirs() | ||
| assert any( | ||
| (dir / "sage" / "cpython" / "cython_metaclass.h").is_file() for dir in dirs | ||
| ) | ||
|
|
||
|
|
||
| def test_get_include_dirs_returns_existing_dirs(): | ||
| dirs = get_include_dirs() | ||
| for dir in dirs: | ||
| assert dir.is_dir(), f"Directory {dir} does not exist" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How can this test ever pass outside Windows?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It cannot. Do you run tests on
.py.infiles? Then we should add arandomdecoration as below.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
normally speaking .in files should not be tested.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I run tests on the installed sage (with
python -m sage.doctest -a), where this is already a.pyfile.