From df70d37141826d27715cc573806dec788e14880b Mon Sep 17 00:00:00 2001
From: wwuck <301402+wwuck@users.noreply.github.com>
Date: Sat, 18 Jun 2022 16:15:10 +1000
Subject: [PATCH] fix(pypi): package name with periods (#15867)

---
 .../pypi/__fixtures__/versions-html-with-periods.html |  4 ++--
 lib/modules/datasource/pypi/index.ts                  | 11 +++++++++--
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/lib/modules/datasource/pypi/__fixtures__/versions-html-with-periods.html b/lib/modules/datasource/pypi/__fixtures__/versions-html-with-periods.html
index 846d72d71b..e91932715c 100644
--- a/lib/modules/datasource/pypi/__fixtures__/versions-html-with-periods.html
+++ b/lib/modules/datasource/pypi/__fixtures__/versions-html-with-periods.html
@@ -7,6 +7,6 @@
     <h1>Links for package.with.periods</h1>
     <a href="">package.with.periods-2.0.0.tar.gz</a><br>
     <a href="">package.with.periods-2.0.1-py3-none-any.whl</a><br>
-    <a href="">package.with.periods-2.0.2-py3-none-any.whl</a><br>
+    <a href="">package_with_periods-2.0.2-py3-none-any.whl</a><br>
     <a href="">package.with.periods-2.0.2.tar.gz</a><br>
-</body></html>
\ No newline at end of file
+</body></html>
diff --git a/lib/modules/datasource/pypi/index.ts b/lib/modules/datasource/pypi/index.ts
index 03511271f5..be28036a10 100644
--- a/lib/modules/datasource/pypi/index.ts
+++ b/lib/modules/datasource/pypi/index.ts
@@ -181,11 +181,18 @@ export class PypiDatasource extends Datasource {
 
     // pep-0427 wheel packages
     //  {distribution}-{version}(-{build tag})?-{python tag}-{abi tag}-{platform tag}.whl.
+    // Also match the current wheel spec
+    // https://packaging.python.org/en/latest/specifications/binary-distribution-format/#escaping-and-unicode
+    // where any of -_. characters in {distribution} are replaced with _
     const wheelText = text.toLowerCase();
-    const wheelPrefix = packageName.replace(regEx(/[^\w\d.]+/g), '_') + '-';
+    const wheelPrefixWithPeriod =
+      packageName.replace(regEx(/[^\w\d.]+/g), '_') + '-';
+    const wheelPrefixWithoutPeriod =
+      packageName.replace(regEx(/[^\w\d]+/g), '_') + '-';
     const wheelSuffix = '.whl';
     if (
-      wheelText.startsWith(wheelPrefix) &&
+      (wheelText.startsWith(wheelPrefixWithPeriod) ||
+        wheelText.startsWith(wheelPrefixWithoutPeriod)) &&
       wheelText.endsWith(wheelSuffix) &&
       wheelText.split('-').length > 2
     ) {
-- 
GitLab