-
-
Notifications
You must be signed in to change notification settings - Fork 690
Doctest hide option: Better detection of hidden packages #36741
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
Changes from 1 commit
8d0147f
fd91a03
9ada8e3
7f5a591
b61c3f5
267dc15
0f4ebc7
7728853
8560fc7
0718be2
bca471b
7083396
42adc04
dd7e714
eb908b4
1835ed4
03670bd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -158,6 +158,12 @@ def __init__(self, name, spkg=None, url=None, description=None, type='optional') | |
| self._hidden = False | ||
| self._type = type | ||
|
|
||
| # For multiprocessing of doctests, the data self._num_hidings should be | ||
| # shared among subprocesses. Thus we use the Value class from the | ||
| # multiprocessing module (cf. self._seen of class AvailableSoftware) | ||
| from multiprocessing import Value | ||
| self._num_hidings = Value('i', 0) | ||
|
|
||
| try: | ||
| from sage.misc.package import spkg_type | ||
| except ImportError: # may have been surgically removed in a downstream distribution | ||
|
|
@@ -205,15 +211,21 @@ def is_present(self): | |
| sage: TestFeature("other").is_present() | ||
| FeatureTestResult('other', True) | ||
| """ | ||
| if self._hidden: | ||
| return FeatureTestResult(self, False, reason="Feature `{name}` is hidden.".format(name=self.name)) | ||
| # We do not use @cached_method here because we wish to use | ||
| # Feature early in the build system of sagelib. | ||
| if self._cache_is_present is None: | ||
| res = self._is_present() | ||
| if not isinstance(res, FeatureTestResult): | ||
| res = FeatureTestResult(self, res) | ||
| self._cache_is_present = res | ||
|
|
||
| if self._hidden: | ||
| if self._num_hidings.value > 0: | ||
| self._num_hidings.value += 1 | ||
| elif self._cache_is_present: | ||
| self._num_hidings.value = 1 | ||
| return FeatureTestResult(self, False, reason="Feature `{name}` is hidden.".format(name=self.name)) | ||
|
|
||
| return self._cache_is_present | ||
|
|
||
| def _is_present(self): | ||
|
|
@@ -386,37 +398,34 @@ def hide(self): | |
| Feature `benzene` is hidden. | ||
| Use method `unhide` to make it available again. | ||
|
|
||
| sage: Benzene().unhide() | ||
| sage: Benzene().unhide() # optional - benzene, needs sage.graphs | ||
| 1 | ||
| sage: len(list(graphs.fusenes(2))) # optional - benzene, needs sage.graphs | ||
| 1 | ||
| """ | ||
| self._hidden = True | ||
|
|
||
| def unhide(self): | ||
| r""" | ||
| Revert what :meth:`hide` does. | ||
| Revert what :meth:`hide` does. It returns the number of events | ||
| a present feature has been hidden. | ||
|
|
||
| EXAMPLES: | ||
|
|
||
| Polycyclic is a standard GAP package since 4.10 (see :trac:`26856`). The | ||
| following test just fails if it is hidden. Thus, in the second | ||
| invocation no optional tag is needed:: | ||
|
|
||
| sage: from sage.features.gap import GapPackage | ||
| sage: Polycyclic = GapPackage("polycyclic", spkg="gap_packages") | ||
| sage: Polycyclic.hide() | ||
| sage: libgap(AbelianGroup(3, [0,3,4], names="abc")) # needs sage.libs.gap | ||
| Traceback (most recent call last): | ||
| ... | ||
| FeatureNotPresentError: gap_package_polycyclic is not available. | ||
| Feature `gap_package_polycyclic` is hidden. | ||
| Use method `unhide` to make it available again. | ||
|
|
||
| sage: Polycyclic.unhide() | ||
| sage: libgap(AbelianGroup(3, [0,3,4], names="abc")) # needs sage.libs.gap | ||
| Pcp-group with orders [ 0, 3, 4 ] | ||
| sage: from sage.features.sagemath import sage__plot | ||
| sage: sage__plot().hide() | ||
| sage: sage__plot().is_present() | ||
| FeatureTestResult('sage.plot', False) | ||
| sage: sage__plot().unhide() # needs sage.plot | ||
| 1 | ||
| sage: sage__plot().is_present() # needs sage.plot | ||
| FeatureTestResult('sage.plot', True) | ||
| """ | ||
| num_hidings = self._num_hidings.value | ||
| self._num_hidings.value = 0 | ||
| self._hidden = False | ||
| return int(num_hidings) | ||
|
|
||
|
|
||
| class FeatureNotPresentError(RuntimeError): | ||
| r""" | ||
|
|
@@ -801,15 +810,15 @@ class StaticFile(FileFeature): | |
| To install no_such_file...you can try to run...sage -i some_spkg... | ||
| Further installation instructions might be available at http://rand.om. | ||
| """ | ||
| def __init__(self, name, filename, search_path=None, **kwds): | ||
| def __init__(self, name, filename, search_path=None, type='optional', **kwds): | ||
|
||
| r""" | ||
| TESTS:: | ||
|
|
||
| sage: from sage.features import StaticFile | ||
| sage: StaticFile(name="null", filename="null", search_path=("/dev",)) | ||
| Feature('null') | ||
| """ | ||
| Feature.__init__(self, name, **kwds) | ||
| Feature.__init__(self, name, type=type, **kwds) | ||
| self.filename = filename | ||
| if search_path is None: | ||
| self.search_path = [SAGE_SHARE] | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.