The feature-check Python API
Commonly-used functions
feature_check.obtain_features(program, option=defs.DEFAULT_OPTION, prefix=defs.DEFAULT_PREFIX)
Execute the specified program and get its list of features.
The program is run with the specified query option (default: "--features") and its output is examined for a line starting with the specified prefix (default: "Features: "). The rest of the line is parsed as a whitespace-separated list of either feature names or "name=version" pairs. The function returns a dictionary of the features obtained with their versions (or "1.0" if only a feature name was found in the program's output).
import feature_check
data = feature_check.obtain_features("timelimit")
print(data.get("subsecond", "not supported"))
For programs that need a different command-line option to list features:
import feature_check
print("SSL" in feature_check.obtain_features("curl",
option="--version"))
Source code in python/src/feature_check/obtain.py
feature_check.parse_expr(expr)
Parse a simple "feature-name op version" expression.
If the expression is valid, return an Expr
object corresponding
to the specified check. Use this object's evaluate()
method and
pass a features dictionary as returned by the obtain_features()
function to get a Result
object; for simple expressions it will be
a ResultBool
object with a boolean value
member.
from feature_check import expr as fexpr
from feature_check import obtain as fobtain
data = fobtain.obtain_features("timelimit");
expr = fexpr.parse_simple("subsecond > 0")
print(expr.evaluate(data).value)
Source code in python/src/feature_check/parser.py
feature_check.parser.parse_features_line(features_line)
Parse the features list, default to version "1.0".
Source code in python/src/feature_check/parser.py
feature_check.parse_version(value)
Parse a version string into a Version
object.
Source code in python/src/feature_check/parser.py
feature_check.version.version_compare(ver_a, ver_b)
Compare two version strings.
Returns -1, 0, or 1 for the first version being less than, equal to, or greater than the second one.
Source code in python/src/feature_check/version.py
Commonly-used functions
feature_check.obtain.obtain_features(program, option=defs.DEFAULT_OPTION, prefix=defs.DEFAULT_PREFIX)
Execute the specified program and get its list of features.
The program is run with the specified query option (default: "--features") and its output is examined for a line starting with the specified prefix (default: "Features: "). The rest of the line is parsed as a whitespace-separated list of either feature names or "name=version" pairs. The function returns a dictionary of the features obtained with their versions (or "1.0" if only a feature name was found in the program's output).
import feature_check
data = feature_check.obtain_features("timelimit")
print(data.get("subsecond", "not supported"))
For programs that need a different command-line option to list features:
import feature_check
print("SSL" in feature_check.obtain_features("curl",
option="--version"))
Source code in python/src/feature_check/obtain.py
Defaults
feature_check.defs.DEFAULT_OPTION = '--features'
module-attribute
The default command-line option to pass to a program to query for supported features.
feature_check.defs.DEFAULT_PREFIX = 'Features: '
module-attribute
The default prefix of the program's features output line.
feature_check.defs.DEFAULT_OUTPUT_FMT = 'tsv'
module-attribute
The default output format for the feature-check
command-line tool.
Version strings
feature_check.version.Version
feature_check.version.VersionComponent
Bases: NamedTuple
Represent a single version component: a numerical part and a freeform string one.
Source code in python/src/feature_check/version.py
__eq__(other)
__ge__(other)
__gt__(other)
__hash__()
__le__(other)
__lt__(other)
__ne__(other)
__str__()
cmp(other)
Compare two components, return None if they are equal.
Source code in python/src/feature_check/version.py
Expressions
feature_check.defs.Expr
dataclass
Bases: ABC
The (pretty much abstract) base class for an expression.
Source code in python/src/feature_check/defs.py
evaluate(data)
abstractmethod
Evaluate the expression and return a Result object.
Overridden in actual expression classes.
Source code in python/src/feature_check/defs.py
feature_check.expr.ExprFeature
dataclass
Bases: Expr
An expression that returns a program feature name as a string.
Source code in python/src/feature_check/expr.py
evaluate(data)
Look up the feature, return the result in a ResultVersion object.
feature_check.expr.ExprVersion
dataclass
Bases: Expr
An expression that returns a version number for a feature.
Source code in python/src/feature_check/expr.py
feature_check.expr.BoolOp
dataclass
feature_check.expr.ExprOp
dataclass
Bases: Expr
A two-argument operation expression.
Source code in python/src/feature_check/expr.py
__post_init__()
evaluate(data)
Evaluate the expression over the specified data.
Source code in python/src/feature_check/expr.py
feature_check.defs.Result
dataclass
feature_check.expr.ResultBool
dataclass
Bases: Result
A boolean result of an expression; the "value" member is boolean.
Source code in python/src/feature_check/expr.py
feature_check.expr.ResultVersion
dataclass
Bases: Result
A version number as a result of an expression.
The "value" member is the version number string.
Source code in python/src/feature_check/expr.py
Errors
feature_check.defs.FCError
Bases: Exception
A base class for errors in handling a feature-check request.
Source code in python/src/feature_check/defs.py
code: int
property
Return the numeric error code.
message: str
property
Return a human-readable error message.
feature_check.obtain.ObtainError
feature_check.obtain.ObtainExecError
Bases: ObtainError
An error that occurred while executing the queried program.
Source code in python/src/feature_check/obtain.py
feature_check.obtain.ObtainNoFeaturesError
Bases: ObtainError
An error that occurred while looking for the features line.
Source code in python/src/feature_check/obtain.py
__init__(program, option, prefix)
feature_check.obtain.ObtainNoFeaturesSupportError
Bases: ObtainExecError
The program does not seem to support the "--features" option.
Source code in python/src/feature_check/obtain.py
__init__(program, option)
feature_check.parser.ParseError
Main program operating modes
feature_check.defs.Mode
dataclass
feature_check.defs.ModeList
dataclass
feature_check.defs.ModeSimple
dataclass
feature_check.defs.ModeSingle
dataclass
Miscellaneous
feature_check.defs.VERSION = '2.2.0'
module-attribute
The feature-check library version, SemVer-style.