Skip to content

Commit

Permalink
fix: pip-compile-multi alters .in file with full path
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch committed Nov 24, 2024
1 parent 5c282a4 commit e2d1139
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -435,8 +435,7 @@ class Github {
}

async fixReqsFile(filePath) {
// Somehow pip-compile-multi generates replaces the '-e file:.' with a hard-coded local path
// hoping they fix it in the future. In the meantime we can fix it here.
// Fixes '-e file:.' lines and strips absolute paths before 'requirements/' in '# -r' lines
try {
// Read the file
const content = await fs.promises.readFile(filePath, { encoding: 'utf-8' });
Expand All @@ -448,10 +447,18 @@ class Github {
needsUpdate = true;
return '-e file:.';
}
if (line.trim().startsWith('# -r ')) {
// Replace everything before 'requirements/' with '# -r requirements/'
const fixedLine = line.replace(/# -r .*?requirements\//, '# -r requirements/');
if (fixedLine !== line) {
needsUpdate = true;
return fixedLine;
}
}
return line;
});

// Join the lines back and write to the file
// Join the lines back and write to the file if any changes were made
if (needsUpdate) {
await fs.promises.writeFile(filePath, updatedLines.join('\n'), { encoding: 'utf-8' });
}
Expand Down

0 comments on commit e2d1139

Please sign in to comment.