Skip to content

Commit

Permalink
feat(manager/pipenv): discard extras from dependency name (#27803)
Browse files Browse the repository at this point in the history
  • Loading branch information
RahulGautamSingh committed Mar 8, 2024
1 parent 049c59c commit 0497dbd
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
2 changes: 2 additions & 0 deletions lib/modules/manager/pipenv/__fixtures__/Pipfile1
Expand Up @@ -10,6 +10,8 @@ name = "private-pypi"

[packages]
some-package = "==0.3.1"
"splinter[django]" = "==3.43.1"
"requests[django][security][something]" = "==1.1.1"
some-other-package = "==1.0.0"
"_invalid-package" = "==1.0.0"
invalid-version = "==0 0"
Expand Down
16 changes: 15 additions & 1 deletion lib/modules/manager/pipenv/extract.spec.ts
Expand Up @@ -33,6 +33,20 @@ describe('modules/manager/pipenv/extract', () => {
currentVersion: '0.3.1',
datasource: 'pypi',
},
{
depType: 'packages',
depName: 'splinter',
currentValue: '==3.43.1',
currentVersion: '3.43.1',
datasource: 'pypi',
},
{
depType: 'packages',
depName: 'requests',
currentValue: '==1.1.1',
currentVersion: '1.1.1',
datasource: 'pypi',
},
{
depType: 'packages',
depName: 'some-other-package',
Expand Down Expand Up @@ -80,7 +94,7 @@ describe('modules/manager/pipenv/extract', () => {
],
});

expect(res?.deps.filter((dep) => !dep.skipReason)).toHaveLength(4);
expect(res?.deps.filter((dep) => !dep.skipReason)).toHaveLength(6);
});

it('marks packages with "extras" as skipReason === unspecified-version', async () => {
Expand Down
17 changes: 12 additions & 5 deletions lib/modules/manager/pipenv/extract.ts
Expand Up @@ -10,7 +10,10 @@ import type { PackageDependency, PackageFileContent } from '../types';
import type { PipFile } from './types';

// based on https://www.python.org/dev/peps/pep-0508/#names
const packageRegex = regEx(/^([A-Z0-9]|[A-Z0-9][A-Z0-9._-]*[A-Z0-9])$/i);
export const packagePattern = '[A-Z0-9]|[A-Z0-9][A-Z0-9._-]*[A-Z0-9]';
export const extrasPattern = '(?:\\s*\\[[^\\]]+\\])*';
const packageRegex = regEx(`^(${packagePattern})(${extrasPattern})$`, 'i');

const rangePattern: string = RANGE_PATTERN;

const specifierPartPattern = `\\s*${rangePattern.replace(
Expand All @@ -30,7 +33,9 @@ function extractFromSection(

const deps = Object.entries(pipfileSection)
.map((x) => {
const [depName, requirements] = x;
const [packageNameString, requirements] = x;
let depName = packageNameString;

let currentValue: string | undefined;
let nestedVersion = false;
let skipReason: SkipReason | undefined;
Expand All @@ -52,10 +57,12 @@ function extractFromSection(
skipReason = 'unspecified-version';
}
if (!skipReason) {
const packageMatches = packageRegex.exec(depName);
if (!packageMatches) {
const packageMatches = packageRegex.exec(packageNameString);
if (packageMatches) {
depName = packageMatches[1];
} else {
logger.debug(
`Skipping dependency with malformed package name "${depName}".`,
`Skipping dependency with malformed package name "${packageNameString}".`,
);
skipReason = 'invalid-name';
}
Expand Down

0 comments on commit 0497dbd

Please sign in to comment.