comparison mxtool/mx.py @ 11777:f3e5cbd1efae

move pylint to mxtool
author Mick Jordan <mick.jordan@oracle.com>
date Tue, 24 Sep 2013 21:36:46 -0700
parents 8bcd76c3f23b
children 039b133ded75
comparison
equal deleted inserted replaced
11774:f6eb4866d558 11777:f3e5cbd1efae
797 """ 797 """
798 Get the list of all loaded suites. 798 Get the list of all loaded suites.
799 """ 799 """
800 if opt_limit_to_suite and _opts.specific_suites: 800 if opt_limit_to_suite and _opts.specific_suites:
801 result = [] 801 result = []
802 for s in _suites: 802 for s in _suites.values():
803 if s.name in _opts.specific_suites: 803 if s.name in _opts.specific_suites:
804 result.append(s) 804 result.append(s)
805 return result 805 return result
806 else: 806 else:
807 return _suites.values() 807 return _suites.values()
1909 return 1909 return
1910 1910
1911 pnames = [p.name for p in projs] 1911 pnames = [p.name for p in projs]
1912 build(['--projects', ",".join(pnames)]) 1912 build(['--projects', ",".join(pnames)])
1913 archive(pnames) 1913 archive(pnames)
1914
1915 def pylint(args):
1916 """run pylint (if available) over Python source files (found by 'hg locate' or by tree walk with -walk)"""
1917
1918 parser = ArgumentParser(prog='mx pylint')
1919 parser.add_argument('--walk', action='store_true', help='use tree walk find .py files')
1920 args = parser.parse_args(args)
1921
1922 rcfile = join(dirname(__file__), '.pylintrc')
1923 if not exists(rcfile):
1924 log('pylint configuration file does not exist: ' + rcfile)
1925 return
1926
1927 try:
1928 output = subprocess.check_output(['pylint', '--version'], stderr=subprocess.STDOUT)
1929 m = re.match(r'.*pylint (\d+)\.(\d+)\.(\d+).*', output, re.DOTALL)
1930 if not m:
1931 log('could not determine pylint version from ' + output)
1932 return
1933 major, minor, micro = (int(m.group(1)), int(m.group(2)), int(m.group(3)))
1934 if major < 1:
1935 log('require pylint version >= 1 (got {0}.{1}.{2})'.format(major, minor, micro))
1936 return
1937 except BaseException:
1938 log('pylint is not available')
1939 return
1940
1941 def findfiles_by_walk():
1942 result = []
1943 for suite in suites(True):
1944 for root, dirs, files in os.walk(suite.dir):
1945 for f in files:
1946 if f.endswith('.py'):
1947 pyfile = join(root, f)
1948 result.append(pyfile)
1949 if 'bin' in dirs:
1950 dirs.remove('bin')
1951 if 'lib' in dirs:
1952 # avoids downloaded .py files
1953 dirs.remove('lib')
1954 return result
1955
1956 def findfiles_by_hg():
1957 result = []
1958 for suite in suites(True):
1959 versioned = subprocess.check_output(['hg', 'locate', '-f'], stderr=subprocess.STDOUT, cwd=suite.dir).split(os.linesep)
1960 for f in versioned:
1961 if f.endswith('.py') and exists(f):
1962 result.append(f)
1963 return result
1964
1965 # Perhaps we should just look in suite.mxDir directories for .py files?
1966 if args.walk:
1967 pyfiles = findfiles_by_walk()
1968 else:
1969 pyfiles = findfiles_by_hg()
1970
1971 env = os.environ.copy()
1972
1973 pythonpath = dirname(__file__)
1974 for suite in suites(True):
1975 pythonpath = os.pathsep.join([pythonpath, suite.mxDir])
1976
1977 env['PYTHONPATH'] = pythonpath
1978
1979 for pyfile in pyfiles:
1980 log('Running pylint on ' + pyfile + '...')
1981 run(['pylint', '--reports=n', '--rcfile=' + rcfile, pyfile], env=env, nonZeroIsFatal=False)
1914 1982
1915 def archive(args): 1983 def archive(args):
1916 """create jar files for projects and distributions""" 1984 """create jar files for projects and distributions"""
1917 parser = ArgumentParser(prog='mx archive') 1985 parser = ArgumentParser(prog='mx archive')
1918 parser.add_argument('names', nargs=REMAINDER, metavar='[<project>|@<distribution>]...') 1986 parser.add_argument('names', nargs=REMAINDER, metavar='[<project>|@<distribution>]...')
3653 'help': [help_, '[command]'], 3721 'help': [help_, '[command]'],
3654 'ideclean': [ideclean, ''], 3722 'ideclean': [ideclean, ''],
3655 'ideinit': [ideinit, ''], 3723 'ideinit': [ideinit, ''],
3656 'archive': [archive, '[options]'], 3724 'archive': [archive, '[options]'],
3657 'projectgraph': [projectgraph, ''], 3725 'projectgraph': [projectgraph, ''],
3726 'pylint': [pylint, ''],
3658 'javap': [javap, '<class name patterns>'], 3727 'javap': [javap, '<class name patterns>'],
3659 'javadoc': [javadoc, '[options]'], 3728 'javadoc': [javadoc, '[options]'],
3660 'site': [site, '[options]'], 3729 'site': [site, '[options]'],
3661 'netbeansinit': [netbeansinit, ''], 3730 'netbeansinit': [netbeansinit, ''],
3662 'projects': [show_projects, ''], 3731 'projects': [show_projects, ''],