<commit_before>fs = require 'fs-plus'
$ = require 'jquery'
process = require 'child_process'

module.exports =
class AtomIsort
  statusDialog: null

  isPythonContext: (editor) ->
    if not editor?
      return false
    return editor.getGrammar().scopeName == 'source.python'

  setStatusDialog: (dialog) ->
    @statusDialog = dialog

  removeStatusbarItem: ->
    @statusBarTile?.destroy()
    @statusBarTile = null

  updateStatusbarText: (message, success) ->
    @statusDialog.update message, success

  getFilePath: ->
    return atom.workspace.getActiveTextEditor().getPath()

  checkImports: ->
    @runIsort 'check'

  sortImports: ->
    @runIsort 'sort'

  runIsort: (mode) ->
    if not @isPythonContext atom.workspace.getActiveTextEditor()
      return

    isortPath = fs.normalize atom.config.get 'atom-isort.isortPath'
    if not fs.existsSync isortPath
      @updateStatusbarText 'unable to open ' + isortPath, false
      return

    params = ['-vb']
    if mode == 'sort'
      @updateStatusbarText '⧗', true
    else if mode == 'check'
      params = params.concat ['-c']
    else
      return
    params = params.concat [@getFilePath()]

    proc = process.spawn isortPath, params<commit_msg>Implements force no-skip correctly.<commit_after>fs = require 'fs-plus'
$ = require 'jquery'
process = require 'child_process'

module.exports =
class AtomIsort
  statusDialog: null

  isPythonContext: (editor) ->
    if not editor?
      return false
    return editor.getGrammar().scopeName == 'source.python'

  setStatusDialog: (dialog) ->
    @statusDialog = dialog

  removeStatusbarItem: ->
    @statusBarTile?.destroy()
    @statusBarTile = null

  updateStatusbarText: (message, success) ->
    @statusDialog.update message, success

  getFilePath: ->
    return atom.workspace.getActiveTextEditor().getPath()

  checkImports: ->
    @runIsort 'check'

  sortImports: ->
    @runIsort 'sort'

  runIsort: (mode) ->
    if not @isPythonContext atom.workspace.getActiveTextEditor()
      return

    isortPath = fs.normalize atom.config.get 'atom-isort.isortPath'
    if not fs.existsSync isortPath
      @updateStatusbarText 'unable to open ' + isortPath, false
      return

    params = ['-ns', @getFilePath(), '-vb']
    if mode == 'sort'
      @updateStatusbarText '⧗', true
    else if mode == 'check'
      params = params.concat ['-c']
    else
      return
    params = params.concat [@getFilePath()]

    proc = process.spawn isortPath, params
{'fraction_non_alphanumeric': 0.11717171717171718, 'fraction_numerical': 0.0, 'mean_word_length': 3.1895093062605753, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '1266736', 'n_tokens_mistral': 792, 'n_tokens_neox': 765, 'n_words': 188}