Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(pypi): support additional file name extensions #29839

Merged
merged 2 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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