diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 4728c2a..a699e0b 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -12,10 +12,10 @@ jobs: image: mysql strategy: matrix: - ruby: [ '2.5', '2.6', '2.7', '3.0', '3.1', '3.2' ] + ruby: [ '2.7', '3.0', '3.1', '3.2' ] task: [ 'spec' ] include: - - ruby: 2.5 # keep in sync with lowest version + - ruby: 2.7 # keep in sync with lowest version task: rubocop name: ${{ matrix.ruby }} rake ${{ matrix.task }} steps: diff --git a/.rubocop.yml b/.rubocop.yml index 9fa1d8c..c7762da 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -4,17 +4,11 @@ require: AllCops: NewCops: enable - TargetRubyVersion: 2.5 + TargetRubyVersion: 2.7 Style/StringLiterals: Enabled: false -Style/StringLiteralsInInterpolation: - Enabled: false - -Lint/AmbiguousRegexpLiteral: - Enabled: false - Bundler/OrderedGems: Enabled: false @@ -65,9 +59,6 @@ Style/SymbolArray: Style/GuardClause: Enabled: false -Lint/AssignmentInCondition: - Enabled: false - Style/EmptyElse: Enabled: false diff --git a/Gemfile.lock b/Gemfile.lock index 1b5404d..faf2145 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -23,14 +23,20 @@ GEM diff-lcs (1.5.0) i18n (1.10.0) concurrent-ruby (~> 1.0) + json (2.7.1) + json (2.7.1-java) + language_server-protocol (3.17.0.3) minitest (5.15.0) - mysql2 (0.5.3) - parser (3.1.1.0) + mysql2 (0.5.6) + parser (3.3.0.5) ast (~> 2.4.1) + racc + racc (1.7.3) + racc (1.7.3-java) rainbow (3.1.1) rake (13.0.6) - regexp_parser (2.2.1) - rexml (3.2.5) + regexp_parser (2.9.0) + rexml (3.2.6) rspec (3.11.0) rspec-core (~> 3.11.0) rspec-expectations (~> 3.11.0) @@ -48,26 +54,28 @@ GEM rspec-rerun (1.1.0) rspec (~> 3.0) rspec-support (3.11.0) - rubocop (1.26.0) + rubocop (1.62.1) + json (~> 2.3) + language_server-protocol (>= 3.17.0) parallel (~> 1.10) - parser (>= 3.1.0.0) + parser (>= 3.3.0.2) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) - rexml - rubocop-ast (>= 1.16.0, < 2.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.31.1, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 1.4.0, < 3.0) - rubocop-ast (1.16.0) - parser (>= 3.1.1.0) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.31.2) + parser (>= 3.3.0.4) rubocop-rake (0.6.0) rubocop (~> 1.0) rubocop-rspec (2.9.0) rubocop (~> 1.19) - ruby-progressbar (1.11.0) + ruby-progressbar (1.13.0) sqlite3 (1.4.2) tzinfo (2.0.4) concurrent-ruby (~> 1.0) - unicode-display_width (2.1.0) + unicode-display_width (2.5.0) zeitwerk (2.5.4) PLATFORMS diff --git a/lib/parallel.rb b/lib/parallel.rb index ee83a07..59a72dc 100644 --- a/lib/parallel.rb +++ b/lib/parallel.rb @@ -24,7 +24,7 @@ class UndumpableException < StandardError attr_reader :backtrace def initialize(original) - super "#{original.class}: #{original.message}" + super("#{original.class}: #{original.message}") @backtrace = original.backtrace end end @@ -300,12 +300,12 @@ def map_with_index(array, options = {}, &block) map(array, options.merge(with_index: true), &block) end - def flat_map(*args, &block) - map(*args, &block).flatten(1) + def flat_map(...) + map(...).flatten(1) end - def filter_map(*args, &block) - map(*args, &block).compact + def filter_map(...) + map(...).compact end # Number of physical processor cores on the current system. @@ -359,7 +359,7 @@ def worker_number=(worker_num) private def add_progress_bar!(job_factory, options) - if progress_options = options[:progress] + if (progress_options = options[:progress]) raise "Progressbar can only be used with array like items" if job_factory.size == Float::INFINITY require 'ruby-progressbar' @@ -388,7 +388,7 @@ def work_direct(job_factory, options, &block) results = [] exception = nil begin - while set = job_factory.next + while (set = job_factory.next) item, index = set results << with_instrumentation(item, index, options) do call_with_index(item, index, options, &block) @@ -411,7 +411,7 @@ def work_in_threads(job_factory, options, &block) in_threads(options) do |worker_num| self.worker_number = worker_num # as long as there are more jobs, work on one of them - while !exception && set = job_factory.next + while !exception && (set = job_factory.next) begin item, index = set result = with_instrumentation item, index, options do @@ -455,7 +455,7 @@ def work_in_ractors(job_factory, options) # start ractors.dup.each do |ractor| - if set = job_factory.next + if (set = job_factory.next) item, index = set instrument_start item, index, options ractor.send [callback, item, index] @@ -466,7 +466,7 @@ def work_in_ractors(job_factory, options) end # replace with new items - while set = job_factory.next + while (set = job_factory.next) item_next, index_next = set done, (exception, result, item, index) = Ractor.select(*ractors) if exception @@ -669,7 +669,7 @@ def instrument_finish_in_order(item, index, result, options) end def instrument_start(item, index, options) - return unless on_start = options[:start] + return unless (on_start = options[:start]) options[:mutex].synchronize { on_start.call(item, index) } end end diff --git a/parallel.gemspec b/parallel.gemspec index ac77d09..d508190 100644 --- a/parallel.gemspec +++ b/parallel.gemspec @@ -16,5 +16,5 @@ Gem::Specification.new name, Parallel::VERSION do |s| } s.files = `git ls-files lib MIT-LICENSE.txt`.split("\n") s.license = "MIT" - s.required_ruby_version = '>= 2.5' + s.required_ruby_version = '>= 2.7' end diff --git a/spec/cases/each_with_ar_sqlite.rb b/spec/cases/each_with_ar_sqlite.rb index d326144..fb25dde 100644 --- a/spec/cases/each_with_ar_sqlite.rb +++ b/spec/cases/each_with_ar_sqlite.rb @@ -4,7 +4,7 @@ require "sqlite3" require "tempfile" $stdout.sync = true -in_worker_type = "in_#{ENV.fetch('WORKER_TYPE')}".to_sym +in_worker_type = :"in_#{ENV.fetch('WORKER_TYPE')}" Tempfile.create("db") do |temp| ActiveRecord::Schema.verbose = false diff --git a/spec/cases/finish_in_order.rb b/spec/cases/finish_in_order.rb index b8c0339..79e921f 100644 --- a/spec/cases/finish_in_order.rb +++ b/spec/cases/finish_in_order.rb @@ -10,7 +10,7 @@ def self.call(item) end method = ENV.fetch('METHOD') -in_worker_type = "in_#{ENV.fetch('WORKER_TYPE')}".to_sym +in_worker_type = :"in_#{ENV.fetch('WORKER_TYPE')}" $stdout.sync = true items = [nil, false, 2, 3, 4] diff --git a/spec/cases/profile_memory.rb b/spec/cases/profile_memory.rb index 89d13cf..508de4f 100644 --- a/spec/cases/profile_memory.rb +++ b/spec/cases/profile_memory.rb @@ -8,7 +8,7 @@ def count_objects GC.start GC.start ObjectSpace.each_object { |o| cur[o.class] += 1 } - cur.map { |k, v| [k, v - old[k]] }.to_h.reject { |_k, v| v == 0 } + cur.to_h { |k, v| [k, v - old[k]] }.reject { |_k, v| v == 0 } end class Callback @@ -18,7 +18,7 @@ def self.call(x); end require './spec/cases/helper' items = Array.new(1000) -options = { "in_#{ARGV[0]}".to_sym => 2 } +options = { "in_#{ARGV[0]}": 2 } # TODO: not sure why this fails without 2.times in threading mode :( diff --git a/spec/cases/with_break.rb b/spec/cases/with_break.rb index 3ea9a27..38bffa5 100644 --- a/spec/cases/with_break.rb +++ b/spec/cases/with_break.rb @@ -3,7 +3,7 @@ $stdout.sync = true # otherwise results can go weird... method = ENV.fetch('METHOD') -in_worker_type = "in_#{ENV.fetch('WORKER_TYPE')}".to_sym +in_worker_type = :"in_#{ENV.fetch('WORKER_TYPE')}" worker_size = (ENV['WORKER_SIZE'] || 4).to_i ARGV.freeze # make ractor happy diff --git a/spec/cases/with_break_before_finish.rb b/spec/cases/with_break_before_finish.rb index c5764e7..adfd2e3 100644 --- a/spec/cases/with_break_before_finish.rb +++ b/spec/cases/with_break_before_finish.rb @@ -2,7 +2,7 @@ require './spec/cases/helper' method = ENV.fetch('METHOD') -in_worker_type = "in_#{ENV.fetch('WORKER_TYPE')}".to_sym +in_worker_type = :"in_#{ENV.fetch('WORKER_TYPE')}" $stdout.sync = true class Callback diff --git a/spec/cases/with_exception.rb b/spec/cases/with_exception.rb index ffecf53..0b92d0f 100644 --- a/spec/cases/with_exception.rb +++ b/spec/cases/with_exception.rb @@ -3,7 +3,7 @@ $stdout.sync = true # otherwise results can go weird... method = ENV.fetch('METHOD') -in_worker_type = "in_#{ENV.fetch('WORKER_TYPE')}".to_sym +in_worker_type = :"in_#{ENV.fetch('WORKER_TYPE')}" worker_size = (ENV['WORKER_SIZE'] || 4).to_i class ParallelTestError < StandardError diff --git a/spec/cases/with_exception_before_finish.rb b/spec/cases/with_exception_before_finish.rb index 5bc429c..d3c876a 100644 --- a/spec/cases/with_exception_before_finish.rb +++ b/spec/cases/with_exception_before_finish.rb @@ -2,7 +2,7 @@ require './spec/cases/helper' method = ENV.fetch('METHOD') -in_worker_type = "in_#{ENV.fetch('WORKER_TYPE')}".to_sym +in_worker_type = :"in_#{ENV.fetch('WORKER_TYPE')}" class ParallelTestError < StandardError end diff --git a/spec/cases/with_exception_in_finish.rb b/spec/cases/with_exception_in_finish.rb index 856b791..eecdaae 100644 --- a/spec/cases/with_exception_in_finish.rb +++ b/spec/cases/with_exception_in_finish.rb @@ -3,7 +3,7 @@ $stdout.sync = true method = ENV.fetch('METHOD') -in_worker_type = "in_#{ENV.fetch('WORKER_TYPE')}".to_sym +in_worker_type = :"in_#{ENV.fetch('WORKER_TYPE')}" class ParallelTestError < StandardError end diff --git a/spec/cases/with_exception_in_start.rb b/spec/cases/with_exception_in_start.rb index 6d49117..e409df3 100644 --- a/spec/cases/with_exception_in_start.rb +++ b/spec/cases/with_exception_in_start.rb @@ -2,7 +2,7 @@ require './spec/cases/helper' method = ENV.fetch('METHOD') -in_worker_type = "in_#{ENV.fetch('WORKER_TYPE')}".to_sym +in_worker_type = :"in_#{ENV.fetch('WORKER_TYPE')}" class ParallelTestError < StandardError end diff --git a/spec/cases/with_exception_in_start_before_finish.rb b/spec/cases/with_exception_in_start_before_finish.rb index 7ff5a05..472cfb1 100644 --- a/spec/cases/with_exception_in_start_before_finish.rb +++ b/spec/cases/with_exception_in_start_before_finish.rb @@ -2,7 +2,7 @@ require './spec/cases/helper' method = ENV.fetch('METHOD') -in_worker_type = "in_#{ENV.fetch('WORKER_TYPE')}".to_sym +in_worker_type = :"in_#{ENV.fetch('WORKER_TYPE')}" $stdout.sync = true class ParallelTestError < StandardError diff --git a/spec/cases/with_worker_number.rb b/spec/cases/with_worker_number.rb index 6afaab5..8a9976e 100644 --- a/spec/cases/with_worker_number.rb +++ b/spec/cases/with_worker_number.rb @@ -2,7 +2,7 @@ require './spec/cases/helper' method = ENV.fetch('METHOD') -in_worker_type = "in_#{ENV.fetch('WORKER_TYPE')}".to_sym +in_worker_type = :"in_#{ENV.fetch('WORKER_TYPE')}" Parallel.public_send(method, 1..100, in_worker_type => 4) do sleep 0.1 # so all workers get started diff --git a/spec/parallel_spec.rb b/spec/parallel_spec.rb index e445898..39e2598 100644 --- a/spec/parallel_spec.rb +++ b/spec/parallel_spec.rb @@ -144,7 +144,7 @@ def cpus kill_process_with_name("spec/cases/parallel_fast_exit.rb") # simulates Ctrl+c sleep 1 result = t.value - result.scan(/I finished/).size.should == 3 + result.scan("I finished").size.should == 3 result.should_not include("Parallel execution interrupted") end.should <= 4 end @@ -334,7 +334,7 @@ def cpus it "sets Parallel.worker_number with 0 #{type}" do skip if type == "ractors" # not supported - type_key = "in_#{type}".to_sym + type_key = :"in_#{type}" result = Parallel.map([1, 2, 3, 4, 5, 6, 7, 8, 9], type_key => 0) { |_x| Parallel.worker_number } result.uniq.should == [0] Parallel.worker_number.should be_nil @@ -343,7 +343,7 @@ def cpus it "can run with 0 by not using #{type}" do Thread.should_not_receive(:exclusive) Process.should_not_receive(:fork) - result = Parallel.map([1, 2, 3, 4, 5, 6, 7, 8, 9], "in_#{type}".to_sym => 0) { |x| x + 2 } + result = Parallel.map([1, 2, 3, 4, 5, 6, 7, 8, 9], "in_#{type}": 0) { |x| x + 2 } result.should == [3, 4, 5, 6, 7, 8, 9, 10, 11] end