[前][次][番号順一覧][スレッド一覧]

ruby-changes:71290

From: Hiroshi <ko1@a...>
Date: Mon, 28 Feb 2022 11:39:42 +0900 (JST)
Subject: [ruby-changes:71290] ff3d7b720e (master): Merge RubyGems and Bundler master

https://git.ruby-lang.org/ruby.git/commit/?id=ff3d7b720e

From ff3d7b720ec21e4856aac0b3c493bc78cbac83d4 Mon Sep 17 00:00:00 2001
From: Hiroshi SHIBATA <hsbt@r...>
Date: Mon, 28 Feb 2022 10:32:28 +0900
Subject: Merge RubyGems and Bundler master

---
 lib/bundler.rb                                    |  2 +-
 lib/bundler/cli/config.rb                         | 11 +++++++-
 lib/bundler/cli/install.rb                        | 31 +++++------------------
 lib/bundler/fetcher.rb                            | 10 ++++----
 lib/bundler/psyched_yaml.rb                       | 10 --------
 lib/bundler/rubygems_ext.rb                       | 23 +++++++++--------
 lib/bundler/rubygems_integration.rb               | 16 ++----------
 lib/bundler/settings.rb                           |  2 +-
 spec/bundler/bundler/fetcher_spec.rb              |  4 +--
 spec/bundler/bundler/rubygems_integration_spec.rb | 11 ++------
 spec/bundler/commands/config_spec.rb              | 14 +++++++++-
 spec/bundler/commands/exec_spec.rb                |  6 ++---
 spec/bundler/commands/inject_spec.rb              |  2 +-
 spec/bundler/commands/lock_spec.rb                |  4 +--
 spec/bundler/install/gemfile/groups_spec.rb       | 13 ++--------
 spec/bundler/install/gems/standalone_spec.rb      |  3 ++-
 spec/bundler/realworld/parallel_spec.rb           |  2 +-
 spec/bundler/spec_helper.rb                       |  2 +-
 spec/bundler/support/helpers.rb                   | 27 +++++++++++---------
 tool/bundler/dev_gems.rb.lock                     |  2 +-
 20 files changed, 82 insertions(+), 113 deletions(-)
 delete mode 100644 lib/bundler/psyched_yaml.rb

diff --git a/lib/bundler.rb b/lib/bundler.rb
index 89865a8254..8688206285 100644
--- a/lib/bundler.rb
+++ b/lib/bundler.rb
@@ -654,7 +654,7 @@ EOF https://github.com/ruby/ruby/blob/trunk/lib/bundler.rb#L654
     private
 
     def eval_yaml_gemspec(path, contents)
-      require_relative "bundler/psyched_yaml"
+      Kernel.require "psych"
 
       Gem::Specification.from_yaml(contents)
     rescue ::Psych::SyntaxError, ArgumentError, Gem::EndOfYAMLException, Gem::Exception
diff --git a/lib/bundler/cli/config.rb b/lib/bundler/cli/config.rb
index 8d2aba0916..e1222c75dd 100644
--- a/lib/bundler/cli/config.rb
+++ b/lib/bundler/cli/config.rb
@@ -180,7 +180,7 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/cli/config.rb#L180
         scopes = %w[global local].select {|s| options[s] }
         case scopes.size
         when 0
-          @scope = "global"
+          @scope = inside_app? ? "local" : "global"
           @explicit_scope = false
         when 1
           @scope = scopes.first
@@ -189,6 +189,15 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/cli/config.rb#L189
             "The options #{scopes.join " and "} were specified. Please only use one of the switches at a time."
         end
       end
+
+      private
+
+      def inside_app?
+        Bundler.root
+        true
+      rescue GemfileNotFound
+        false
+      end
     end
   end
 end
diff --git a/lib/bundler/cli/install.rb b/lib/bundler/cli/install.rb
index c3400c3959..e9b85f7f6f 100644
--- a/lib/bundler/cli/install.rb
+++ b/lib/bundler/cli/install.rb
@@ -135,32 +135,13 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/cli/install.rb#L135
     end
 
     def normalize_groups
-      options[:with] &&= options[:with].join(":").tr(" ", ":").split(":")
-      options[:without] &&= options[:without].join(":").tr(" ", ":").split(":")
-
       check_for_group_conflicts_in_cli_options
 
-      Bundler.settings.set_command_option :with, nil if options[:with] == []
-      Bundler.settings.set_command_option :without, nil if options[:without] == []
-
-      with = options.fetch(:with, [])
-      with |= Bundler.settings[:with].map(&:to_s)
-      with -= options[:without] if options[:without]
-
-      without = options.fetch(:without, [])
-      without |= Bundler.settings[:without].map(&:to_s)
-      without -= options[:with] if options[:with]
-
-      options[:with]    = with
-      options[:without] = without
-
-      unless Bundler.settings[:without] == options[:without] && Bundler.settings[:with] == options[:with]
-        # need to nil them out first to get around validation for backwards compatibility
-        Bundler.settings.set_command_option :without, nil
-        Bundler.settings.set_command_option :with,    nil
-        Bundler.settings.set_command_option :without, options[:without] - options[:with]
-        Bundler.settings.set_command_option :with,    options[:with]
-      end
+      # need to nil them out first to get around validation for backwards compatibility
+      Bundler.settings.set_command_option :without, nil
+      Bundler.settings.set_command_option :with,    nil
+      Bundler.settings.set_command_option :without, options[:without]
+      Bundler.settings.set_command_option :with,    options[:with]
     end
 
     def normalize_settings
@@ -184,7 +165,7 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/cli/install.rb#L165
 
       Bundler.settings.set_command_option_if_given :clean, options["clean"]
 
-      normalize_groups
+      normalize_groups if options[:without] || options[:with]
 
       options[:force] = options[:redownload]
     end
diff --git a/lib/bundler/fetcher.rb b/lib/bundler/fetcher.rb
index 89103fe1ec..e07f925107 100644
--- a/lib/bundler/fetcher.rb
+++ b/lib/bundler/fetcher.rb
@@ -240,7 +240,7 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/fetcher.rb#L240
         raise SSLError if needs_ssl && !defined?(OpenSSL::SSL)
 
         con = PersistentHTTP.new :name => "bundler", :proxy => :ENV
-        if gem_proxy = Bundler.rubygems.configuration[:http_proxy]
+        if gem_proxy = Gem.configuration[:http_proxy]
           con.proxy = Bundler::URI.parse(gem_proxy) if gem_proxy != :no_proxy
         end
 
@@ -251,8 +251,8 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/fetcher.rb#L251
         end
 
         ssl_client_cert = Bundler.settings[:ssl_client_cert] ||
-          (Bundler.rubygems.configuration.ssl_client_cert if
-            Bundler.rubygems.configuration.respond_to?(:ssl_client_cert))
+          (Gem.configuration.ssl_client_cert if
+            Gem.configuration.respond_to?(:ssl_client_cert))
         if ssl_client_cert
           pem = File.read(ssl_client_cert)
           con.cert = OpenSSL::X509::Certificate.new(pem)
@@ -283,8 +283,8 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/fetcher.rb#L283
     def bundler_cert_store
       store = OpenSSL::X509::Store.new
       ssl_ca_cert = Bundler.settings[:ssl_ca_cert] ||
-        (Bundler.rubygems.configuration.ssl_ca_cert if
-          Bundler.rubygems.configuration.respond_to?(:ssl_ca_cert))
+        (Gem.configuration.ssl_ca_cert if
+          Gem.configuration.respond_to?(:ssl_ca_cert))
       if ssl_ca_cert
         if File.directory? ssl_ca_cert
           store.add_path ssl_ca_cert
diff --git a/lib/bundler/psyched_yaml.rb b/lib/bundler/psyched_yaml.rb
deleted file mode 100644
index 3d9893031f..0000000000
--- a/lib/bundler/psyched_yaml.rb
+++ /dev/null
@@ -1,10 +0,0 @@ https://github.com/ruby/ruby/blob/trunk/lib/bundler/fetcher.rb#L0
-# frozen_string_literal: true
-
-begin
-  require "psych"
-rescue LoadError
-  # Apparently Psych wasn't available. Oh well.
-end
-
-# At least load the YAML stdlib, whatever that may be
-require "yaml" unless defined?(YAML.dump)
diff --git a/lib/bundler/rubygems_ext.rb b/lib/bundler/rubygems_ext.rb
index 5d572aa73d..cc06b9ee93 100644
--- a/lib/bundler/rubygems_ext.rb
+++ b/lib/bundler/rubygems_ext.rb
@@ -4,14 +4,12 @@ require "pathname" https://github.com/ruby/ruby/blob/trunk/lib/bundler/rubygems_ext.rb#L4
 
 require "rubygems/specification"
 
-# Possible use in Gem::Specification#source below and require
-# shouldn't be deferred.
-require "rubygems/source"
-
 require_relative "match_platform"
 
 module Gem
   class Specification
+    include ::Bundler::MatchPlatform
+
     attr_accessor :remote, :location, :relative_loaded_from
 
     remove_method :source
@@ -81,6 +79,17 @@ module Gem https://github.com/ruby/ruby/blob/trunk/lib/bundler/rubygems_ext.rb#L79
       gemfile
     end
 
+    # Backfill missing YAML require when not defined. Fixed since 3.1.0.pre1.
+    module YamlBackfiller
+      def to_yaml(opts = {})
+        Gem.load_yaml unless defined?(::YAML)
+
+        super(opts)
+      end
+    end
+
+    prepend YamlBackfiller
+
     def nondevelopment_dependencies
       dependencies - development_dependencies
     end
@@ -228,9 +237,3 @@ module Gem https://github.com/ruby/ruby/blob/trunk/lib/bundler/rubygems_ext.rb#L237
     end
   end
 end
-
-module Gem
-  class Specification
-    include ::Bundler::MatchPlatform
-  end
-end
diff --git a/lib/bundler/rubygems_integration.rb b/lib/bundler/rubygems_integration.rb
index 785f7fa360..1c2b374d8b 100644
--- a/lib/bundler/rubygems_integration.rb
+++ b/lib/bundler/rubygems_integration.rb
@@ -104,18 +104,6 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/rubygems_integration.rb#L104
       obj.to_s
     end
 
-    def configuration
-      require_relative "psyched_yaml"
-      Gem.configuration
-    rescue Gem::SystemExitException, LoadError => e
-      Bundler.ui.error "#{e.class}: #{e.message}"
-      Bundler.ui.trace e
-      raise
-    rescue ::Psych::SyntaxError => e
-      raise YamlSyntaxError.new(e, "Your RubyGems configuration, which is " \
-        "usually located in ~/.gemrc, contains invalid YAML syntax.")
-    end
-
     def ruby_engine
       Gem.ruby_engine
     end
@@ -217,7 +205,7 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/rubygems_integration.rb#L205
 
     def spec_from_gem(path, policy = nil)
       require "rubygems/security"
-      require_relative "psyched_yaml"
+      require "psych"
       gem_from_path(path, security_policies[policy]).spec
     rescue Exception, Gem::Exception,  (... truncated)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]