Skip to content

Commit d4b7007

Browse files
ruromeroclaude
andcommitted
fix(pip): clean up .egg-info directories created by pip --dry-run
pip creates .egg-info as a side effect of --dry-run --report. Snapshot existing .egg-info dirs before invoking pip and remove only newly created ones afterward to avoid polluting the user's project. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 08f7bd1 commit d4b7007

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

src/providers/python_pip_pyproject.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import fs from 'node:fs'
2+
import path from 'node:path'
3+
14
import { environmentVariableIsPopulated, getCustomPath, invokeCommand } from '../tools.js'
25

36
import Base_pyproject from './base_pyproject.js'
@@ -46,9 +49,12 @@ export default class Python_pip_pyproject extends Base_pyproject {
4649
} catch {
4750
pipBin = getCustomPath('pip', opts)
4851
}
49-
return invokeCommand(pipBin, [
52+
let eggInfoDirs = this._findEggInfoDirs(manifestDir)
53+
let result = invokeCommand(pipBin, [
5054
'install', '--dry-run', '--ignore-installed', '--quiet', '--report', '-', '.'
5155
], { cwd: manifestDir }).toString()
56+
this._cleanupEggInfo(manifestDir, eggInfoDirs)
57+
return result
5258
}
5359

5460
/**
@@ -131,4 +137,20 @@ export default class Python_pip_pyproject extends Base_pyproject {
131137
let reportOutput = this._getPipReportOutput(manifestDir, opts)
132138
return this._parsePipReport(reportOutput)
133139
}
140+
141+
_findEggInfoDirs(dir) {
142+
try {
143+
return fs.readdirSync(dir).filter(f => f.endsWith('.egg-info'))
144+
} catch {
145+
return []
146+
}
147+
}
148+
149+
_cleanupEggInfo(dir, existing) {
150+
for (let entry of this._findEggInfoDirs(dir)) {
151+
if (!existing.includes(entry)) {
152+
fs.rmSync(path.join(dir, entry), { recursive: true, force: true })
153+
}
154+
}
155+
}
134156
}

0 commit comments

Comments
 (0)