-
-
Notifications
You must be signed in to change notification settings - Fork 768
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
35
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 31 commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
d0b252d
meson.options: add the defer_runtime_checks option
orlitzky 40c9eed
src/sage/meson.build,src/sage/config.py.in: record defer_feature_checks
orlitzky 02f2ff7
src/sage/features/build_feature.py: new class for build-time features
orlitzky 3da593d
src/sage/config.py.in: add placeholder vars for build features
orlitzky 327cd99
src/**/meson.build: record build-time feature information in conf_data
orlitzky 1e825f4
src/sage/features/sagemath.py: make BRiAl a BuildFeature
orlitzky 236b4f8
src/sage/features/bliss.py: convert to a BuildFeature
orlitzky eb4d871
src/sage/features/coxeter3.py: convert to a BuildFeature
orlitzky 54f512b
src/sage/features/mcqd.py: convert to a BuildFeature
orlitzky f8dfc51
src/sage/features/meataxe.py: convert to a BuildFeature
orlitzky 11df90b
src/sage/features/sirocco.py: convert to a BuildFeature
orlitzky 3f17359
src/sage/features/tdlib.py: convert to a BuildFeature
orlitzky 0a25137
src/sage/features/rankwidth.py: new BuildFeature
orlitzky 8cd2e34
src/sage/features/mwrank.py: new feature for the mwrank program
orlitzky cf59d56
src/sage/features/sagemath.py: new feature for sage.libs.eclib
orlitzky a31d34b
src/doc/en/reference/spkg/index.rst: add sage.features.mwrank
orlitzky fd5c59d
src/doc/en/reference/spkg/index.rst: add sage.features.build_feature
orlitzky 42a964f
src/doc/en/reference/spkg/index.rst: add sage.features.rankwidth
orlitzky 31da84d
src/sage/doctest/external.py: no runtime detection for build features
orlitzky d02d9d6
conftest.py: only ignore ImportErrors for disabled features
orlitzky e25c8cb
conftest.py: ignore ImportErrors for sage.libs.eclib if disabled
orlitzky fba22ba
build/pkgs/sagelib: defer feature checks to runtime
orlitzky afe80dc
src/sage/features/build_feature.py: fix is_present() doctest
orlitzky a32706b
src/sage/features/mwrank.py: fix is_present_at_runtime()
orlitzky cadac34
src/sage/features/sagemath.py: make eclib runtime-detectable
orlitzky 1239b36
src/sage/features/sirocco.py: make sirocco runtime-detectable
orlitzky 2c364a3
src/sage/features/mcqd.py: make mcqd runtime-detectable
orlitzky 2e7bf1d
src/sage/features/meataxe.py: make meataxe runtime-detectable
orlitzky 6ce0b0c
src/sage/features/bliss.py: make bliss runtime-detectable
orlitzky 4637eaf
src/sage/features/tdlib.py: make tdlib runtime-detectable
orlitzky e6a5150
src/sage/features/coxeter3.py: make coxeter3 runtime-detectable
orlitzky e167823
src/sage/features/rankwidth.py: make rankwidth runtime-detectable
orlitzky b7638be
src/sage/features/sagemath.py: make brial runtime-detectable
orlitzky 4fadc5b
src/sage/features/bliss.py: don't import PythonModule twice
orlitzky c90afeb
src/sage/features/coxeter3.py: fix module name
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.
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.