Skip to content

Commit

Permalink
fix(pypi): support additional file name extensions (#29839)
Browse files Browse the repository at this point in the history
Co-authored-by: Sebastian Poxhofer <secustor@users.noreply.github.com>
  • Loading branch information
rarkins and secustor committed Jun 25, 2024
1 parent 03f5c5c commit eaaeb47
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!DOCTYPE html>
<html><head><title>Simple Index</title><meta name="api-version" value="2" /></head><body>
<a href="../../company-aws-sso-client/0.11.7/company-aws-sso-client-0.11.7.zip#sha256=5247ab59a1318380a53ec439c54a2af121ad47dd6de70124f8cdc44aefe137ea" data-requires-python="&gt;=2.7" rel="internal">company-aws-sso-client-0.11.7.zip</a>
<a href="../../company-aws-sso-client/0.11.8/company-aws-sso-client-0.11.8.zip#sha256=4074d11346e47df832bbb5740e4061f1f5272852c462b5746f2c027364430a9b" data-requires-python="&gt;=2.7" rel="internal">company-aws-sso-client-0.11.8.zip</a>
</body></html>
20 changes: 20 additions & 0 deletions lib/modules/datasource/pypi/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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/')
Expand Down
15 changes: 12 additions & 3 deletions lib/modules/datasource/pypi/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit eaaeb47

Please sign in to comment.