<commit_before>path = require 'path'
process = require 'child_process'
byline = require 'byline'

Pep8ErrorsView = require './pep8-view'

module.exports =
    supportedExtensions: [".py"]
    errorView: null

    activate: (state) ->
        atom.workspaceView.command 'pep8:lint', =>
            @lint()

    lint: ->
        editor = atom.workspace.getActiveEditor()
        return unless editor?

        filePath = editor.getPath()
        if path.extname(filePath) not in @supportedExtensions
            console.log "PEP8 Linter: Ignore file " + filePath
            return

        @lintFile filePath, (errors) ->
            if errors
                @errorView = new Pep8ErrorsView()
                @errorView.setItems(errors)
                @errorView.show()

    lintFile: (path, callback) ->

        console.log "PEP8 Linter: Linting file " + path

        line_expr = /:(\d+):(\d+): (E\d{3}) (.*)/
        errors = []

        proc = process.spawn("/usr/local/bin/pep8", [path])

        # Watch for pep8 errors
        output = byline(proc.stdout)
        output.on 'data', (line) -><commit_msg>Don't use a hardcoded pep8 path, use a configurable option<commit_after>path = require 'path'
process = require 'child_process'
byline = require 'byline'

Pep8ErrorsView = require './pep8-view'

module.exports =
    supportedExtensions: [".py"]
    errorView: null
    pep8Path: null

    activate: (state) ->
        unless atom.config.get('pep8.PEP8Path')
            atom.config.set('pep8.PEP8Path', "/usr/local/bin/pep8")

        @pep8Path = atom.config.get('pep8.PEP8Path')

        atom.workspaceView.command 'pep8:lint', =>
            @lint()

    lint: ->
        editor = atom.workspace.getActiveEditor()
        return unless editor?

        filePath = editor.getPath()
        if path.extname(filePath) not in @supportedExtensions
            console.log "PEP8 Linter: Ignore file " + filePath
            return

        @lintFile filePath, (errors) ->
            if errors
                @errorView = new Pep8ErrorsView()
                @errorView.setItems(errors)
                @errorView.show()

    lintFile: (path, callback) ->

        console.log "PEP8 Linter: Linting file " + path

        line_expr = /:(\d+):(\d+): (E\d{3}) (.*)/
        errors = []

        return unless @pep8Path

        proc = process.spawn(@pep8Path, [path])

        # Watch for pep8 errors
        output = byline(proc.stdout)
        output.on 'data', (line) ->
{'fraction_non_alphanumeric': 0.12943548387096773, 'fraction_numerical': 0.011693548387096775, 'mean_word_length': 2.0858208955223883, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1495666', 'n_tokens_mistral': 800, 'n_tokens_neox': 762, 'n_words': 174}