diff options
author | Nirbheek Chauhan <nirbheek@centricular.com> | 2018-07-02 00:14:44 +0530 |
---|---|---|
committer | Nirbheek Chauhan <nirbheek.chauhan@gmail.com> | 2018-07-02 07:05:08 +0000 |
commit | 18cd3bd31a305b9bf4c901c03ab056c622dbcbc9 (patch) | |
tree | c59652e5774b949d20c2ec93755b4c1b18c5209d | |
parent | 817dcaa23b92d37339a157ee637ebf361663054b (diff) | |
download | meson-18cd3bd31a305b9bf4c901c03ab056c622dbcbc9.zip meson-18cd3bd31a305b9bf4c901c03ab056c622dbcbc9.tar.gz meson-18cd3bd31a305b9bf4c901c03ab056c622dbcbc9.tar.bz2 |
FeatureNew: Minor code cleanup, no changes
Early return reduces indentation level and makes the code easier to
read.
-rw-r--r-- | mesonbuild/interpreterbase.py | 83 |
1 files changed, 41 insertions, 42 deletions
diff --git a/mesonbuild/interpreterbase.py b/mesonbuild/interpreterbase.py index d2da398..22d85a2 100644 --- a/mesonbuild/interpreterbase.py +++ b/mesonbuild/interpreterbase.py @@ -144,33 +144,32 @@ class FeatureNew: def add_called_feature(self): if self.feature_version not in self.feature_versions: self.feature_versions[self.feature_version] = set() - if self.feature_name in self.feature_versions[self.feature_version]: return False - else: - self.feature_versions[self.feature_version].add(self.feature_name) - return True + self.feature_versions[self.feature_version].add(self.feature_name) + return True def called_features_report(): - if FeatureNew.feature_warnings: - warning_str = 'Invalid minimum meson_version \'{}\' conflicts with:'\ - .format(mesonlib.target_version) - fv = FeatureNew.feature_versions - for version in sorted(fv.keys()): - warning_str += '\n * {}: {}'.format(version, fv[version]) - mlog.warning(warning_str) + if not FeatureNew.feature_warnings: + return + warning_str = 'Invalid minimum meson_version \'{}\' conflicts with:'\ + .format(mesonlib.target_version) + fv = FeatureNew.feature_versions + for version in sorted(fv.keys()): + warning_str += '\n * {}: {}'.format(version, fv[version]) + mlog.warning(warning_str) def use(self): tv = mesonlib.target_version if tv == '': return - if not mesonlib.version_compare_condition_with_min(tv, self.feature_version): - FeatureNew.feature_warnings = True - if self.add_called_feature(): - mlog.warning( - '''Project targetting \'{}\' but tried to use feature introduced in \'{}\': {}''' - .format(tv, self.feature_version, self.feature_name) - ) + if mesonlib.version_compare_condition_with_min(tv, self.feature_version): + return + FeatureNew.feature_warnings = True + if not self.add_called_feature(): + return + mlog.warning('Project targetting \'{}\' but tried to use feature introduced ' + 'in \'{}\': {}'.format(tv, self.feature_version, self.feature_name)) def __call__(self, f): @wraps(f) @@ -192,33 +191,31 @@ class FeatureDeprecated: def add_called_feature(self): if self.feature_version not in self.feature_versions: self.feature_versions[self.feature_version] = set() - if self.feature_name in self.feature_versions[self.feature_version]: return False - else: - self.feature_versions[self.feature_version].add(self.feature_name) - return True + self.feature_versions[self.feature_version].add(self.feature_name) + return True def called_features_report(): - if FeatureDeprecated.feature_warnings: - warning_str = 'Deprecated features used:'\ - .format(mesonlib.target_version) - fv = FeatureDeprecated.feature_versions - for version in sorted(fv.keys()): - warning_str += '\n * {}: {}'.format(version, fv[version]) - mlog.warning(warning_str) + if not FeatureDeprecated.feature_warnings: + return + warning_str = 'Deprecated features used:'.format(mesonlib.target_version) + fv = FeatureDeprecated.feature_versions + for version in sorted(fv.keys()): + warning_str += '\n * {}: {}'.format(version, fv[version]) + mlog.warning(warning_str) def use(self): tv = mesonlib.target_version if tv == '': return - if not mesonlib.version_compare_condition_with_max(tv, self.feature_version): - FeatureDeprecated.feature_warnings = True - if self.add_called_feature(): - mlog.warning( - '''Project targetting \'{}\' but tried to use feature deprecated since \'{}\': {}''' - .format(tv, self.feature_version, self.feature_name) - ) + if mesonlib.version_compare_condition_with_max(tv, self.feature_version): + return + FeatureDeprecated.feature_warnings = True + if not self.add_called_feature(): + return + mlog.warning('Project targetting \'{}\' but tried to use feature deprecated ' + 'since \'{}\': {}'.format(tv, self.feature_version, self.feature_name)) def __call__(self, f): @wraps(f) @@ -236,10 +233,11 @@ class FeatureNewKwargs: def __call__(self, f): @wraps(f) def wrapped(*wrapped_args, **wrapped_kwargs): - s, node_or_state, args, call_kwargs = _get_callee_args(wrapped_args) + s, node_or_state, args, kwargs = _get_callee_args(wrapped_args) for arg in self.kwargs: - if arg in call_kwargs: - FeatureNew(arg + ' arg in ' + self.feature_name, self.feature_version).use() + if arg not in kwargs: + continue + FeatureNew(arg + ' arg in ' + self.feature_name, self.feature_version).use() return f(*wrapped_args, **wrapped_kwargs) return wrapped @@ -252,10 +250,11 @@ class FeatureDeprecatedKwargs: def __call__(self, f): @wraps(f) def wrapped(*wrapped_args, **wrapped_kwargs): - s, node_or_state, args, call_kwargs = _get_callee_args(wrapped_args) + s, node_or_state, args, kwargs = _get_callee_args(wrapped_args) for arg in self.kwargs: - if arg in call_kwargs: - FeatureDeprecated(arg + ' arg in ' + self.feature_name, self.feature_version).use() + if arg not in kwargs: + continue + FeatureDeprecated(arg + ' arg in ' + self.feature_name, self.feature_version).use() return f(*wrapped_args, **wrapped_kwargs) return wrapped |