def main(): """ Entry point when used via command line. Features are given using the environment variable ``PRODUCT_EQUATION``. If it is not set, ``PRODUCT_EQUATION_FILENAME`` is tried: if it points to an existing equation file that selection is used. (if ``APE_PREPEND_FEATURES`` is given, those features are prepended) If the list of features is empty, ``ape.EnvironmentIncomplete`` is raised. """ # check APE_PREPEND_FEATURES features = os.environ.get('APE_PREPEND_FEATURES', '').split() # features can be specified inline in PRODUCT_EQUATION inline_features = os.environ.get('PRODUCT_EQUATION', '').split() if inline_features: # append inline features features += inline_features else: # fallback: features are specified in equation file feature_file = os.environ.get('PRODUCT_EQUATION_FILENAME', '') if feature_file: # append features from equation file features += get_features_from_equation_file(feature_file) else: if not features: raise EnvironmentIncomplete( 'Error running ape:\n' 'Either the PRODUCT_EQUATION or ' 'PRODUCT_EQUATION_FILENAME environment ' 'variable needs to be set!') # run ape with features selected run(sys.argv, features=features)
def run_product_tests(): """ runs tests for the features that are activated in the product equation """ features = featuremonkey.get_features_from_equation_file(os.environ['PRODUCT_EQUATION_FILENAME']) args = ['test'] + features tasks.manage(*args)
def main(): ''' entry point when used via command line features are given using the environment variable PRODUCT_EQUATION. If it is not set, PRODUCT_EQUATION_FILENAME is tried: if it points to an existing equation file that selection is used. If that fails ``ape.EnvironmentIncomplete`` is raised. ''' #check APE_PREPEND_FEATURES features = os.environ.get('APE_PREPEND_FEATURES', '').split() #features can be specified inline in PRODUCT_EQUATION inline_features = os.environ.get('PRODUCT_EQUATION', '').split() if inline_features: #append inline features features += inline_features else: #fallback: features are specified in equation file feature_file = os.environ.get('PRODUCT_EQUATION_FILENAME', '') if feature_file: #append features from equation file features += get_features_from_equation_file(feature_file) else: if not features: print ( 'Error running ape:\n' 'Either the PRODUCT_EQUATION or ' 'PRODUCT_EQUATION_FILENAME environment ' 'variable needs to be set!' ) sys.exit(1) #run ape with features selected run(sys.argv, features=features)
def run_product_tests(*args): """ Runs tests for the features that are activated in the product equation. Example: $ ape runfeaturetests -r -v=2 """ features = featuremonkey.get_features_from_equation_file(os.environ['PRODUCT_EQUATION_FILENAME']) base_args = ['test'] + features args = base_args + list(args) tasks.manage(*args)
def run_product_tests(*args): """ Runs tests for the features that are activated in the product equation. Example: $ ape runfeaturetests -r -v=2 """ features = featuremonkey.get_features_from_equation_file( os.environ['PRODUCT_EQUATION_FILENAME']) base_args = ['test'] + features args = base_args + list(args) tasks.manage(*args)
def get_features_from_equation(container_dir, product_name): """ Takes the container dir and the product name and returns the list of features. :param container_dir: path of the container dir :param product_name: name of the product :return: list of strings, each representing one feature """ import featuremonkey file_path = os.path.join(container_dir, 'products', product_name, 'product.equation') return featuremonkey.get_features_from_equation_file(file_path)
def explain_features(): '''print the location of each feature and its version if the feature is located inside a git repository, this will also print the git-rev and modified files ''' from ape import tasks import featuremonkey import os featurenames = featuremonkey.get_features_from_equation_file(os.environ['PRODUCT_EQUATION_FILENAME']) for featurename in featurenames: tasks.explain_feature(featurename)
def explain_feature(featurename): '''print the location of single feature and its version if the feature is located inside a git repository, this will also print the git-rev and modified files ''' import os import featuremonkey import importlib import subprocess def guess_version(feature_module): if hasattr(feature_module, '__version__'): return feature_module.__version__ if hasattr(feature_module, 'get_version'): return feature_module.get_version() return 'unable to determine version: please add __version__ or get_version() to this feature module!' def git_rev(module): stdout, stderr = subprocess.Popen( ["git", "rev-parse", "HEAD"], cwd=os.path.dirname(module.__file__), stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate() if 'Not a git repo' in stderr: return '-' else: return stdout.strip() def git_changes(module): stdout = subprocess.Popen(["git", "diff", "--name-only"], cwd=os.path.dirname(module.__file__), stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0] return stdout.strip() or '-' if featurename in featuremonkey.get_features_from_equation_file( os.environ['PRODUCT_EQUATION_FILENAME']): print print featurename print '-' * 60 print is_subfeature = '.features.' in featurename try: feature_module = importlib.import_module(featurename) except ImportError: print 'Error: unable to import feature "%s"' % featurename print 'Location: %s' % os.path.dirname(feature_module.__file__) print if is_subfeature: print 'Version: see parent feature' print else: print 'Version: %s' % str(guess_version(feature_module)) print print 'git: %s' % git_rev(feature_module) print print 'git changed: %s' % '\n\t\t'.join( git_changes(feature_module).split('\n')) else: print 'No feature named ' + featurename
def explain_feature(featurename): '''print the location of single feature and its version if the feature is located inside a git repository, this will also print the git-rev and modified files ''' import os import featuremonkey import importlib import subprocess def guess_version(feature_module): if hasattr(feature_module, '__version__'): return feature_module.__version__ if hasattr(feature_module, 'get_version'): return feature_module.get_version() return 'unable to determine version: please add __version__ or get_version() to this feature module!' def git_rev(module): stdout, stderr = subprocess.Popen( ["git", "rev-parse", "HEAD"], cwd=os.path.dirname(module.__file__), stdout=subprocess.PIPE, stderr=subprocess.PIPE ).communicate() if 'Not a git repo' in stderr: return '-' else: return stdout.strip() def git_changes(module): stdout = subprocess.Popen( ["git", "diff", "--name-only"], cwd=os.path.dirname(module.__file__), stdout=subprocess.PIPE, stderr=subprocess.PIPE ).communicate()[0] return stdout.strip() or '-' if featurename in featuremonkey.get_features_from_equation_file(os.environ['PRODUCT_EQUATION_FILENAME']): print print featurename print '-' * 60 print is_subfeature = '.features.' in featurename try: feature_module = importlib.import_module(featurename) except ImportError: print 'Error: unable to import feature "%s"' % featurename print 'Location: %s' % os.path.dirname(feature_module.__file__) print if is_subfeature: print 'Version: see parent feature' print else: print 'Version: %s' % str(guess_version(feature_module)) print print 'git: %s' % git_rev(feature_module) print print 'git changed: %s' % '\n\t\t'.join(git_changes(feature_module).split('\n')) else: print 'No feature named ' + featurename