<commit_before>import sublime
import sublime_plugin
import subprocess
import os
import locale
import json
import threading
import functools
import time
import shutil
import glob
import fnmatch
import re
from subprocess import Popen, PIPE

# For Go runtime information, verify go on PATH and ask it about itself.
def load_goenv():
  goenv = {}
  goenvstr = Popen(['go', 'env'], stdout=PIPE).communicate()[0].decode()
  for env in goenvstr.splitlines():
    match = re.match('(.*)=\"(.*)\"', env)
    if match and match.group(1) and match.group(2):
      goenv[match.group(1)] = match.group(2)
  return goenv

# Keep a plugin module cache of the Go runtime information.
GOENV = load_goenv()
print("GoTools: Initialized using Go environment: "+str(GOENV))

class MergedSettings():
  def __init__(self):
    # This is a Sublime settings object.
    self.plugin = sublime.load_settings("GoTools.sublime-settings")
    # This is just a dict.
    self.project = sublime.active_window().active_view().settings().get('GoTools', {})

  def get(self, key, default = None):
    return self.project.get(key, self.plugin.get(key, default))

class GoToolsSettings():
  def __init__(self):
    # Load the Sublime settings files.
    settings = MergedSettings()

    self.goroot = GOENV["GOROOT"]
    self.goarch = GOENV["GOHOSTARCH"]
    self.goos = GOENV["GOHOSTOS"]
    self.go_tools = GOENV["GOTOOLDIR"]

    # The GOROOT bin directory is namespaced with the GOOS and GOARCH.
    self.gorootbin = os.path.join(self.goroot, "bin", self.goos + "_" + self.goarch)

    if not self.goroot or not self.goarch or not self.goos or not self.go_tools:
      raise Exception("GoTools: ERROR: Couldn't detect Go runtime information from `go env`.")

    # For GOPATH, env < plugin < project, and project supports replacement of
    # ${gopath} with whatever preceded in the hierarchy.
    self.gopath = settings.plugin.get('gopath', os.getenv('GOPATH', ''))
    if 'gopath' in settings.project:
      self.gopath = settings.project['gopath'].replace('${gopath}', self.gopath)

    if self.gopath is None or len(self.gopath) == 0:
      raise Exception("GoTools: ERROR: You must set either the `gopath` setting or the GOPATH environment variable.")

    # Plugin feature settings.
    self.debug_enabled = settings.get("debug_enabled")<commit_msg>Nit: don't bother to construct gorootbin if go runtime can't be detected<commit_after>import sublime
import sublime_plugin
import subprocess
import os
import locale
import json
import threading
import functools
import time
import shutil
import glob
import fnmatch
import re
from subprocess import Popen, PIPE

# For Go runtime information, verify go on PATH and ask it about itself.
def load_goenv():
  goenv = {}
  goenvstr = Popen(['go', 'env'], stdout=PIPE).communicate()[0].decode()
  for env in goenvstr.splitlines():
    match = re.match('(.*)=\"(.*)\"', env)
    if match and match.group(1) and match.group(2):
      goenv[match.group(1)] = match.group(2)
  return goenv

# Keep a plugin module cache of the Go runtime information.
GOENV = load_goenv()
print("GoTools: Initialized using Go environment: "+str(GOENV))

class MergedSettings():
  def __init__(self):
    # This is a Sublime settings object.
    self.plugin = sublime.load_settings("GoTools.sublime-settings")
    # This is just a dict.
    self.project = sublime.active_window().active_view().settings().get('GoTools', {})

  def get(self, key, default = None):
    return self.project.get(key, self.plugin.get(key, default))

class GoToolsSettings():
  def __init__(self):
    # Load the Sublime settings files.
    settings = MergedSettings()

    self.goroot = GOENV["GOROOT"]
    self.goarch = GOENV["GOHOSTARCH"]
    self.goos = GOENV["GOHOSTOS"]
    self.go_tools = GOENV["GOTOOLDIR"]

    if not self.goroot or not self.goarch or not self.goos or not self.go_tools:
      raise Exception("GoTools: ERROR: Couldn't detect Go runtime information from `go env`.")

    # The GOROOT bin directory is namespaced with the GOOS and GOARCH.
    self.gorootbin = os.path.join(self.goroot, "bin", self.goos + "_" + self.goarch)

    # For GOPATH, env < plugin < project, and project supports replacement of
    # ${gopath} with whatever preceded in the hierarchy.
    self.gopath = settings.plugin.get('gopath', os.getenv('GOPATH', ''))
    if 'gopath' in settings.project:
      self.gopath = settings.project['gopath'].replace('${gopath}', self.gopath)

    if self.gopath is None or len(self.gopath) == 0:
      raise Exception("GoTools: ERROR: You must set either the `gopath` setting or the GOPATH environment variable.")

    # Plugin feature settings.
    self.debug_enabled = settings.get("debug_enabled")
{'fraction_non_alphanumeric': 0.12098660429513076, 'fraction_numerical': 0.0025515628322347436, 'mean_word_length': 4.014925373134329, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '7163087', 'n_tokens_mistral': 1499, 'n_tokens_neox': 1467, 'n_words': 462}