From 2ecf403609934bd38711c47c7c118affa32f7016 Mon Sep 17 00:00:00 2001 From: "Kirill A. Korinsky" Date: Fri, 6 Feb 2026 18:18:30 +0100 Subject: [PATCH] Treat -, _ and . in distfile as equivalent for PyPi. Why? To catch cases with PKGNAME= ${DISTNAME:S/_/-/} --- Portroach/SiteHandler/PyPI.pm | 39 +++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/Portroach/SiteHandler/PyPI.pm b/Portroach/SiteHandler/PyPI.pm index 81898f1..9f26078 100644 --- a/Portroach/SiteHandler/PyPI.pm +++ b/Portroach/SiteHandler/PyPI.pm @@ -116,6 +116,45 @@ sub GetFiles foreach my $url (@$urls) { push(@$files, $url->{filename}); } + + if ($port->{ver} && $json->{releases} && $json->{releases}->{$port->{ver}}) { + my @distfiles = split ' ', ($port->{distfiles} || ''); + my %seen = map { $_ => 1 } @distfiles; + + foreach my $rel (@{$json->{releases}->{$port->{ver}}}) { + next unless ($rel->{packagetype} && $rel->{packagetype} eq 'sdist'); + next unless ($rel->{filename}); + next if ($seen{$rel->{filename}}); + push @distfiles, $rel->{filename}; + $seen{$rel->{filename}} = 1; + } + + foreach my $distfile (@distfiles) { + next unless ($distfile =~ /^(.*?)\Q$port->{ver}\E(.*)$/); + my ($prefix, $suffix) = ($1, $2); + my ($name_prefix, $sep) = ($prefix, ''); + if ($prefix =~ /^(.*?)([-_\.])$/) { + ($name_prefix, $sep) = ($1, $2); + } + + my %alts; + foreach my $ch ('-', '_', '.') { + my $alt_prefix = $name_prefix; + $alt_prefix =~ s/[-_.]+/$ch/g; + $alts{$alt_prefix} = 1; + } + + foreach my $alt_prefix (keys %alts) { + my $alt = $alt_prefix . $sep . $port->{ver} . $suffix; + next if ($alt eq $distfile); + next if ($seen{$alt}); + push @distfiles, $alt; + $seen{$alt} = 1; + } + } + + $port->{distfiles} = join ' ', @distfiles if (@distfiles); + } } else { _debug("GET failed: " . $resp->code); return 0;