-
-
Notifications
You must be signed in to change notification settings - Fork 811
Explicit build-time features #41550
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
Open
orlitzky
wants to merge
36
commits into
sagemath:develop
Choose a base branch
from
orlitzky:build-time-features
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Explicit build-time features #41550
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
26677a1
meson.options: add the defer_runtime_checks option
orlitzky 629023d
src/sage/meson.build,src/sage/config.py.in: record defer_feature_checks
orlitzky d448425
src/sage/features/build_feature.py: new class for build-time features
orlitzky 1cdabf6
src/sage/config.py.in: add placeholder vars for build features
orlitzky 9302d2a
src/**/meson.build: record build-time feature information in conf_data
orlitzky 2175462
src/sage/features/sagemath.py: make BRiAl a BuildFeature
orlitzky 46d3c4d
src/sage/features/bliss.py: convert to a BuildFeature
orlitzky 0608eeb
src/sage/features/coxeter3.py: convert to a BuildFeature
orlitzky e62d5c6
src/sage/features/mcqd.py: convert to a BuildFeature
orlitzky bf38da2
src/sage/features/meataxe.py: convert to a BuildFeature
orlitzky 25f3844
src/sage/features/sirocco.py: convert to a BuildFeature
orlitzky 580453c
src/sage/features/tdlib.py: convert to a BuildFeature
orlitzky 260a586
src/sage/features/rankwidth.py: new BuildFeature
orlitzky 85865b6
src/sage/features/mwrank.py: new feature for the mwrank program
orlitzky a2e3826
src/sage/features/sagemath.py: new feature for sage.libs.eclib
orlitzky 6c56185
src/doc/en/reference/spkg/index.rst: add sage.features.mwrank
orlitzky b6d3eea
src/doc/en/reference/spkg/index.rst: add sage.features.build_feature
orlitzky a5aed67
src/doc/en/reference/spkg/index.rst: add sage.features.rankwidth
orlitzky c7cf752
src/sage/doctest/external.py: no runtime detection for build features
orlitzky 576e2a6
conftest.py: only ignore ImportErrors for disabled features
orlitzky 0e8efbe
conftest.py: ignore ImportErrors for sage.libs.eclib if disabled
orlitzky afe3b43
build/pkgs/sagelib: defer feature checks to runtime
orlitzky ca6bc31
src/sage/features/build_feature.py: fix is_present() doctest
orlitzky 3752036
src/sage/features/mwrank.py: fix is_present_at_runtime()
orlitzky 86d20c3
src/sage/features/sagemath.py: make eclib runtime-detectable
orlitzky 1bb60a8
src/sage/features/sirocco.py: make sirocco runtime-detectable
orlitzky c9a099e
src/sage/features/mcqd.py: make mcqd runtime-detectable
orlitzky 1d22a0d
src/sage/features/meataxe.py: make meataxe runtime-detectable
orlitzky 9eb9e06
src/sage/features/bliss.py: make bliss runtime-detectable
orlitzky cc2da29
src/sage/features/tdlib.py: make tdlib runtime-detectable
orlitzky 86bb563
src/sage/features/coxeter3.py: make coxeter3 runtime-detectable
orlitzky 24d5e0e
src/sage/features/rankwidth.py: make rankwidth runtime-detectable
orlitzky 2f1486d
src/sage/features/sagemath.py: make brial runtime-detectable
orlitzky 927a70f
src/sage/features/bliss.py: don't import PythonModule twice
orlitzky c5360d5
src/sage/features/coxeter3.py: fix module name
orlitzky bead86a
src/sage/graphs/graph_decompositions/rankwidth.pyx: add "needs"
orlitzky 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
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
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,138 @@ | ||
| r""" | ||
| Features that can be explicitly enabled or disabled at build time | ||
|
|
||
| These features are unique in that, if they are enabled or disabled at | ||
| build-time, then we usually do not want to detect them on-the-fly. | ||
| Instead we trust the value supplied (or detected) at build-time. There | ||
| is however an overrride to defer these checks to run-time (the classic | ||
| behavior) for use on binary distros or anywhere it is desirable to | ||
| enable/disable features without rebuilding sage. | ||
|
|
||
| This is an implementation of Option 3 in `Github discussion 41067 | ||
| <https://github.com/sagemath/sage/discussions/41067>`__. | ||
| """ | ||
|
|
||
| from sage.features import Feature, FeatureTestResult | ||
|
|
||
| class BuildFeature(Feature): | ||
| r""" | ||
| A class for features that can be enabled or disabled at | ||
| build-time. | ||
|
|
||
| The current implementation refers to build features that are | ||
| configurable in meson. For example:: | ||
|
|
||
| option( | ||
| 'foo', | ||
| type: 'feature', | ||
| value: 'auto', | ||
| description: 'support for foo' | ||
| ) | ||
|
|
||
| At build time, support for this "foo" will be automatically | ||
| detected, and either enabled or disabled depending on whether or | ||
| not its requirements are met. Alternatively, users may pass either | ||
| ``-Dfoo=enabled`` or ``-Dfoo=disabled`` to explicitly enable or | ||
| disable the feature. Features may be disabled regardless of | ||
| whether or not they are installed, but usually features may only | ||
| be enabled if their dependencies are present and usable. | ||
|
|
||
| In any event, after ``meson setup``, support for "foo" is either | ||
| enabled or disabled, and a boolean variable called something like | ||
| ``foo_enabled`` is written to ``sage.config``. In your subclass, | ||
| you should set the member variable ``_enabled_in_build`` to the | ||
| value of that config variable. | ||
|
|
||
| The :meth:`_is_present` method for this class will return the | ||
| value of that config variable unless ``defer_feature_checks`` is | ||
| set to ``True`` in ``sage.config``. If checks are deferred, the | ||
| :meth:`_is_present` method will try to return the value of | ||
| :meth:`is_present_at_runtime` instead. If your feature can be | ||
| detected at run-time, you should implement that check in | ||
| :meth:`is_present_at_runtime`. Otherwise, leave it unimplemented; | ||
| and :meth:`_is_present` will return ``False``. | ||
|
|
||
| EXAMPLES:: | ||
|
|
||
| sage: from sage.features.build_feature import BuildFeature | ||
| sage: BuildFeature("foo") | ||
| Feature('foo') | ||
|
|
||
| """ | ||
|
|
||
| # Set this in subclasses. | ||
| _enabled_in_build = None | ||
|
|
||
| # Implement this method if your feature is detectable at run-time. | ||
| # Your test should only return True if the feature meets Sage's | ||
| # requirements; for example, if there are doctests for gzipped foo | ||
| # data files hidden behind "needs foo", then you should ensure | ||
| # that foo was compiled with (say) --enable-zlib in your check. | ||
| # | ||
| # def is_present_at_runtime(self): | ||
| # pass | ||
|
|
||
| def is_runtime_detectable(self): | ||
| r""" | ||
| Return whether or not this feature can (and should) be | ||
| detected at runtime. | ||
|
|
||
| A feature is runtime detectable if both of the following hold: | ||
|
|
||
| - Deferred feature checks have been enabled globally by | ||
| passing ``-Ddefer_feature_checks=true`` to ``meson setup``. | ||
|
|
||
| - An ``is_present_at_runtime`` method has been implemented for | ||
| the feature. | ||
|
|
||
| EXAMPLES: | ||
|
|
||
| The method returns ``False`` if you have not implemented | ||
| ``is_present_at_runtime``:: | ||
|
|
||
| sage: from sage.features.build_feature import BuildFeature | ||
| sage: bf = BuildFeature("example") | ||
| sage: bf.is_runtime_detectable() | ||
| False | ||
|
|
||
| """ | ||
| from sage.config import defer_feature_checks | ||
| if not defer_feature_checks: | ||
| return False | ||
| elif hasattr(self, "is_present_at_runtime"): | ||
| return True | ||
| else: | ||
| return False | ||
|
|
||
| def _is_present(self): | ||
| r""" | ||
| Default presence check for build features. | ||
|
|
||
| If this feature :meth:`is_runtime_detectable`, we return the | ||
| result of that method. Otherwise, we use the value of | ||
| ``self._enabled_in_build``. | ||
|
|
||
| EXAMPLES: | ||
|
|
||
| When feature checks are deferred, runtime-detectable features | ||
| can be detected without ``self._enabled_in_build`` being set, | ||
| but this will fail by surprise when they are un-deferred:: | ||
|
|
||
| sage: from sage.config import defer_feature_checks | ||
| sage: from sage.features.build_feature import BuildFeature | ||
| sage: bf = BuildFeature("example") | ||
| sage: const_True = lambda s: True | ||
| sage: bf.is_present_at_runtime = const_True.__get__(bf) | ||
| sage: (not defer_feature_checks) or bf.is_present().is_present | ||
| True | ||
|
|
||
| """ | ||
| if self.is_runtime_detectable(): | ||
| return self.is_present_at_runtime() | ||
| else: | ||
| import sage.config | ||
| # Wrap with bool() so that we can be lazy and use meson's | ||
| # set10() rather than painstakingly writing "True" and | ||
| # "False" to the config file. | ||
| result = bool(self._enabled_in_build) | ||
| return FeatureTestResult(self, result) | ||
Oops, something went wrong.
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.
Just as an idea in the spirit of convention-over-configuration: you could query in
_is_presentbelow always the variable<name of feature>_enabledfromsage.config. Then you don't have to set_enabled_in_buildfor each feature.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 did this at first and talked myself out of it! With the current implementation, the downside to doing it by convention is that when the convention fails (e.g. mwrank, brial), you have to override the whole
_is_present()method leading to duplicated code.Given that you have to create a whole new subclass for every new feature and give it a name anyway, just spelling out the variable name in one line felt simpler.