<commit_before>require "keg"
require "language/python"
require "formula"
require "version"
require "development_tools"
require "utils/shell"

module Homebrew
  module Diagnostic
    def self.missing_deps(ff, hide = nil)
      missing = {}
      ff.each do |f|
        missing_dependencies = f.missing_dependencies(hide: hide)

        unless missing_dependencies.empty?
          yield f.full_name, missing_dependencies if block_given?
          missing[f.full_name] = missing_dependencies
        end
      end
      missing
    end

    class Volumes
      def initialize
        @volumes = get_mounts
      end

      def which(path)
        vols = get_mounts path

        # no volume found
        return -1 if vols.empty?

        vol_index = @volumes.index(vols[0])
        # volume not found in volume list
        return -1 if vol_index.nil?
        vol_index
      end

      def get_mounts(path = nil)
        vols = []
        # get the volume of path, if path is nil returns all volumes

        args = %w[/bin/df -P]
        args << path if path

        Utils.popen_read(*args) do |io|
          io.each_line do |line|
            case line.chomp
              # regex matches: /dev/disk0s2   489562928 440803616  48247312    91%    /
            when /^.+\s+[0-9]+\s+[0-9]+\s+[0-9]+\s+[0-9]{1,3}%\s+(.+)/
              vols << Regexp.last_match(1)
            end
          end
        end
        vols
      end
    end

    class Checks
      ############# HELPERS
      # Finds files in HOMEBREW_PREFIX *and* /usr/local.
      # Specify paths relative to a prefix eg. "include/foo.h".
      # Sets @found for your convenience.
      def find_relative_paths(*relative_paths)
        @found = [HOMEBREW_PREFIX, "/usr/local"].uniq.inject([]) do |found, prefix|
          found + relative_paths.map { |f| File.join(prefix, f) }.select { |f| File.exist? f }
        end
      end

      def inject_file_list(list, string)
        list.inject(string) { |acc, elem| acc << "  #{elem}\n" }
      end
      ############# END HELPERS

      def development_tools_checks
        %w[
          check_for_installed_developer_tools
        ].freeze
      end

      def fatal_development_tools_checks
        %w[
        ].freeze
      end

      def build_error_checks
        (development_tools_checks + %w[
        ]).freeze
      end

      def check_for_installed_developer_tools
        return if DevelopmentTools.installed?

        <<-EOS.undent
          No developer tools installed.
          #{DevelopmentTools.installation_instructions}
        EOS
      end

      def check_build_from_source
        return unless ENV("HOMEBREW_BUILD_FROM_SOURCE")

        <<-EOS.undent
          You have HOMEBREW_BUILD_FROM_SOURCE set. This environment variable is
          intended for use by Homebrew developers. If you are encountering errors,
          please try unsetting this. Please do not file issues if you encounter
          errors when using this environment variable.
        EOS
      end

      # See https://github.com/Homebrew/legacy-homebrew/pull/9986
      def check_path_for_trailing_slashes
        bad_paths = PATH.new(ENV["HOMEBREW_PATH"]).select { |p| p.end_with?("/") }<commit_msg>diagnostic: use ENV[]<commit_after>require "keg"
require "language/python"
require "formula"
require "version"
require "development_tools"
require "utils/shell"

module Homebrew
  module Diagnostic
    def self.missing_deps(ff, hide = nil)
      missing = {}
      ff.each do |f|
        missing_dependencies = f.missing_dependencies(hide: hide)

        unless missing_dependencies.empty?
          yield f.full_name, missing_dependencies if block_given?
          missing[f.full_name] = missing_dependencies
        end
      end
      missing
    end

    class Volumes
      def initialize
        @volumes = get_mounts
      end

      def which(path)
        vols = get_mounts path

        # no volume found
        return -1 if vols.empty?

        vol_index = @volumes.index(vols[0])
        # volume not found in volume list
        return -1 if vol_index.nil?
        vol_index
      end

      def get_mounts(path = nil)
        vols = []
        # get the volume of path, if path is nil returns all volumes

        args = %w[/bin/df -P]
        args << path if path

        Utils.popen_read(*args) do |io|
          io.each_line do |line|
            case line.chomp
              # regex matches: /dev/disk0s2   489562928 440803616  48247312    91%    /
            when /^.+\s+[0-9]+\s+[0-9]+\s+[0-9]+\s+[0-9]{1,3}%\s+(.+)/
              vols << Regexp.last_match(1)
            end
          end
        end
        vols
      end
    end

    class Checks
      ############# HELPERS
      # Finds files in HOMEBREW_PREFIX *and* /usr/local.
      # Specify paths relative to a prefix eg. "include/foo.h".
      # Sets @found for your convenience.
      def find_relative_paths(*relative_paths)
        @found = [HOMEBREW_PREFIX, "/usr/local"].uniq.inject([]) do |found, prefix|
          found + relative_paths.map { |f| File.join(prefix, f) }.select { |f| File.exist? f }
        end
      end

      def inject_file_list(list, string)
        list.inject(string) { |acc, elem| acc << "  #{elem}\n" }
      end
      ############# END HELPERS

      def development_tools_checks
        %w[
          check_for_installed_developer_tools
        ].freeze
      end

      def fatal_development_tools_checks
        %w[
        ].freeze
      end

      def build_error_checks
        (development_tools_checks + %w[
        ]).freeze
      end

      def check_for_installed_developer_tools
        return if DevelopmentTools.installed?

        <<-EOS.undent
          No developer tools installed.
          #{DevelopmentTools.installation_instructions}
        EOS
      end

      def check_build_from_source
        return unless ENV["HOMEBREW_BUILD_FROM_SOURCE"]

        <<-EOS.undent
          You have HOMEBREW_BUILD_FROM_SOURCE set. This environment variable is
          intended for use by Homebrew developers. If you are encountering errors,
          please try unsetting this. Please do not file issues if you encounter
          errors when using this environment variable.
        EOS
      end

      # See https://github.com/Homebrew/legacy-homebrew/pull/9986
      def check_path_for_trailing_slashes
        bad_paths = PATH.new(ENV["HOMEBREW_PATH"]).select { |p| p.end_with?("/") }
{'fraction_non_alphanumeric': 0.09555624611559975, 'fraction_numerical': 0.014916096954630205, 'mean_word_length': 2.0149882903981267, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6061653', 'n_tokens_mistral': 2075, 'n_tokens_neox': 1922, 'n_words': 514}