ruby-changes:30888
From: drbrain <ko1@a...>
Date: Thu, 19 Sep 2013 06:29:57 +0900 (JST)
Subject: [ruby-changes:30888] drbrain:r42967 (trunk): * lib/rubygems: Update to RubyGems 2.2.0.preview.1
drbrain 2013-09-19 06:29:41 +0900 (Thu, 19 Sep 2013) New Revision: 42967 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=42967 Log: * lib/rubygems: Update to RubyGems 2.2.0.preview.1 This brings several new features to RubyGems summarized here: https://github.com/rubygems/rubygems/blob/v2.2.0.preview.1/History.txt * test/rubygems: ditto. Modified files: trunk/ChangeLog trunk/lib/rubygems/commands/list_command.rb trunk/lib/rubygems/commands/pristine_command.rb trunk/lib/rubygems/commands/push_command.rb trunk/lib/rubygems/commands/query_command.rb trunk/lib/rubygems/commands/search_command.rb trunk/lib/rubygems/commands/uninstall_command.rb trunk/lib/rubygems/commands/update_command.rb trunk/lib/rubygems/commands/which_command.rb trunk/lib/rubygems/gemcutter_utilities.rb trunk/lib/rubygems/package.rb trunk/lib/rubygems/request.rb trunk/lib/rubygems/requirement.rb trunk/lib/rubygems/specification.rb trunk/lib/rubygems.rb trunk/test/rubygems/test_gem_commands_install_command.rb trunk/test/rubygems/test_gem_commands_pristine_command.rb trunk/test/rubygems/test_gem_commands_push_command.rb trunk/test/rubygems/test_gem_commands_query_command.rb trunk/test/rubygems/test_gem_commands_uninstall_command.rb trunk/test/rubygems/test_gem_commands_update_command.rb trunk/test/rubygems/test_gem_package.rb trunk/test/rubygems/test_gem_request.rb trunk/test/rubygems/test_gem_specification.rb trunk/test/rubygems/test_gem_uninstaller.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 42966) +++ ChangeLog (revision 42967) @@ -1,3 +1,13 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Thu Sep 19 06:29:30 2013 Eric Hodel <drbrain@s...> + + * lib/rubygems: Update to RubyGems 2.2.0.preview.1 + + This brings several new features to RubyGems summarized here: + + https://github.com/rubygems/rubygems/blob/v2.2.0.preview.1/History.txt + + * test/rubygems: ditto. + Wed Sep 18 23:14:58 2013 Masaki Matsushita <glass.saga@g...> * string.c (rb_str_enumerate_lines): make String#each_line and Index: lib/rubygems/gemcutter_utilities.rb =================================================================== --- lib/rubygems/gemcutter_utilities.rb (revision 42966) +++ lib/rubygems/gemcutter_utilities.rb (revision 42967) @@ -56,8 +56,10 @@ module Gem::GemcutterUtilities https://github.com/ruby/ruby/blob/trunk/lib/rubygems/gemcutter_utilities.rb#L56 ## # Creates an RubyGems API to +host+ and +path+ with the given HTTP +method+. + # + # If +allowed_push_host+ metadata is present, then it will only allow that host. - def rubygems_api_request(method, path, host = nil, &block) + def rubygems_api_request(method, path, host = nil, allowed_push_host = nil, &block) require 'net/http' self.host = host if host @@ -66,6 +68,11 @@ module Gem::GemcutterUtilities https://github.com/ruby/ruby/blob/trunk/lib/rubygems/gemcutter_utilities.rb#L68 terminate_interaction 1 # TODO: question this end + if allowed_push_host and self.host != allowed_push_host + alert_error "#{self.host.inspect} is not allowed by the gemspec, which only allows #{allowed_push_host.inspect}" + terminate_interaction 1 + end + uri = URI.parse "#{self.host}/#{path}" request_method = Net::HTTP.const_get method.to_s.capitalize Index: lib/rubygems/specification.rb =================================================================== --- lib/rubygems/specification.rb (revision 42966) +++ lib/rubygems/specification.rb (revision 42967) @@ -327,7 +327,7 @@ class Gem::Specification < Gem::BasicSpe https://github.com/ruby/ruby/blob/trunk/lib/rubygems/specification.rb#L327 add_bindir(@executables), @extra_rdoc_files, @extensions, - ].flatten.uniq.compact + ].flatten.sort.uniq.compact end ###################################################################### @@ -1321,9 +1321,7 @@ class Gem::Specification < Gem::BasicSpe https://github.com/ruby/ruby/blob/trunk/lib/rubygems/specification.rb#L1321 def add_self_to_load_path return if default_gem? - paths = require_paths.map do |path| - File.join full_gem_path, path - end + paths = full_require_paths # gem directories must come after -I and ENV['RUBYLIB'] insert_index = Gem.load_path_insert_index @@ -2017,6 +2015,17 @@ class Gem::Specification < Gem::BasicSpe https://github.com/ruby/ruby/blob/trunk/lib/rubygems/specification.rb#L2015 end ## + # Full paths in the gem to add to <code>$LOAD_PATH</code> when this gem is + # activated. + # + + def full_require_paths + require_paths.map do |path| + File.join full_gem_path, path + end + end + + ## # The RubyGems version required by this gem def required_rubygems_version= req @@ -2380,6 +2389,11 @@ class Gem::Specification < Gem::BasicSpe https://github.com/ruby/ruby/blob/trunk/lib/rubygems/specification.rb#L2389 "[\"#{non_files.join "\", \""}\"] are not files" end + if files.include? file_name then + raise Gem::InvalidSpecificationException, + "#{full_name} contains itself (#{file_name}), check your files list" + end + unless specification_version.is_a?(Fixnum) raise Gem::InvalidSpecificationException, 'specification_version must be a Fixnum (did you mean version?)' Index: lib/rubygems/commands/push_command.rb =================================================================== --- lib/rubygems/commands/push_command.rb (revision 42966) +++ lib/rubygems/commands/push_command.rb (revision 42967) @@ -69,13 +69,18 @@ You can upgrade or downgrade to the late https://github.com/ruby/ruby/blob/trunk/lib/rubygems/commands/push_command.rb#L69 terminate_interaction 1 end + gem_data = Gem::Package.new(name) + unless @host then - if gem_data = Gem::Package.new(name) then - @host = gem_data.spec.metadata['default_gem_server'] - end + @host = gem_data.spec.metadata['default_gem_server'] end - args << @host if @host + # Always include this, even if it's nil + args << @host + + if gem_data.spec.metadata.has_key?('allowed_push_host') + args << gem_data.spec.metadata['allowed_push_host'] + end say "Pushing gem to #{@host || Gem.host}..." Index: lib/rubygems/commands/update_command.rb =================================================================== --- lib/rubygems/commands/update_command.rb (revision 42966) +++ lib/rubygems/commands/update_command.rb (revision 42967) @@ -244,6 +244,9 @@ command to remove old versions. https://github.com/ruby/ruby/blob/trunk/lib/rubygems/commands/update_command.rb#L244 args << '--no-rdoc' unless options[:document].include? 'rdoc' args << '--no-ri' unless options[:document].include? 'ri' args << '--no-format-executable' if options[:no_format_executable] + args << '--previous-version' << Gem::VERSION if + options[:system] == true or + Gem::Version.new(options[:system]) >= Gem::Version.new(2) args end Index: lib/rubygems/commands/pristine_command.rb =================================================================== --- lib/rubygems/commands/pristine_command.rb (revision 42966) +++ lib/rubygems/commands/pristine_command.rb (revision 42967) @@ -12,6 +12,7 @@ class Gem::Commands::PristineCommand < G https://github.com/ruby/ruby/blob/trunk/lib/rubygems/commands/pristine_command.rb#L12 'Restores installed gems to pristine condition from files located in the gem cache', :version => Gem::Requirement.default, :extensions => true, + :extensions_set => false, :all => false add_option('--all', @@ -23,7 +24,8 @@ class Gem::Commands::PristineCommand < G https://github.com/ruby/ruby/blob/trunk/lib/rubygems/commands/pristine_command.rb#L24 add_option('--[no-]extensions', 'Restore gems with extensions', 'in addition to regular gems') do |value, options| - options[:extensions] = value + options[:extensions_set] = true + options[:extensions] = value end add_option('--only-executables', @@ -62,6 +64,9 @@ If the cached gem cannot be found it wil https://github.com/ruby/ruby/blob/trunk/lib/rubygems/commands/pristine_command.rb#L64 If --no-extensions is provided pristine will not attempt to restore a gem with an extension. + +If --extensions is given (but not --all or gem names) only gems with +extensions will be restored. EOF end @@ -72,6 +77,14 @@ with an extension. https://github.com/ruby/ruby/blob/trunk/lib/rubygems/commands/pristine_command.rb#L77 def execute specs = if options[:all] then Gem::Specification.map + + # `--extensions` must be explicitly given to pristine only gems + # with extensions. + elsif options[:extensions_set] and + options[:extensions] and options[:args].empty? then + Gem::Specification.select do |spec| + spec.extensions and not spec.extensions.empty? + end else get_all_gem_names.map do |gem_name| Gem::Specification.find_all_by_name gem_name, options[:version] Index: lib/rubygems/commands/which_command.rb =================================================================== --- lib/rubygems/commands/which_command.rb (revision 42966) +++ lib/rubygems/commands/which_command.rb (revision 42967) @@ -45,9 +45,9 @@ requiring to see why it does not behave https://github.com/ruby/ruby/blob/trunk/lib/rubygems/commands/which_command.rb#L45 if spec then if options[:search_gems_first] then - dirs = gem_paths(spec) + $LOAD_PATH + dirs = spec.full_require_paths + $LOAD_PATH else - dirs = $LOAD_PATH + gem_paths(spec) + dirs = $LOAD_PATH + spec.full_require_paths end end @@ -81,10 +81,6 @@ requiring to see why it does not behave https://github.com/ruby/ruby/blob/trunk/lib/rubygems/commands/which_command.rb#L81 result end - def gem_paths(spec) - spec.require_paths.collect { |d| File.join spec.full_gem_path, d } - end - def usage # :nodoc: "#{program_name} FILE [FILE ...]" end Index: lib/rubygems/commands/query_command.rb =================================================================== --- lib/rubygems/commands/query_command.rb (revision 42966) +++ lib/rubygems/commands/query_command.rb (revision 42967) @@ -72,16 +72,26 @@ is too hard to use. https://github.com/ruby/ruby/blob/trunk/lib/rubygems/commands/query_command.rb#L72 def execute exit_code = 0 + if options[:args].to_a.empty? and options[:name].source.empty? + name = options[:name] + no_name = true + elsif !options[:name].source.empty? + name = Array(options[:name]) + else + name = options[:args].to_a.map{|arg| /#{arg}/i } + end - name = options[:name] prerelease = options[:prerelease] unless options[:installed].nil? then - if name.source.empty? then + if no_name then alert_error "You must specify a gem name" exit_code |= 4 + elsif name.count > 1 + alert_error "You must specify only ONE gem!" + exit_code |= 4 else - installed = installed? name, options[:version] + installed = installed? name.first, options[:version] installed = !installed unless options[:installed] if installed then @@ -95,6 +105,22 @@ is too hard to use. https://github.com/ruby/ruby/blob/trunk/lib/rubygems/commands/query_command.rb#L105 terminate_interaction exit_code end + names = Array(name) + names.each { |n| show_gems n, prerelease } + end + + private + + def display_header type + if (ui.outs.tty? and Gem.configuration.verbose) or both? then + say + say "*** #{type} GEMS ***" + say + end + end + + #Guts of original execute + def show_gems name, prerelease req = Gem::Requirement.default # TODO: deprecate for real dep = Gem::Deprecate.skip_during { Gem::Dependency.new name, req } @@ -105,11 +131,7 @@ is too hard to use. https://github.com/ruby/ruby/blob/trunk/lib/rubygems/commands/query_command.rb#L131 alert_warning "prereleases are always shown locally" end - if ui.outs.tty? or both? then - say - say "*** LOCAL GEMS ***" - say - end + display_header 'LOCAL' specs = Gem::Specification.find_all { |s| s.name =~ name and req =~ s.version @@ -123,11 +145,7 @@ is too hard to use. https://github.com/ruby/ruby/blob/trunk/lib/rubygems/commands/query_command.rb#L145 end if remote? then - if ui.outs.tty? or both? then - say - say "*** REMOTE GEMS ***" - say - end + display_header 'REMOTE' fetcher = Gem::SpecFetcher.fetcher @@ -155,8 +173,6 @@ is too hard to use. https://github.com/ruby/ruby/blob/trunk/lib/rubygems/commands/query_command.rb#L173 end end - private - ## # Check if gem +name+ version +version+ is installed. Index: lib/rubygems/commands/search_command.rb =================================================================== --- lib/rubygems/commands/search_command.rb (revision 42966) +++ lib/rubygems/commands/search_command.rb (revision 42967) @@ -36,11 +36,5 @@ To list local gems use the list command. https://github.com/ruby/ruby/blob/trunk/lib/rubygems/commands/search_command.rb#L36 "#{program_name} [STRING]" end - def execute - string = get_one_optional_argument - options[:name] = /#{string}/i - super - end - end Index: lib/rubygems/commands/uninstall_command.rb =================================================================== --- lib/rubygems/commands/uninstall_command.rb (revision 42966) +++ lib/rubygems/commands/uninstall_command.rb (revision 42967) @@ -15,7 +15,7 @@ class Gem::Commands::UninstallCommand < https://github.com/ruby/ruby/blob/trunk/lib/rubygems/commands/uninstall_command.rb#L15 def initialize super 'uninstall', 'Uninstall gems from the local repository', :version => Gem::Requirement.default, :user_install => true, - :install_dir => Gem.dir, :check_dev => false + :check_dev => false add_option('-a', '--[no-]all', 'Uninstall all matching versions' @@ -84,7 +84,6 @@ class Gem::Commands::UninstallCommand < https://github.com/ruby/ruby/blob/trunk/lib/rubygems/commands/uninstall_command.rb#L84 def defaults_str # :nodoc: "--version '#{Gem::Requirement.default}' --no-force " + - "--install-dir #{Gem.dir}\n" + "--user-install" end @@ -104,8 +103,7 @@ that is a dependency of an existing gem. https://github.com/ruby/ruby/blob/trunk/lib/rubygems/commands/uninstall_command.rb#L103 def execute if options[:all] and not options[:args].empty? then - alert_error 'Gem names and --all may not be used together' - terminate_interaction 1 + uninstall_specific elsif options[:all] then uninstall_all else Index: lib/rubygems/commands/list_command.rb =================================================================== --- lib/rubygems/commands/list_command.rb (revision 42966) +++ lib/rubygems/commands/list_command.rb (revision 42967) @@ -33,13 +33,7 @@ To search for remote gems use the search https://github.com/ruby/ruby/blob/trunk/lib/rubygems/commands/list_command.rb#L33 end def usage # :nodoc: - "#{program_name} [STRING]" - end - - def execute - string = get_one_optional_argument || '' - options[:name] = /^#{string}/i - super + "#{program_name} [STRING ...]" end end Index: lib/rubygems/requirement.rb =================================================================== --- lib/rubygems/requirement.rb (revision 42966) +++ lib/rubygems/requirement.rb (revision 42967) @@ -1,13 +1,3 @@ https://github.com/ruby/ruby/blob/trunk/lib/rubygems/requirement.rb#L1 -## -# A Requirement is a set of one or more version restrictions. It supports a -# few (<tt>=, !=, >, <, >=, <=, ~></tt>) different restriction operators. - -# REFACTOR: The fact that a requirement is singular or plural is kind of -# awkward. Is Requirement the right name for this? Or should it be one -# [op, number] pair, and we call the list of requirements something else? -# Since a Requirement is held by a Dependency, maybe this should be made -# singular and the list aspect should be pulled up into Dependency? - require "rubygems/version" require "rubygems/deprecate" @@ -15,6 +5,10 @@ require "rubygems/deprecate" https://github.com/ruby/ruby/blob/trunk/lib/rubygems/requirement.rb#L5 # load our yaml + workarounds now. Gem.load_yaml if defined? ::YAML +## +# A Requirement is a set of one or more version restrictions. It supports a +# few (<tt>=, !=, >, <, >=, <=, ~></tt>) different restriction operators. + class Gem::Requirement OPS = { #:nodoc: "=" => lambda { |v, r| v == r }, @@ -41,9 +35,6 @@ class Gem::Requirement https://github.com/ruby/ruby/blob/trunk/lib/rubygems/requirement.rb#L35 # If the input is "weird", the default version requirement is # returned. - # REFACTOR: There's no reason that this can't be unified with .new. - # .new is the standard Ruby factory method. - def self.create input case input when Gem::Requirement then @@ -78,11 +69,6 @@ class Gem::Requirement https://github.com/ruby/ruby/blob/trunk/lib/rubygems/requirement.rb#L69 # parse("1.0") # => ["=", "1.0"] # parse(Gem::Version.new("1.0")) # => ["=, "1.0"] - # REFACTOR: Little two element arrays like this have no real semantic - # value. I'd love to see something like this: - # Constraint = Struct.new(:operator, :version); (or similar) - # and have a Requirement be a list of Constraints. - def self.parse obj return ["=", obj] if Gem::Version === obj Index: lib/rubygems/request.rb =================================================================== --- lib/rubygems/request.rb (revision 42966) +++ lib/rubygems/request.rb (revision 42967) @@ -21,7 +21,7 @@ class Gem::Request https://github.com/ruby/ruby/blob/trunk/lib/rubygems/request.rb#L21 @proxy_uri = case proxy when :no_proxy then nil - when nil then get_proxy_from_env + when nil then get_proxy_from_env uri.scheme when URI::HTTP then proxy else URI.parse(proxy) end @@ -203,19 +203,27 @@ class Gem::Request https://github.com/ruby/ruby/blob/trunk/lib/rubygems/request.rb#L203 end ## - # Returns an HTTP proxy URI if one is set in the environment variables. + # Returns a proxy URI for the given +scheme+ if one is set in the + # environment variables. - def get_proxy_from_env - env_proxy = ENV['http_proxy'] || ENV['HTTP_PROXY'] + def get_proxy_from_env scheme = 'http' + _scheme = scheme.downcase + _SCHEME = scheme.upcase + env_proxy = ENV["#{_scheme}_proxy"] || ENV["#{_SCHEME}_PROXY"] - return nil if env_proxy.nil? or env_proxy.empty? + no_env_proxy = env_proxy.nil? || env_proxy.empty? + + return get_proxy_from_env 'http' if no_env_proxy and _scheme != 'http' + return nil if no_env_proxy uri = URI(Gem::UriFormatter.new(env_proxy).normalize) if uri and uri.user.nil? and uri.password.nil? then - # Probably we have http_proxy_* variables? - uri.user = Gem::UriFormatter.new(ENV['http_proxy_user'] || ENV['HTTP_PROXY_USER']).escape - uri.password = Gem::UriFormatter.new(ENV['http_proxy_pass'] || ENV['HTTP_PROXY_PASS']).escape + user = ENV["#{_scheme}_proxy_user"] || ENV["#{_SCHEME}_PROXY_USER"] + password = ENV["#{_scheme}_proxy_pass"] || ENV["#{_SCHEME}_PROXY_PASS"] + + uri.user = Gem::UriFormatter.new(user).escape + uri.password = Gem::UriFormatter.new(password).escape end uri Index: lib/rubygems/package.rb =================================================================== --- lib/rubygems/package.rb (revision 42966) +++ lib/rubygems/package.rb (revision 42967) @@ -349,11 +349,20 @@ EOM https://github.com/ruby/ruby/blob/trunk/lib/rubygems/package.rb#L349 FileUtils.rm_rf destination - FileUtils.mkdir_p File.dirname destination + mkdir_options = {} + mkdir_options[:mode] = entry.header.mode if entry.directory? + mkdir = + if entry.directory? then + destination + else + File.dirname destination + end + + FileUtils.mkdir_p mkdir, mkdir_options open destination, 'wb', entry.header.mode do |out| out.write entry.read - end + end if entry.file? say destination if Gem.configuration.really_verbose end Index: lib/rubygems.rb =================================================================== --- lib/rubygems.rb (revision 42966) +++ lib/rubygems.rb (revision 42967) @@ -8,7 +8,7 @@ https://github.com/ruby/ruby/blob/trunk/lib/rubygems.rb#L8 require 'rbconfig' module Gem - VERSION = '2.1.3' + VERSION = '2.2.0.preview.1' end # Must be first since it unloads the prelude from 1.9.2 Index: test/rubygems/test_gem_commands_uninstall_command.rb =================================================================== --- test/rubygems/test_gem (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/