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

Drop win32ole #346

Merged
merged 4 commits into from
Jun 8, 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,14 +12,14 @@ jobs:
image: mysql
strategy:
matrix:
ruby: [ '2.7', '3.0', '3.1', '3.2' ]
ruby: [ '2.7', '3.0', '3.1', '3.2', '3.3' ]
task: [ 'spec' ]
include:
- ruby: 2.7 # keep in sync with lowest version
task: rubocop
name: ${{ matrix.ruby }} rake ${{ matrix.task }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ gem 'rubocop-rake'
gem 'rubocop-rspec'

gem 'mysql2', group: :mysql
gem 'sqlite3'
gem 'sqlite3', '~> 1.4'
6 changes: 4 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ GEM
json (2.7.1)
json (2.7.1-java)
language_server-protocol (3.17.0.3)
mini_portile2 (2.8.7)
minitest (5.15.0)
mysql2 (0.5.6)
parser (3.3.0.5)
Expand Down Expand Up @@ -72,7 +73,8 @@ GEM
rubocop-rspec (2.9.0)
rubocop (~> 1.19)
ruby-progressbar (1.13.0)
sqlite3 (1.4.2)
sqlite3 (1.7.3)
mini_portile2 (~> 2.8.0)
tzinfo (2.0.4)
concurrent-ruby (~> 1.0)
unicode-display_width (2.5.0)
Expand All @@ -95,7 +97,7 @@ DEPENDENCIES
rubocop-rake
rubocop-rspec
ruby-progressbar
sqlite3
sqlite3 (~> 1.4)

BUNDLED WITH
2.3.12
33 changes: 28 additions & 5 deletions lib/parallel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -328,11 +328,7 @@ def physical_processor_count
end
cores.count
when /mswin|mingw/
require 'win32ole'
result_set = WIN32OLE.connect("winmgmts://").ExecQuery(
"select NumberOfCores from Win32_Processor"
)
result_set.to_enum.collect(&:NumberOfCores).reduce(:+)
physical_processor_count_windows
else
processor_count
end
Expand All @@ -358,6 +354,33 @@ def worker_number=(worker_num)

private

def physical_processor_count_windows
# Get-CimInstance introduced in PowerShell 3 or earlier: https://learn.microsoft.com/en-us/previous-versions/powershell/module/cimcmdlets/get-ciminstance?view=powershell-3.0
result = run(
'powershell -command "Get-CimInstance -ClassName Win32_Processor ' \
'| Select-Object -Property NumberOfCores"'
)
if !result || $?.exitstatus != 0
# fallback to deprecated wmic for older systems
result = run("wmic cpu get NumberOfCores")
end
if !result || $?.exitstatus != 0
# Bail out if both commands returned something unexpected
warn "guessing pyhsical processor count"
processor_count
else
# powershell: "\nNumberOfCores\n-------------\n 4\n\n\n"
# wmic: "NumberOfCores \n\n4 \n\n\n\n"
result.scan(/\d+/).map(&:to_i).reduce(:+)
end
end

def run(command)
IO.popen(command, &:read)
rescue Errno::ENOENT
# Ignore
end

def add_progress_bar!(job_factory, options)
if (progress_options = options[:progress])
raise "Progressbar can only be used with array like items" if job_factory.size == Float::INFINITY
Expand Down
2 changes: 1 addition & 1 deletion spec/parallel_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ def cpus
def normalize(result)
result = result.sub(/\{(.*)\}/, "\\1").split(", ")
result.reject! { |x| x =~ /^(Hash|Array|String)=>(1|-1|-2)$/ }
result.reject! { |x| x =~ /^(Mutex)=>(1)$/ } if RUBY_VERSION < "2.0"
result.reject! { |x| x =~ /^(Thread::Mutex)=>(1)$/ } if RUBY_VERSION >= "3.3"
result
end

Expand Down