<commit_before>#!/usr/bin/env ruby
#--
# Copyright 2010 <NAME> <<EMAIL>>
# This program is free software. It may be redistributed and/or modified under
# the terms of the LGPL version 2.1 (or later).
#++

require 'optparse'
require 'rubygems'

provides = false
requires = false

opts = OptionParser.new("#{$0} <--provides|--requires>")
opts.on("-P", "--provides", "Print provides") do |val|
    provides = true
end
opts.on("-R", "--requires", "Print requires") do |val|
    requires= true
end

rest = opts.permute(ARGV)

if rest.size != 0 or (!provides and !requires) or (provides and requires)
    $stderr.puts "Use either --provides OR --requires"
    $stderr.puts opts
    exit(1)
end

specpath = "%s/specifications/.*\.gemspec$" % Gem::dir
gems = []
for gemspec in $stdin.readlines
  if gemspec.match(specpath)
    gems.push(gemspec.chomp)
  end
end
if gems.length > 0
  if requires
    require 'rbconfig'

    module Gem
      class Requirement
        def rpm_dependency_transform(name, version)
          pessimistic = ""
          if version == "> 0.0.0" or version == ">= 0"
            version = ""
          else
            if version[0..1] == "~>"
              pessimistic = "rubygem(%s) < %s\n" % [name, Gem::Version.create(version[3..-1]).bump]
              version = version.gsub(/\~>/, '=>')
            end
            version = version.gsub(/^/, ' ')
          end
          version = "rubygem(%s)%s\n%s" % [name, version, pessimistic]
        end

        def to_rpm(name)
          result = as_list
          return result.map { |version| rpm_dependency_transform(name, version) }
        end

      end
    end
    print "ruby >= %s\n" % Config::CONFIG["ruby_version"]
  end

  for gem in gems
    data = File.read(gem)
    spec = eval(data)
    if provides
      print "rubygem(%s) = %s\n" % [spec.name, spec.version]
    end
    if requires
      for d in spec.dependencies
        print d.version_requirements.to_rpm(d.name)
      end
      for d in spec.required_rubygems_version.to_rpm("rubygems")
        print d.gsub(/(rubygem\()|(\))/, "")
      end
    end
  end
end<commit_msg>add (commented out) strict dependency on ruby version<commit_after>#!/usr/bin/env ruby
#--
# Copyright 2010 <NAME> <<EMAIL>>
# This program is free software. It may be redistributed and/or modified under
# the terms of the LGPL version 2.1 (or later).
#++

require 'optparse'
require 'rubygems'

provides = false
requires = false

opts = OptionParser.new("#{$0} <--provides|--requires>")
opts.on("-P", "--provides", "Print provides") do |val|
    provides = true
end
opts.on("-R", "--requires", "Print requires") do |val|
    requires= true
end

rest = opts.permute(ARGV)

if rest.size != 0 or (!provides and !requires) or (provides and requires)
    $stderr.puts "Use either --provides OR --requires"
    $stderr.puts opts
    exit(1)
end

specpath = "%s/specifications/.*\.gemspec$" % Gem::dir
gems = []
for gemspec in $stdin.readlines
  if gemspec.match(specpath)
    gems.push(gemspec.chomp)
  end
end
if gems.length > 0
  if requires
    require 'rbconfig'

    module Gem
      class Requirement
        def rpm_dependency_transform(name, version)
          pessimistic = ""
          if version == "> 0.0.0" or version == ">= 0"
            version = ""
          else
            if version[0..1] == "~>"
              pessimistic = "rubygem(%s) < %s\n" % [name, Gem::Version.create(version[3..-1]).bump]
              version = version.gsub(/\~>/, '=>')
            end
            version = version.gsub(/^/, ' ')
          end
          version = "rubygem(%s)%s\n%s" % [name, version, pessimistic]
        end

        def to_rpm(name)
          result = as_list
          return result.map { |version| rpm_dependency_transform(name, version) }
        end

      end
    end
    # TODO: Should we add a strict dependency on ruby version here?
    #print "ruby < %s%s\n" % [Config::CONFIG["ruby_version"][0..-2], Config::CONFIG["ruby_version"][-1..-1].to_i + 1]
    print "ruby >= %s\n" % Config::CONFIG["ruby_version"]
  end

  for gem in gems
    data = File.read(gem)
    spec = eval(data)
    if provides
      print "rubygem(%s) = %s\n" % [spec.name, spec.version]
    end
    if requires
      for d in spec.dependencies
        print d.version_requirements.to_rpm(d.name)
      end
      for d in spec.required_rubygems_version.to_rpm("rubygems")
        print d.gsub(/(rubygem\()|(\))/, "")
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.14815647482014388, 'fraction_numerical': 0.009217625899280575, 'mean_word_length': 2.4170506912442398, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 25, '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': '7107557', 'n_tokens_mistral': 1557, 'n_tokens_neox': 1481, 'n_words': 395}