-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #171 from benjeffery/coverage
Add coveralls coverage
- Loading branch information
Showing
4 changed files
with
80 additions
and
12 deletions.
There are no files selected for viewing
This file contains 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 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 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,56 @@ | ||
import functools | ||
import logging | ||
import os | ||
|
||
import numba | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
_DISABLE_NUMBA = os.environ.get("TSBROWSE_DISABLE_NUMBA", "0") | ||
|
||
try: | ||
ENABLE_NUMBA = {"0": True, "1": False}[_DISABLE_NUMBA] | ||
except KeyError as e: # pragma: no cover | ||
raise KeyError( | ||
"Environment variable 'TSBROWSE_DISABLE_NUMBA' must be '0' or '1'" | ||
) from e | ||
|
||
# We will mostly be using disable numba for debugging and running tests for | ||
# coverage, so raise a loud warning in case this is being used accidentally. | ||
|
||
if not ENABLE_NUMBA: | ||
logger.warning( | ||
"numba globally disabled for tsbrowse; performance will be drastically" | ||
" reduced." | ||
) | ||
|
||
|
||
DEFAULT_NUMBA_ARGS = { | ||
"nopython": True, | ||
"cache": True, | ||
} | ||
|
||
|
||
def numba_njit(**numba_kwargs): | ||
def _numba_njit(func): | ||
@functools.wraps(func) | ||
def wrapper(*args, **kwargs): | ||
return func(*args, **kwargs) # pragma: no cover | ||
|
||
if ENABLE_NUMBA: # pragma: no cover | ||
combined_kwargs = {**DEFAULT_NUMBA_ARGS, **numba_kwargs} | ||
return numba.jit(**combined_kwargs)(func) | ||
else: | ||
return func | ||
|
||
return _numba_njit | ||
|
||
|
||
def numba_jitclass(spec): | ||
def _numba_jitclass(cls): | ||
if ENABLE_NUMBA: # pragma: no cover | ||
return numba.experimental.jitclass(spec)(cls) | ||
else: | ||
return cls | ||
|
||
return _numba_jitclass |
This file contains 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