Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bump ruby requirements + rubocop #343

Merged
merged 4 commits into from
Mar 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 1 addition & 10 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -65,9 +59,6 @@ Style/SymbolArray:
Style/GuardClause:
Enabled: false

Lint/AssignmentInCondition:
Enabled: false

Style/EmptyElse:
Enabled: false

Expand Down
34 changes: 21 additions & 13 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
22 changes: 11 additions & 11 deletions lib/parallel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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'

Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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]
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion parallel.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion spec/cases/each_with_ar_sqlite.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/cases/finish_in_order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions spec/cases/profile_memory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 :(

Expand Down
2 changes: 1 addition & 1 deletion spec/cases/with_break.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/cases/with_break_before_finish.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/cases/with_exception.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/cases/with_exception_before_finish.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/cases/with_exception_in_finish.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/cases/with_exception_in_start.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/cases/with_exception_in_start_before_finish.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/cases/with_worker_number.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions spec/parallel_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down
Loading