def generate_filelist(basepath=None, recurse=True, ignore=False): """ Recursively get a list of files to test/lint """ if basepath: walkpath = os.path.join(get_path_to_wmcore_root(), 'src/python', basepath) else: walkpath = os.path.join(get_path_to_wmcore_root(), 'src/python') files = [] if walkpath.endswith('.py'): if ignore and walkpath.endswith(ignore): files.append(walkpath) else: for dirpath, dummyDirnames, filenames in os.walk(walkpath): # skipping CVS directories and their contents pathelements = dirpath.split('/') if 'CVS' not in pathelements: # to build up a list of file names which contain tests for filename in filenames: if filename.endswith('.py'): filepath = '/'.join([dirpath, filename]) files.append(filepath) if len(files) == 0 and recurse: files = generate_filelist(basepath + '.py', not recurse) return files
def run(self): if not os.getenv('COUCHURL', False): # Use the default localhost URL if none is configured. print('export COUCHURL=http://localhost:5984') here = get_path_to_wmcore_root() tests = here + '/test/python' source = here + '/src/python' # Stuff we want on the path exepth = [source + '/WMCore/WebTools', here + '/bin'] pypath = os.getenv('PYTHONPATH', '').strip(':').split(':') for pth in [tests, source]: if pth not in pypath: pypath.append(pth) # We might want to add other executables to PATH expath = os.getenv('PATH', '').split(':') for pth in exepth: if pth not in expath: expath.append(pth) print('export PYTHONPATH=%s' % ':'.join(pypath)) print('export PATH=%s' % ':'.join(expath)) # We want the WMCORE root set, too print('export WMCORE_ROOT=%s' % get_path_to_wmcore_root()) print('export WMCOREBASE=$WMCORE_ROOT') print('export WTBASE=$WMCORE_ROOT/src')
def generate_filelist(basepath=None, recurse=True, ignore=False): """ Recursively get a list of files to test/lint """ if basepath: walkpath = os.path.join(get_path_to_wmcore_root(), "src/python", basepath) else: walkpath = os.path.join(get_path_to_wmcore_root(), "src/python") files = [] if walkpath.endswith(".py"): if ignore and walkpath.endswith(ignore): files.append(walkpath) else: for dirpath, dirnames, filenames in os.walk(walkpath): # skipping CVS directories and their contents pathelements = dirpath.split("/") result = [] if not "CVS" in pathelements: # to build up a list of file names which contain tests for file in filenames: if file.endswith(".py"): filepath = "/".join([dirpath, file]) files.append(filepath) if len(files) == 0 and recurse: files = generate_filelist(basepath + ".py", not recurse) return files
def run(self): if not os.getenv('DATABASE', False): # Use an in memory sqlite one if none is configured. print('export DATABASE=sqlite://') if not os.getenv('COUCHURL', False): # Use the default localhost URL if none is configured. print('export COUCHURL=http://localhost:5984') here = get_path_to_wmcore_root() tests = here + '/test/python' source = here + '/src/python' # Stuff we want on the path exepth = [source + '/WMCore/WebTools', here + '/bin'] pypath = os.getenv('PYTHONPATH', '').strip(':').split(':') for pth in [tests, source]: if pth not in pypath: pypath.append(pth) # We might want to add other executables to PATH expath = os.getenv('PATH', '').split(':') for pth in exepth: if pth not in expath: expath.append(pth) print('export PYTHONPATH=%s' % ':'.join(pypath)) print('export PATH=%s' % ':'.join(expath)) # We want the WMCORE root set, too print('export WMCORE_ROOT=%s' % get_path_to_wmcore_root()) print('export WMCOREBASE=$WMCORE_ROOT') print('export WTBASE=$WMCORE_ROOT/src')
def run(self): if not os.getenv("DATABASE", False): # Use an in memory sqlite one if none is configured. print "export DATABASE=sqlite://" if not os.getenv("COUCHURL", False): # Use the default localhost URL if none is configured. print "export COUCHURL=http://localhost:5984" here = get_path_to_wmcore_root() tests = here + "/test/python" source = here + "/src/python" # Stuff we want on the path exepth = [source + "/WMCore/WebTools", here + "/bin"] pypath = os.getenv("PYTHONPATH", "").strip(":").split(":") for pth in [tests, source]: if pth not in pypath: pypath.append(pth) # We might want to add other executables to PATH expath = os.getenv("PATH", "").split(":") for pth in exepth: if pth not in expath: expath.append(pth) print "export PYTHONPATH=%s" % ":".join(pypath) print "export PATH=%s" % ":".join(expath) # We want the WMCORE root set, too print "export WMCORE_ROOT=%s" % get_path_to_wmcore_root() print "export WMCOREBASE=$WMCORE_ROOT" print "export WTBASE=$WMCORE_ROOT/src"
def lint_files(files, reports=False): """ lint a (list of) file(s) and return the results as a dictionary containing filename : result_dict """ rcfile = os.path.join(get_path_to_wmcore_root(), 'standards/.pylintrc') arguements = ['--rcfile=%s' % rcfile, '--ignore=DefaultConfig.py'] if not reports: arguements.append('-rn') arguements.extend(files) lntr = LinterRun(arguements) results = {} for file in files: lntr.linter.check(file) results[file] = { 'stats': lntr.linter.stats, 'score': lint_score(lntr.linter.stats, lntr.linter.config.evaluation) } if reports: print('----------------------------------') print('Your code has been rated at %.2f/10' % \ lint_score(lntr.linter.stats, lntr.linter.config.evaluation)) return results, lntr.linter.config.evaluation
def lint_files(files, reports=False): """ lint a (list of) file(s) and return the results as a dictionary containing filename : result_dict """ rcfile=os.path.join(get_path_to_wmcore_root(),'standards/.pylintrc') arguements = ['--rcfile=%s' % rcfile, '--ignore=DefaultConfig.py'] if not reports: arguements.append('-rn') arguements.extend(files) lntr = LinterRun(arguements) results = {} for file in files: lntr.linter.check(file) results[file] = {'stats': lntr.linter.stats, 'score': lint_score(lntr.linter.stats, lntr.linter.config.evaluation) } if reports: print '----------------------------------' print 'Your code has been rated at %.2f/10' % \ lint_score(lntr.linter.stats, lntr.linter.config.evaluation) return results, lntr.linter.config.evaluation
def lint_files(files, reports=False): """ lint a (list of) file(s) and return the results as a dictionary containing filename : result_dict """ rcfile = os.path.join(get_path_to_wmcore_root(), "standards/.pylintrc") arguements = ["--rcfile=%s" % rcfile, "--ignore=DefaultConfig.py"] if not reports: arguements.append("-rn") arguements.extend(files) lntr = LinterRun(arguements) results = {} for file in files: lntr.linter.check(file) results[file] = { "stats": lntr.linter.stats, "score": lint_score(lntr.linter.stats, lntr.linter.config.evaluation), } if reports: print "----------------------------------" print "Your code has been rated at %.2f/10" % lint_score(lntr.linter.stats, lntr.linter.config.evaluation) return results, lntr.linter.config.evaluation
def run(self): """ run all the tests needed to generate the report and make an html table """ files = generate_filelist() error = 0 warning = 0 refactor = 0 convention = 0 statement = 0 srcpypath = '/'.join([get_path_to_wmcore_root(), 'src/python/']) sys.path.append(srcpypath) cfg = ConfigParser() cfg.read('standards/.pylintrc') # Supress stdout/stderr sys.stderr = open('/dev/null', 'w') sys.stdout = open('/dev/null', 'w') # wrap it in an exception handler, otherwise we can't see why it fails try: # lint the code for stats in lint_files(files): error += stats['error'] warning += stats['warning'] refactor += stats['refactor'] convention += stats['convention'] statement += stats['statement'] except Exception,e: # and restore the stdout/stderr sys.stderr = sys.__stderr__ sys.stdout = sys.__stderr__ raise e
def run(self): """ run all the tests needed to generate the report and make an html table """ files = generate_filelist() error = 0 warning = 0 refactor = 0 convention = 0 statement = 0 srcpypath = '/'.join([get_path_to_wmcore_root(), 'src/python/']) sys.path.append(srcpypath) cfg = ConfigParser() cfg.read('standards/.pylintrc') # Supress stdout/stderr sys.stderr = open('/dev/null', 'w') sys.stdout = open('/dev/null', 'w') # wrap it in an exception handler, otherwise we can't see why it fails try: # lint the code for stats in lint_files(files): error += stats['error'] warning += stats['warning'] refactor += stats['refactor'] convention += stats['convention'] statement += stats['statement'] except Exception, e: # and restore the stdout/stderr sys.stderr = sys.__stderr__ sys.stdout = sys.__stderr__ raise e
def run(self): """ run all the tests needed to generate the report and make an html table """ files = generate_filelist() error = 0 warning = 0 refactor = 0 convention = 0 statement = 0 srcpypath = "/".join([get_path_to_wmcore_root(), "src/python/"]) sys.path.append(srcpypath) cfg = ConfigParser() cfg.read("standards/.pylintrc") # Supress stdout/stderr sys.stderr = open("/dev/null", "w") sys.stdout = open("/dev/null", "w") # wrap it in an exception handler, otherwise we can't see why it fails try: # lint the code for stats in lint_files(files): error += stats["error"] warning += stats["warning"] refactor += stats["refactor"] convention += stats["convention"] statement += stats["statement"] except Exception, e: # and restore the stdout/stderr sys.stderr = sys.__stderr__ sys.stdout = sys.__stderr__ raise e
from __future__ import print_function, division import os import sys import imp from setuptools import setup from setup_build import list_packages, list_static_files, get_path_to_wmcore_root # Obnoxiously, there's a dependency cycle when building packages. We'd like # to simply get the current WMCore version by using # from WMCore import __version__ # But PYTHONPATH isn't set until after the package is built, so we can't # depend on the python module resolution behavior to load the version. # Instead, we use the imp module to load the source file directly by # filename. wmcore_root = get_path_to_wmcore_root() wmcore_package = imp.load_source( 'temp_module', os.path.join(wmcore_root, 'src', 'python', 'WMCore', '__init__.py')) wmcore_version = wmcore_package.__version__ # Requirements file for pip dependencies requirements = "requirements.txt" def parse_requirements(requirements_file): """ Create a list for the 'install_requires' component of the setup function by parsing a requirements file """
def initialize_options(self): self._dir = get_path_to_wmcore_root() self.package = None self.report = False
def run(self): """ run all the tests needed to generate the report and make an html table """ files = generate_filelist() error = 0 warning = 0 refactor = 0 convention = 0 statement = 0 srcpypath = '/'.join([get_path_to_wmcore_root(), 'src/python/']) sys.path.append(srcpypath) cfg = ConfigParser() cfg.read('standards/.pylintrc') # Supress stdout/stderr sys.stderr = open('/dev/null', 'w') sys.stdout = open('/dev/null', 'w') # wrap it in an exception handler, otherwise we can't see why it fails try: # lint the code for stats in lint_files(files): error += stats['error'] warning += stats['warning'] refactor += stats['refactor'] convention += stats['convention'] statement += stats['statement'] except Exception as e: # and restore the stdout/stderr sys.stderr = sys.__stderr__ sys.stdout = sys.__stderr__ raise e # and restore the stdout/stderr sys.stderr = sys.__stderr__ sys.stdout = sys.__stderr__ stats = { 'error': error, 'warning': warning, 'refactor': refactor, 'convention': convention, 'statement': statement } lint_score = eval(cfg.get('MASTER', 'evaluation'), {}, stats) coverage = 0 # TODO: calculate this testless_classes = [] # TODO: generate this print("<table>") print("<tr>") print("<td colspan=2><h1>WMCore test report</h1></td>") print("</tr>") print("<tr>") print("<td>Average lint score</td>") print("<td>%.2f</td>" % lint_score) print("</tr>") print("<tr>") print("<td>% code coverage</td>") print("<td>%s</td>" % coverage) print("</tr>") print("<tr>") print("<td>Classes missing tests</td>") print("<td>") if len(testless_classes) == 0: print("None") else: print("<ul>") for c in testless_classes: print("<li>%c</li>" % c) print("</ul>") print("</td>") print("</tr>") print("</table>")
def run(self): """ run all the tests needed to generate the report and make an html table """ files = generate_filelist() error = 0 warning = 0 refactor = 0 convention = 0 statement = 0 srcpypath = '/'.join([get_path_to_wmcore_root(), 'src/python/']) sys.path.append(srcpypath) cfg = ConfigParser() cfg.read('standards/.pylintrc') # Supress stdout/stderr sys.stderr = open('/dev/null', 'w') sys.stdout = open('/dev/null', 'w') # wrap it in an exception handler, otherwise we can't see why it fails try: # lint the code for stats in lint_files(files): error += stats['error'] warning += stats['warning'] refactor += stats['refactor'] convention += stats['convention'] statement += stats['statement'] except Exception as e: # and restore the stdout/stderr sys.stderr = sys.__stderr__ sys.stdout = sys.__stderr__ raise e # and restore the stdout/stderr sys.stderr = sys.__stderr__ sys.stdout = sys.__stderr__ stats = {'error': error, 'warning': warning, 'refactor': refactor, 'convention': convention, 'statement': statement} lint_score = eval(cfg.get('MASTER', 'evaluation'), {}, stats) coverage = 0 # TODO: calculate this testless_classes = [] # TODO: generate this print("<table>") print("<tr>") print("<td colspan=2><h1>WMCore test report</h1></td>") print("</tr>") print("<tr>") print("<td>Average lint score</td>") print("<td>%.2f</td>" % lint_score) print("</tr>") print("<tr>") print("<td>% code coverage</td>") print("<td>%s</td>" % coverage) print("</tr>") print("<tr>") print("<td>Classes missing tests</td>") print("<td>") if len(testless_classes) == 0: print("None") else: print("<ul>") for c in testless_classes: print("<li>%c</li>" % c) print("</ul>") print("</td>") print("</tr>") print("</table>")
'src/python/WMCore', 'src/python/WMComponent', 'src/python/WMQuality', 'src/python/PSetTweaks']) # Divine out the version of WMCore from WMCore.__init__, which is bumped by # "bin/buildrelease.sh" # Obnoxiously, there's a dependency cycle when building packages. We'd like # to simply get the current WMCore version by using # from WMCore import __version__ # But PYTHONPATH isn't set until after the package is built, so we can't # depend on the python module resolution behavior to load the version. # Instead, we use the imp module to load the source file directly by # filename. wmcore_root = get_path_to_wmcore_root() wmcore_package = imp.load_source('temp_module', os.path.join(wmcore_root, 'src', 'python', 'WMCore', '__init__.py')) wmcore_version = wmcore_package.__version__ setup(name='wmcore', version=wmcore_version, maintainer='CMS DMWM Group', maintainer_email='*****@*****.**', cmdclass={'deep_clean': CleanCommand, 'coverage': CoverageCommand, 'test': TestCommand, 'env': EnvCommand,