<commit_before>require 'download_strategy'
require 'dependencies'
require 'formula_support'
require 'hardware'
require 'bottles'
require 'extend/fileutils'
require 'patches'
require 'compilers'


class Formula
  include FileUtils

  attr_reader :name, :path, :homepage, :downloader
  attr_reader :stable, :bottle, :devel, :head, :active_spec

  # The build folder, usually in /tmp.
  # Will only be non-nil during the stage method.
  attr_reader :buildpath

  # Homebrew determines the name
  def initialize name='__UNKNOWN__', path=nil
    set_instance_variable :homepage
    set_instance_variable :stable
    set_instance_variable :bottle
    set_instance_variable :devel
    set_instance_variable :head

    @name = name
    validate_variable :name

    # Legacy formulae can set specs via class ivars
    ensure_specs_set if @stable.nil?

    # If a checksum or version was set in the DSL, but no stable URL
    # was defined, make @stable nil and save callers some trouble
    @stable = nil if @stable and @stable.url.nil?

    # Ensure the bottle URL is set. If it does not have a checksum,
    # then a bottle is not available for the current platform.
    if @bottle and not (@bottle.checksum.nil? or @bottle.checksum.empty?)
      @bottle.url ||= bottle_base_url + bottle_filename(self)
    else
      @bottle = nil
    end

    @active_spec = if @head and ARGV.build_head? then @head # --HEAD
      elsif @devel and ARGV.build_devel? then @devel        # --devel
      elsif @bottle and install_bottle?(self) then @bottle  # bottle available
      elsif @stable.nil? and @head then @head               # head-only
      else @stable                                          # default
      end

    @version = @active_spec.version
    validate_variable :version if @version

    raise "No url provided for formula #{name}" if @active_spec.url.nil?

    # If we got an explicit path, use that, else determine from the name
    @path = path.nil? ? self.class.path(name) : Pathname.new(path)
    @downloader = download_strategy.new(name, @active_spec)
  end

  # Derive specs from class ivars
  def ensure_specs_set
    set_instance_variable :url
    set_instance_variable :version
    set_instance_variable :md5
    set_instance_variable :sha1
    set_instance_variable :sha256

    unless @url.nil?
      @stable = SoftwareSpec.new
      @stable.url(@url)
      @stable.version(@version)
      @stable.md5(@md5)
      @stable.sha1(@sha1)
      @stable.sha256(@sha256)
    end

    if @head.kind_of? String
      url = @head
      @head = HeadSoftwareSpec.new
      @head.url(url, self.class.instance_variable_get("@specs"))
    end
  end

  def url;      @active_spec.url;           end
  def version;  @active_spec.version;       end
  def specs;    @active_spec.specs;         end
  def mirrors;  @active_spec.mirrors or []; end

  # if the dir is there, but it's empty we consider it not installed
  def installed?
    return installed_prefix.children.length > 0
  rescue
    return false
  end

  def explicitly_requested?
    # `ARGV.formulae` will throw an exception if it comes up with an empty list.
    # FIXME: `ARGV.formulae` shouldn't be throwing exceptions, see issue #8823
   return false if ARGV.named.empty?
   ARGV.formulae.include? self
  end

  def linked_keg
    HOMEBREW_REPOSITORY/'Library/LinkedKegs'/@name
  end

  def installed_prefix
    devel_prefix = unless @devel.nil?
      HOMEBREW_CELLAR/@name/@devel.version
    end

    head_prefix = unless @head.nil?<commit_msg>Formula: mirrors are always non-nil<commit_after>require 'download_strategy'
require 'dependencies'
require 'formula_support'
require 'hardware'
require 'bottles'
require 'extend/fileutils'
require 'patches'
require 'compilers'


class Formula
  include FileUtils

  attr_reader :name, :path, :homepage, :downloader
  attr_reader :stable, :bottle, :devel, :head, :active_spec

  # The build folder, usually in /tmp.
  # Will only be non-nil during the stage method.
  attr_reader :buildpath

  # Homebrew determines the name
  def initialize name='__UNKNOWN__', path=nil
    set_instance_variable :homepage
    set_instance_variable :stable
    set_instance_variable :bottle
    set_instance_variable :devel
    set_instance_variable :head

    @name = name
    validate_variable :name

    # Legacy formulae can set specs via class ivars
    ensure_specs_set if @stable.nil?

    # If a checksum or version was set in the DSL, but no stable URL
    # was defined, make @stable nil and save callers some trouble
    @stable = nil if @stable and @stable.url.nil?

    # Ensure the bottle URL is set. If it does not have a checksum,
    # then a bottle is not available for the current platform.
    if @bottle and not (@bottle.checksum.nil? or @bottle.checksum.empty?)
      @bottle.url ||= bottle_base_url + bottle_filename(self)
    else
      @bottle = nil
    end

    @active_spec = if @head and ARGV.build_head? then @head # --HEAD
      elsif @devel and ARGV.build_devel? then @devel        # --devel
      elsif @bottle and install_bottle?(self) then @bottle  # bottle available
      elsif @stable.nil? and @head then @head               # head-only
      else @stable                                          # default
      end

    @version = @active_spec.version
    validate_variable :version if @version

    raise "No url provided for formula #{name}" if @active_spec.url.nil?

    # If we got an explicit path, use that, else determine from the name
    @path = path.nil? ? self.class.path(name) : Pathname.new(path)
    @downloader = download_strategy.new(name, @active_spec)
  end

  # Derive specs from class ivars
  def ensure_specs_set
    set_instance_variable :url
    set_instance_variable :version
    set_instance_variable :md5
    set_instance_variable :sha1
    set_instance_variable :sha256

    unless @url.nil?
      @stable = SoftwareSpec.new
      @stable.url(@url)
      @stable.version(@version)
      @stable.md5(@md5)
      @stable.sha1(@sha1)
      @stable.sha256(@sha256)
    end

    if @head.kind_of? String
      url = @head
      @head = HeadSoftwareSpec.new
      @head.url(url, self.class.instance_variable_get("@specs"))
    end
  end

  def url;      @active_spec.url;     end
  def version;  @active_spec.version; end
  def specs;    @active_spec.specs;   end
  def mirrors;  @active_spec.mirrors; end

  # if the dir is there, but it's empty we consider it not installed
  def installed?
    return installed_prefix.children.length > 0
  rescue
    return false
  end

  def explicitly_requested?
    # `ARGV.formulae` will throw an exception if it comes up with an empty list.
    # FIXME: `ARGV.formulae` shouldn't be throwing exceptions, see issue #8823
   return false if ARGV.named.empty?
   ARGV.formulae.include? self
  end

  def linked_keg
    HOMEBREW_REPOSITORY/'Library/LinkedKegs'/@name
  end

  def installed_prefix
    devel_prefix = unless @devel.nil?
      HOMEBREW_CELLAR/@name/@devel.version
    end

    head_prefix = unless @head.nil?
{'fraction_non_alphanumeric': 0.08273894436519258, 'fraction_numerical': 0.005706134094151213, 'mean_word_length': 3.0200688073394497, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7361480', 'n_tokens_mistral': 2284, 'n_tokens_neox': 2168, 'n_words': 680}