Repository navigation
fix(python): select venv python.exe on Windows for python3 sources - #692
Conversation
On Windows the venv created from a `python3` source interpreter still installs Scripts\python.exe and Scripts\pip.exe, but prepareEnvironment() derived the venv executable names from the source interpreter name and selected the nonexistent Scripts\python3.exe. The pip upgrade then failed with an unrecognized-command error and Python analysis produced no report. Select the venv executable names by platform instead: Windows always uses python.exe/pip.exe, while POSIX keeps python3/pip3 for a python3 source and python/pip otherwise. The duplicated per-branch drive-letter handling is folded into a single path that still reuses #decideIfWindowsOrLinuxPath. Adds a failing-first esmock reproducer covering Windows with python3 and python sources plus a POSIX python3/pip3 regression case. Implements TC-7486 Signed-off-by: Adva Oren <aoren@redhat.com> Assisted-by: Claude Code
Reviewer's GuideImplementationSelect the venv’s standard Python and pip executable names by platform, independent of the source interpreter name, while retaining Windows drive-letter path handling.
TestsAdd mocked coverage for Windows and POSIX venv executable selection across python and python3 sources, including exact paths anchored to the created venv.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="test/providers/python_controller.test.js" line_range="142-143" />
<code_context>
+ // Then the pip upgrade runs through the venv Scripts/python.exe
+ expect(pipUpgradeInvocation.args).to.deep.equal(['-m', 'pip', 'install', '--upgrade', 'pip'])
+ expect(pipUpgradeInvocation.bin).to.equal(controller.pathToPythonBin)
+ expect(pathComponents(pipUpgradeInvocation.bin)).to.include('Scripts')
+ expect(path.basename(pipUpgradeInvocation.bin)).to.equal('python.exe')
+
+ // Then the venv pip path ends in Scripts/pip.exe
</code_context>
<issue_to_address>
**Wrong venv directory goes unnoticed**
When the executable paths point to a different directory that still contains `Scripts`, the Windows test accepts any path containing a `Scripts` component and the expected basename, so a path such as `/tmp/wrong/Scripts/python.exe` (and likewise for pip) passes without pointing into the venv it created.
Assert each executable path equals the expected path built from `controller.pythonEnvDir`, the platform-specific venv subdirectory, and the executable name.
Also at `test/providers/python_controller.test.js:146-147`.
</issue_to_address>Sourcery assessment
Approval pending. 1 finding to address first.
Blocking findings: test/providers/python_controller.test.js:143
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #692 +/- ##
==========================================
+ Coverage 91.49% 91.60% +0.10%
==========================================
Files 44 44
Lines 11642 11638 -4
Branches 2347 2346 -1
==========================================
+ Hits 10652 10661 +9
+ Misses 990 977 -13
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
[sdlc-workflow/verify-pr] Re: @sourcery-ai[bot] review — Classified as code change request — exact expected interpreter and pip paths should be anchored to the created venv directory, not only a Scripts component and executable basename. Sub-task TC-7502 created for this finding and duplicate inline comment 4524563687; no duplicate task created. Review item: review-body-5841416362. |
Verification Report for TC-7486 (commit eb7eb92)PR: #692
Overall: FAILThe failure is the required local Review feedback
Verification evidence
Local failures: 10 missing-Poetry cases ( CI test run 42811649429 matches the verified HEAD and passes both Node jobs. Its runner is Ubuntu, not Windows. Preventive follow-upTC-7504 adds a test-oracle sufficiency method and eval coverage to bug-fix task generation. The original task explicitly prescribed basename/component checks, and the implementation followed that guidance. The earliest observable limitation is therefore test specification, not proven implementation noncompliance. There is no Feature/incorporates lineage, and available artifacts do not establish which skill or person authored the guidance. Root-cause and test-quality/classification rows are informational and excluded from the Overall verdict. The overall FAIL comes from Verification Commands; Review Feedback and indirect Windows acceptance verification are WARN. No code was modified, no PR was merged, and no Jira status was transitioned. This comment was AI-generated by sdlc-workflow/verify-pr v0.13.10. |
Anchor the Windows pip-upgrade interpreter, pathToPythonBin, and pathToPipBin expectations to the venv directory recorded on the -m venv invocation instead of accepting any Scripts component with the expected basename. Add a negative case proving a same-basename executable from a different venv is rejected, and tighten POSIX expectations the same way. Implements TC-7502 Signed-off-by: Adva Oren <aoren@redhat.com> Assisted-by: Claude Code
Strum355
left a comment
There was a problem hiding this comment.
Some changes to make, as always, double check my logic on your end before making changes 😄
venv always installs the unversioned python and pip names, so the
includes("python3") heuristic only added a branch without changing
behavior. Use python/pip on both platforms and keep only the platform
directory and .exe handling. Update the POSIX regression cases to cover
both python3 and python sources.
Implements TC-7486
Signed-off-by: Adva Oren <aoren@redhat.com>
Assisted-by: Claude Code
The removed test asserted inequality against a directory production can never produce, so it could not fail for any plausible regression. The exact-path equality assertions in the Windows cases already reject a same-basename executable from another venv. Drop the test and its now-unused pathComponents helper. Implements TC-7502 Signed-off-by: Adva Oren <aoren@redhat.com> Assisted-by: Claude Code
Signed-off-by: Adva Oren <aoren@redhat.com>
Summary
Fixes Python virtual-environment analysis on Windows (blocked TC-7485). With
TRUSTIFY_DA_PYTHON_VIRTUAL_ENV=trueand a source interpreter namedpython3, venv creation succeeded but the pip upgrade targeted the nonexistentScripts\python3.exe, so analysis failed with an unrecognized-command error and no report was produced.src/providers/python_controller.js—prepareEnvironment()now selects the venv executables by platform instead of deriving them from the source interpreter name: Windows always usesScripts\python.exe/Scripts\pip.exe, and POSIX usesbin/python/bin/pip; both are independent of how the source interpreter is named. The two duplicated branches (each with its own drive-letter handling) collapse into one path that still reuses#decideIfWindowsOrLinuxPath.test/providers/python_controller.test.js— newesmock-based suite that stubsos.platform()andinvokeCommandto capture venv creation and pip-upgrade invocations: Windows with apython3source (the reproducer), Windows with apythonsource, and POSIXpython3andpythonregression cases assertingbin/python/bin/pip.test/providers/python_controller.test.js— tightened the Windows cases to require the exact venv-anchoredScripts\python.exeandScripts\pip.exepaths; the exact-path equality already rejects a same-basename executable from a different venv. The POSIX cases now pinbin/python/bin/piptoo (TC-7502).Root cause
venvinstallspython.exe/pip.exeon Windows no matter how the source interpreter is named. Before this change,prepareEnvironment()keyed the executable names offpathToPythonBin.includes("python3"), and#decideIfWindowsOrLinuxPath()only appended.exe, never normalizingpython3topython. The source-name heuristic is now removed: standardpython/pipnames are used inside the venv on both platforms.Testing
Scripts\python3.exe(expected 'python3.exe' to equal 'python.exe'); after the fix it observesScripts\python.exeandScripts\pip.exe, with no invocation targetingpython3.exe/pip3.exe.npm run tests -- --grep "Python_controller"— 7 passing.npm run lint— 0 errors (16 pre-existing warnings in untouched files).npm test— 1037 passing / 15 failing. The 15 failures are the known environment-dependent baseline and all reproduce on pristinemainin this environment: 2python-pipcases broken by a stale local~/.local/bin/pipdeptree(ModuleNotFoundError: No module named 'pipdeptree._runner', reproducible outside the repo), 10python-pyproject/poetry cases, and 3 OCI registry lookups.Notes
Implements TC-7486
Summary by Sourcery
Fix virtual-environment analysis by selecting executable names from the platform-specific venv layout instead of the source interpreter name.
Bug Fixes:
pythonandpipexecutables inside virtual environments regardless of the source interpreter name, fixing Windows analysis forpython3sources.Enhancements:
Tests:
pythonandpython3source interpreters.