<commit_before>-- moonraker
-- simple build system. so simple you probably shouldn't use it
-- look at example .moonraker
-- to do anything sufficiently useful you'll need luafilesystem
moonscript = require "moonscript"

tasks = {} -- each task
descs = {} -- descriptions of each task
done  = {} -- tasks already executed
multi = {} -- tasks that can be executed multiple times
requires = {} -- each task's required tasks

default   = nil -- default task
nextdesc  = nil -- description to assign to next defined task
nextmulti = nil -- whether the next defined task is able to execute multiple times
tmpname = os.tmpname! -- temporary file for output

-- functions available to moonraker
environment =
  task: (taskt, block) ->
    name = nil
    for k, v in pairs taskt
      name = k -- task name is the only element in the table
      requires[k] = v unless type(v) == "function"
      tasks[k] = v if type(v) == "function"
      descs[k] = nextdesc -- set our description

    tasks[name] = type(block) == "table" and block.do or block if block
    multi[name] = nextmulti if nextmulti
    nextdesc, nextmulti = nil, nil
  desc: (name) ->
    nextdesc = name
  multiple: ->
    nextmulti = true
  default: (name) ->
    print("Already set default task: #{default}") if default
    default = name
  windows: ->
    package.config\sub(1,1) == "\\"

-- transforms unknown access to os execution
setmetatable environment, __index: (t, k) ->
  return _G[k] if _G[k]
  (x) =>
    returncode = os.execute("#{k} #{x or @} > #{tmpname}")
    result = [l for l in io.lines(tmpname)]
    table.concat(result, "\n"), returncode

doTask = (name) ->
  return if not multi[name] and done[name] -- task already executed
  unless tasks[name]
    return print("No task: " .. name)
  task = tasks[name]
  if requires[name]
    if type(requires[name]) == "table"
      for item in *requires[name]
        doTask(item)
    else
      doTask(requires[name])
  start = os.clock()
  safe, res = pcall(task, environment)
  if safe
    print res if res
    done[name] = true
    elapsed = os.clock() - start
    print(("Completed %s in %0.2fs.")\format(name, elapsed))
  else
    print "Error in task: #{name}\n #{res}"

help = "\tUsage: moonraker file (default: .moonraker) task (optional)"

doFile = (file) ->
  start = os.clock()
  filepath = file or arg[2] and arg[1] or ".moonraker"<commit_msg>printing result was a bad idea.<commit_after>-- moonraker
-- simple build system. so simple you probably shouldn't use it
-- look at example .moonraker
-- to do anything sufficiently useful you'll need luafilesystem
moonscript = require "moonscript"

tasks = {} -- each task
descs = {} -- descriptions of each task
done  = {} -- tasks already executed
multi = {} -- tasks that can be executed multiple times
requires = {} -- each task's required tasks

default   = nil -- default task
nextdesc  = nil -- description to assign to next defined task
nextmulti = nil -- whether the next defined task is able to execute multiple times
tmpname = os.tmpname! -- temporary file for output

-- functions available to moonraker
environment =
  task: (taskt, block) ->
    name = nil
    for k, v in pairs taskt
      name = k -- task name is the only element in the table
      requires[k] = v unless type(v) == "function"
      tasks[k] = v if type(v) == "function"
      descs[k] = nextdesc -- set our description

    tasks[name] = type(block) == "table" and block.do or block if block
    multi[name] = nextmulti if nextmulti
    nextdesc, nextmulti = nil, nil
  desc: (name) ->
    nextdesc = name
  multiple: ->
    nextmulti = true
  default: (name) ->
    print("Already set default task: #{default}") if default
    default = name
  windows: ->
    package.config\sub(1,1) == "\\"

-- transforms unknown access to os execution
setmetatable environment, __index: (t, k) ->
  return _G[k] if _G[k]
  (x) =>
    returncode = os.execute("#{k} #{x or @} > #{tmpname}")
    result = [l for l in io.lines(tmpname)]
    table.concat(result, "\n"), returncode

doTask = (name) ->
  return if not multi[name] and done[name] -- task already executed
  unless tasks[name]
    return print("No task: " .. name)
  task = tasks[name]
  if requires[name]
    if type(requires[name]) == "table"
      for item in *requires[name]
        doTask(item)
    else
      doTask(requires[name])
  start = os.clock()
  safe, res = pcall(task, environment)
  if safe
    done[name] = true
    elapsed = os.clock() - start
    print(("Completed %s in %0.2fs.")\format(name, elapsed))
  else
    print "Error in task: #{name}\n #{res}"

help = "\tUsage: moonraker file (default: .moonraker) task (optional)"

doFile = (file) ->
  start = os.clock()
  filepath = file or arg[2] and arg[1] or ".moonraker"
{'fraction_non_alphanumeric': 0.12986739633761313, 'fraction_numerical': 0.0025257840454641126, 'mean_word_length': 3.023708721422523, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, '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': '6494597', 'n_tokens_mistral': 1497, 'n_tokens_neox': 1476, 'n_words': 546}