From eaaeb47b599c3a935bb9bf0fd08015899008f3a0 Mon Sep 17 00:00:00 2001 From: Rhys Arkins Date: Tue, 25 Jun 2024 14:13:35 +0200 Subject: [PATCH] fix(pypi): support additional file name extensions (#29839) Co-authored-by: Sebastian Poxhofer --- .../pypi/__fixtures__/versions-archives.html | 5 +++++ lib/modules/datasource/pypi/index.spec.ts | 20 +++++++++++++++++++ lib/modules/datasource/pypi/index.ts | 15 +++++++++++--- 3 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 lib/modules/datasource/pypi/__fixtures__/versions-archives.html diff --git a/lib/modules/datasource/pypi/__fixtures__/versions-archives.html b/lib/modules/datasource/pypi/__fixtures__/versions-archives.html new file mode 100644 index 00000000000000..39cf1bdd9fda3e --- /dev/null +++ b/lib/modules/datasource/pypi/__fixtures__/versions-archives.html @@ -0,0 +1,5 @@ + +Simple Index +company-aws-sso-client-0.11.7.zip +company-aws-sso-client-0.11.8.zip + diff --git a/lib/modules/datasource/pypi/index.spec.ts b/lib/modules/datasource/pypi/index.spec.ts index c4cb541f252db5..22b9a07252bfa0 100644 --- a/lib/modules/datasource/pypi/index.spec.ts +++ b/lib/modules/datasource/pypi/index.spec.ts @@ -18,6 +18,7 @@ const withWhitespacesResponse = Fixtures.get( 'versions-html-with-whitespaces.html', ); const hyphensResponse = Fixtures.get('versions-html-hyphens.html'); +const zipResponse = Fixtures.get('versions-archives.html'); const baseUrl = 'https://pypi.org/pypi'; const datasource = PypiDatasource.id; @@ -355,6 +356,25 @@ describe('modules/datasource/pypi/index', () => { ]); }); + it('process data from simple endpoint with zip archives', async () => { + httpMock + .scope('https://some.registry.org/simple/') + .get('/company-aws-sso-client/') + .reply(200, zipResponse); + const config = { + registryUrls: ['https://some.registry.org/simple/'], + }; + const res = await getPkgReleases({ + datasource, + ...config, + packageName: 'company-aws-sso-client', + }); + expect(res?.releases).toMatchObject([ + { version: '0.11.7' }, + { version: '0.11.8' }, + ]); + }); + it('process data from simple endpoint with hyphens replaced with underscores', async () => { httpMock .scope('https://some.registry.org/simple/') diff --git a/lib/modules/datasource/pypi/index.ts b/lib/modules/datasource/pypi/index.ts index 477525bdd48fa5..532de67f592e2b 100644 --- a/lib/modules/datasource/pypi/index.ts +++ b/lib/modules/datasource/pypi/index.ts @@ -182,9 +182,18 @@ export class PypiDatasource extends Datasource { // source packages const srcText = PypiDatasource.normalizeName(text); const srcPrefix = `${packageName}-`; - const srcSuffix = '.tar.gz'; - if (srcText.startsWith(srcPrefix) && srcText.endsWith(srcSuffix)) { - return srcText.replace(srcPrefix, '').replace(regEx(/\.tar\.gz$/), ''); + const srcSuffixes = ['.tar.gz', '.tar.bz2', '.tar.xz', '.zip']; + if ( + srcText.startsWith(srcPrefix) && + srcSuffixes.some((srcSuffix) => srcText.endsWith(srcSuffix)) + ) { + const res = srcText.replace(srcPrefix, ''); + for (const suffix of srcSuffixes) { + if (res.endsWith(suffix)) { + // strip off the suffix using character length + return res.slice(0, -suffix.length); + } + } } // pep-0427 wheel packages