Skip to content

Commit

Permalink
feat(pip-compile): Treat included paths as relative to the package fi…
Browse files Browse the repository at this point in the history
…le (#29499)
  • Loading branch information
mbudnek authored Jun 7, 2024
1 parent 3741d2a commit 2a08238
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
56 changes: 56 additions & 0 deletions lib/modules/manager/pip-compile/extract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -602,4 +602,60 @@ describe('modules/manager/pip-compile/extract', () => {
['dash_r.txt'],
]);
});

it('handles -r dependency on file with relative path same dir', async () => {
fs.readLocalFile.mockImplementation((name): any => {
if (name === 'dir/1.in') {
return 'foo';
} else if (name === 'dir/2.in') {
return '-r 1.in\nbar';
} else if (name === 'dir/1.txt') {
return getSimpleRequirementsFile(
'pip-compile --output-file=1.txt 1.in',
['foo==1.0.1'],
);
} else if (name === 'dir/2.txt') {
return getSimpleRequirementsFile(
'pip-compile --output-file=2.txt 2.in',
['foo==1.0.1', 'bar==2.0.0'],
);
}
return null;
});

const lockFiles = ['dir/1.txt', 'dir/2.txt'];
const packageFiles = await extractAllPackageFiles({}, lockFiles);
expect(packageFiles).toMatchObject([
{ packageFile: 'dir/1.in', lockFiles: ['dir/1.txt', 'dir/2.txt'] },
{ packageFile: 'dir/2.in', lockFiles: ['dir/2.txt'] },
]);
});

it('handles -r dependency on file with relative path above', async () => {
fs.readLocalFile.mockImplementation((name): any => {
if (name === 'common/1.in') {
return 'foo';
} else if (name === 'dir/2.in') {
return '-r ../common/1.in\nbar';
} else if (name === 'common/1.txt') {
return getSimpleRequirementsFile(
'pip-compile --output-file=1.txt 1.in',
['foo==1.0.1'],
);
} else if (name === 'dir/2.txt') {
return getSimpleRequirementsFile(
'pip-compile --output-file=2.txt 2.in',
['foo==1.0.1', 'bar==2.0.0'],
);
}
return null;
});

const lockFiles = ['common/1.txt', 'dir/2.txt'];
const packageFiles = await extractAllPackageFiles({}, lockFiles);
expect(packageFiles).toMatchObject([
{ packageFile: 'common/1.in', lockFiles: ['common/1.txt', 'dir/2.txt'] },
{ packageFile: 'dir/2.in', lockFiles: ['dir/2.txt'] },
]);
});
});
8 changes: 8 additions & 0 deletions lib/modules/manager/pip-compile/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ export async function extractAllPackageFiles(
);
if (packageFileContent) {
if (packageFileContent.managerData?.requirementsFiles) {
packageFileContent.managerData.requirementsFiles =
packageFileContent.managerData.requirementsFiles.map(
(file: string) => upath.normalize(upath.join(compileDir, file)),
);
for (const file of packageFileContent.managerData.requirementsFiles) {
depsBetweenFiles.push({
sourceFile: file,
Expand All @@ -147,6 +151,10 @@ export async function extractAllPackageFiles(
}
}
if (packageFileContent.managerData?.constraintsFiles) {
packageFileContent.managerData.constraintsFiles =
packageFileContent.managerData.constraintsFiles.map(
(file: string) => upath.normalize(upath.join(compileDir, file)),
);
for (const file of packageFileContent.managerData.constraintsFiles) {
depsBetweenFiles.push({
sourceFile: file,
Expand Down

0 comments on commit 2a08238

Please sign in to comment.