quality.rake 2.67 KB
Newer Older
1
def run_pylint(system, report_dir, flags='')
2 3 4 5 6
    apps = Dir["#{system}", "#{system}/djangoapps/*"]
    if system != 'lms'
        apps += Dir["#{system}/lib/*"]
    end

7
    apps = apps.map do |app|
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
        File.basename(app)
    end.select do |app|
        app !=~ /.pyc$/
    end.map do |app|
        if app =~ /.py$/
            app.gsub('.py', '')
        else
            app
        end
    end

    pythonpath_prefix = "PYTHONPATH=#{system}:#{system}/djangoapps:#{system}/lib:common/djangoapps:common/lib"
    sh("#{pythonpath_prefix} pylint #{flags} -f parseable #{apps.join(' ')} | tee #{report_dir}/pylint.report")
end

23 24 25 26 27

[:lms, :cms, :common].each do |system|
    report_dir = report_dir_path(system)
    directory report_dir

28 29 30 31 32 33 34
    namespace :pylint do
        namespace system do
            desc "Run pylint checking for #{system} checking for errors only, and aborting if there are any"
            task :errors do
                run_pylint(system, report_dir, '-E')
            end
        end
35

36
        desc "Run pylint on all #{system} code"
37
        task system => [report_dir, :install_python_prereqs] do
38
            run_pylint(system, report_dir)
39 40
        end
    end
41
    task :pylint => :"pylint:#{system}"
42

43 44 45 46 47 48 49 50
    namespace :pep8 do
        desc "Run pep8 on all #{system} code"
        task system => [report_dir, :install_python_prereqs] do
            sh("pep8 #{system} | tee #{report_dir}/pep8.report")
        end
    end
    task :pep8 => :"pep8:#{system}"
end
51 52 53 54 55

dquality_dir = File.join(REPORT_DIR, "diff_quality")
directory dquality_dir

desc "Build the html diff quality reports, and print the reports to the console."
56 57
task :quality => [dquality_dir, :install_python_prereqs] do

58
    # Generage diff-quality html report for pep8, and print to console
59 60 61 62 63
    # If pep8 reports exist, use those
    # Otherwise, `diff-quality` will call pep8 itself
    pep8_reports = FileList[File.join(REPORT_DIR, '**/pep8.report')].join(' ')
    sh("diff-quality --violations=pep8 --html-report #{dquality_dir}/diff_quality_pep8.html #{pep8_reports}")
    sh("diff-quality --violations=pep8 #{pep8_reports}")
64 65

    # Generage diff-quality html report for pylint, and print to console
66 67 68
    # If pylint reports exist, use those
    # Otherwise, `diff-quality` will call pylint itself
    pylint_reports = FileList[File.join(REPORT_DIR, '**/pylint.report')].join(' ')
69
    pythonpath_prefix = "PYTHONPATH=$PYTHONPATH:lms:lms/djangoapps:lms/lib:cms:cms/djangoapps:cms/lib:common:common/djangoapps:common/lib"
70 71 72
    sh("#{pythonpath_prefix} diff-quality --violations=pylint --html-report #{dquality_dir}/diff_quality_pylint.html #{pylint_reports}")
    sh("#{pythonpath_prefix} diff-quality --violations=pylint #{pylint_reports}")
end