Merge pull request #9339 from Rylan12/fix-pypi-package-comparison

utils/pypi: make package name comparison case-insensitive
This commit is contained in:
Rylan Polster 2020-11-30 20:37:09 -05:00 committed by GitHub
commit 0164b66471
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions

View File

@ -22,6 +22,7 @@ describe PyPI do
let(:package_with_different_version) { described_class.new("snakemake==5.29.0") } let(:package_with_different_version) { described_class.new("snakemake==5.29.0") }
let(:package_with_extra) { described_class.new("snakemake[foo]") } let(:package_with_extra) { described_class.new("snakemake[foo]") }
let(:package_with_extra_and_version) { described_class.new("snakemake[foo]==5.28.0") } let(:package_with_extra_and_version) { described_class.new("snakemake[foo]==5.28.0") }
let(:package_with_different_capitalization) { described_class.new("SNAKEMAKE") }
let(:package_from_url) { described_class.new(package_url, is_url: true) } let(:package_from_url) { described_class.new(package_url, is_url: true) }
let(:other_package) { described_class.new("virtualenv==20.2.0") } let(:other_package) { described_class.new("virtualenv==20.2.0") }
@ -146,6 +147,10 @@ describe PyPI do
it "returns true for the same package with different versions" do it "returns true for the same package with different versions" do
expect(package_with_version.same_package?(package_with_different_version)).to eq true expect(package_with_version.same_package?(package_with_different_version)).to eq true
end end
it "returns true for the same package with different capitalization" do
expect(package.same_package?(package_with_different_capitalization)).to eq true
end
end end
describe "<=>" do describe "<=>" do

View File

@ -91,7 +91,7 @@ module PyPI
sig { params(other: Package).returns(T::Boolean) } sig { params(other: Package).returns(T::Boolean) }
def same_package?(other) def same_package?(other)
@name.tr("_", "-") == other.name.tr("_", "-") @name.tr("_", "-").casecmp(other.name.tr("_", "-")).zero?
end end
# Compare only names so we can use .include? on a Package array # Compare only names so we can use .include? on a Package array
@ -231,7 +231,7 @@ module PyPI
end end
# Remove extra packages that may be included in pipgrip output # Remove extra packages that may be included in pipgrip output
exclude_list = %W[#{main_package.name.downcase} argparse pip setuptools wheel wsgiref].map { |p| Package.new p } exclude_list = %W[#{main_package.name} argparse pip setuptools wheel wsgiref].map { |p| Package.new p }
found_packages.delete_if { |package| exclude_list.include? package } found_packages.delete_if { |package| exclude_list.include? package }
new_resource_blocks = "" new_resource_blocks = ""