Skip to content

Commit

Permalink
language/python: syntax and style cleanup
Browse files Browse the repository at this point in the history
Co-authored-by: Kevin <[email protected]>
Co-authored-by: Mike McQuaid <[email protected]>
  • Loading branch information
3 people committed Apr 13, 2024
1 parent 8e02017 commit 54f3367
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
11 changes: 5 additions & 6 deletions Library/Homebrew/language/python.rb
Expand Up @@ -232,11 +232,11 @@ def virtualenv_install_with_resources(using: nil, system_site_packages: true, wi
python = "python3" if python == "python"
end

venv_resources = if without.blank? && start_with.blank? && end_with.blank?
venv_resources = if without.nil? && start_with.nil? && end_with.nil?
resources
else
remaining_resources = resources.to_h { |resource| [resource.name, resource] }
unless (unknown_resource = Array(without).find { |r| remaining_resources.delete(r).nil? }).nil?
if (unknown_resource = Array(without).find { |r| remaining_resources.delete(r).nil? })
raise ArgumentError, "#{__method__} `without` includes unknown resource \"#{unknown_resource}\""
end

Expand All @@ -246,10 +246,9 @@ def virtualenv_install_with_resources(using: nil, system_site_packages: true, wi
raise ArgumentError, "#{__method__} `start_with` includes unknown resource \"#{start_with[index]}\""
end

end_with = Array(end_with)
end_with_resources = end_with.map { |r| remaining_resources.delete(r) }
unless (index = end_with_resources.find_index(nil)).nil?
raise ArgumentError, "#{__method__} `end_with` includes unknown resource \"#{end_with[index]}\""
end_with_resources = Array(end_with).map do |r|
remaining_resources.delete(r) ||
raise(ArgumentError, "#{__method__} `end_with` includes unknown resource \"#{r}\"")
end

start_with_resources + remaining_resources.values + end_with_resources
Expand Down
5 changes: 4 additions & 1 deletion Library/Homebrew/test/language/python/virtualenv_spec.rb
Expand Up @@ -8,7 +8,10 @@
let(:venv) { instance_double(Language::Python::Virtualenv::Virtualenv) }
let(:f) do
formula "foo" do
include Language::Python::Virtualenv # rubocop:disable RSpec/DescribedClass
# Couldn't find a way to get described_class to work inside formula do
# rubocop:disable RSpec/DescribedClass
include Language::Python::Virtualenv
# rubocop:enable RSpec/DescribedClass

url "https://brew.sh/foo-1.0.tgz"

Expand Down

0 comments on commit 54f3367

Please sign in to comment.