<commit_before>from os.path import join, dirname, realpath, isfile
from os import system, remove
from sublime import HIDDEN, PERSISTENT, load_settings, cache_path
import subprocess
import re

class Line:

  # A digit is one-three numbers, with an optional floating point part,
  # and maybe a % sign, and maybe surrounded by whitespace.
  DIGIT = '\s*\d{1,3}(\.\d*)?%?\s*'

  # Three digits is three digits, with commas between.
  THREE_DIGITS = DIGIT + ',' + DIGIT + ',' + DIGIT

  # Four digits is three digits (which we save for later),
  # and then a comma and then the fourth digit.
  FOUR_DIGITS = '(' + THREE_DIGITS + '),' + DIGIT

  HEX_REGEXP = '#((?:[0-9a-fA-F]{3}){1,2})'
  RGB_REGEXP = 'rgb\(' + THREE_DIGITS + '\)'
  RGBA_REGEXP = 'rgba\(' + FOUR_DIGITS + '\)'
  HSL_REGEXP = 'hsl\(' + THREE_DIGITS + '\)'
  HSLA_REGEXP = 'hsla\(' + FOUR_DIGITS + '\)'

  def __init__(self, view, region, file_id):
    self.view     = view
    self.region   = region
    self.file_id  = file_id
    self.settings = load_settings("GutterColor.sublime-settings")
    self.text     = self.view.substr(self.region)

  def has_color(self):
    """Returns True/False depending on whether the line has a color in it"""
    return True if self.color() else False

  def color(self):
    """Returns the color in the line, if any."""
    if self.hex_color():
      return self.hex_color()
    if self.rgb_color():
      return self.rgb_color()
    if self.rgba_color():
      return self.rgba_color()
    if self.hsl_color():
      return self.hsl_color()
    return self.hsla_color()

  def hex_color(self):
    """Returns the color in the line, if any hex is found."""
    matches = re.search(Line.HEX_REGEXP, self.text)
    if matches:
      return matches.group(0)

  def rgb_color(self):
    """Returns the color in the line, if any rgb is found."""
    matches = re.search(Line.RGB_REGEXP, self.text)
    if matches:
      return matches.group(0)

  def rgba_color(self):
    """Returns the color in the line, if any rgba is found."""
    matches = re.search(Line.RGBA_REGEXP, self.text)
    if matches:
      return 'rgb(' + matches.group(1) + ')'

  def hsl_color(self):
    """Returns the color in the line, if any hsl is found."""
    matches = re.search(Line.HSL_REGEXP, self.text)
    if matches:
      return matches.group(0)

  def hsla_color(self):
    """Returns the color in the line, if any rgba is found."""
    matches = re.search(Line.HSLA_REGEXP, self.text)
    if matches:
      return 'hsl(' + matches.group(1) + ')'


  def icon_path(self):
    """Returns the absolute path to the icons"""
    return join(cache_path(), 'GutterColor', '%s.png' % self.color())

  def relative_icon_path(self):
    """The relative location of the color icon"""
    return "Cache/GutterColor/%s.png" % (self.color())

  def add_region(self):
    """Add the icon to the gutter"""
    self.create_icon()
    self.view.add_regions(
      "gutter_color_%s" % self.region.a,
      [self.region],
      "gutter_color",
      self.relative_icon_path(),
      HIDDEN | PERSISTENT
    )

  def erase_region(self):
    """Remove icon from the gutter"""
    self.view.erase_regions("gutter_color_%s" % self.region.a)

  def create_icon(self):
    """Create the color icon using ImageMagick convert"""
    script = "%s -units PixelsPerCentimeter -type TrueColorMatte -channel RGBA " \
      "-size 32x32 -alpha transparent xc:none " \
      "-fill \"%s\" -draw \"circle 15,16 8,10\" png32:\"%s\"" % \
      (self.settings.get("convert_path"), self.color(), self.icon_path())<commit_msg>Add quotes around the convert_path executable<commit_after>from os.path import join, dirname, realpath, isfile
from os import system, remove
from sublime import HIDDEN, PERSISTENT, load_settings, cache_path
import subprocess
import re

class Line:

  # A digit is one-three numbers, with an optional floating point part,
  # and maybe a % sign, and maybe surrounded by whitespace.
  DIGIT = '\s*\d{1,3}(\.\d*)?%?\s*'

  # Three digits is three digits, with commas between.
  THREE_DIGITS = DIGIT + ',' + DIGIT + ',' + DIGIT

  # Four digits is three digits (which we save for later),
  # and then a comma and then the fourth digit.
  FOUR_DIGITS = '(' + THREE_DIGITS + '),' + DIGIT

  HEX_REGEXP = '#((?:[0-9a-fA-F]{3}){1,2})'
  RGB_REGEXP = 'rgb\(' + THREE_DIGITS + '\)'
  RGBA_REGEXP = 'rgba\(' + FOUR_DIGITS + '\)'
  HSL_REGEXP = 'hsl\(' + THREE_DIGITS + '\)'
  HSLA_REGEXP = 'hsla\(' + FOUR_DIGITS + '\)'

  def __init__(self, view, region, file_id):
    self.view     = view
    self.region   = region
    self.file_id  = file_id
    self.settings = load_settings("GutterColor.sublime-settings")
    self.text     = self.view.substr(self.region)

  def has_color(self):
    """Returns True/False depending on whether the line has a color in it"""
    return True if self.color() else False

  def color(self):
    """Returns the color in the line, if any."""
    if self.hex_color():
      return self.hex_color()
    if self.rgb_color():
      return self.rgb_color()
    if self.rgba_color():
      return self.rgba_color()
    if self.hsl_color():
      return self.hsl_color()
    return self.hsla_color()

  def hex_color(self):
    """Returns the color in the line, if any hex is found."""
    matches = re.search(Line.HEX_REGEXP, self.text)
    if matches:
      return matches.group(0)

  def rgb_color(self):
    """Returns the color in the line, if any rgb is found."""
    matches = re.search(Line.RGB_REGEXP, self.text)
    if matches:
      return matches.group(0)

  def rgba_color(self):
    """Returns the color in the line, if any rgba is found."""
    matches = re.search(Line.RGBA_REGEXP, self.text)
    if matches:
      return 'rgb(' + matches.group(1) + ')'

  def hsl_color(self):
    """Returns the color in the line, if any hsl is found."""
    matches = re.search(Line.HSL_REGEXP, self.text)
    if matches:
      return matches.group(0)

  def hsla_color(self):
    """Returns the color in the line, if any rgba is found."""
    matches = re.search(Line.HSLA_REGEXP, self.text)
    if matches:
      return 'hsl(' + matches.group(1) + ')'


  def icon_path(self):
    """Returns the absolute path to the icons"""
    return join(cache_path(), 'GutterColor', '%s.png' % self.color())

  def relative_icon_path(self):
    """The relative location of the color icon"""
    return "Cache/GutterColor/%s.png" % (self.color())

  def add_region(self):
    """Add the icon to the gutter"""
    self.create_icon()
    self.view.add_regions(
      "gutter_color_%s" % self.region.a,
      [self.region],
      "gutter_color",
      self.relative_icon_path(),
      HIDDEN | PERSISTENT
    )

  def erase_region(self):
    """Remove icon from the gutter"""
    self.view.erase_regions("gutter_color_%s" % self.region.a)

  def create_icon(self):
    """Create the color icon using ImageMagick convert"""
    script = "\"%s\" -units PixelsPerCentimeter -type TrueColorMatte -channel RGBA " \
      "-size 32x32 -alpha transparent xc:none " \
      "-fill \"%s\" -draw \"circle 15,16 8,10\" png32:\"%s\"" % \
      (self.settings.get("convert_path"), self.color(), self.icon_path())
{'fraction_non_alphanumeric': 0.14146205357142858, 'fraction_numerical': 0.006975446428571429, 'mean_word_length': 3.153534183082271, 'pattern_counts': {'":': 0, '<': 3, '<?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': '25522', 'n_tokens_mistral': 2548, 'n_tokens_neox': 2416, 'n_words': 692}