fix: Handle Python projects without pyproject.toml in a365 deploy#253
Conversation
…irementsTxt When deploying Python projects that have only requirements.txt (no pyproject.toml or setup.py), the -e . approach fails because pip cannot find a package to install. This fix detects the project structure: - If pyproject.toml or setup.py exists: Use -e . (editable install) - If only requirements.txt exists: Copy the existing file as-is - If neither exists: Create a minimal placeholder with a warning Fixes microsoft#252
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug where a365 deploy incorrectly overwrites requirements.txt with an editable install directive (-e .) for Python projects that lack pyproject.toml or setup.py, causing Azure Oryx deployment failures. The fix adds project structure detection to choose the appropriate requirements.txt generation strategy.
Changes:
- Modified
CreateAzureRequirementsTxt()to detect project structure (pyproject.toml/setup.py presence) - For projects with pyproject.toml/setup.py: uses editable install approach (existing behavior)
- For projects with only requirements.txt: copies the existing file to preserve dependencies (new behavior)
- For projects with no requirements file: creates a minimal placeholder (fallback)
src/Microsoft.Agents.A365.DevTools.Cli/Services/PythonBuilder.cs
Outdated
Show resolved
Hide resolved
This addresses all review feedback from the PR review: **Fixes (PythonBuilder.cs):** - Added try-catch for File.Copy with specific exception handling: - FileNotFoundException with helpful error message - UnauthorizedAccessException for permission issues - IOException for file-in-use or disk full scenarios - Added warning when both pyproject.toml and requirements.txt exist to clarify precedence and avoid confusion **Tests (PythonBuilderTests.cs):** - Created 5 comprehensive test scenarios covering all code paths: 1. With pyproject.toml → creates editable install 2. With setup.py → creates editable install 3. With only requirements.txt → preserves original dependencies 4. With both pyproject.toml and requirements.txt → prefers pyproject.toml 5. With no package files → creates minimal placeholder - Proper test cleanup with IDisposable pattern - Mocked Python environment for isolated testing - All tests pass ✅ This resolves the BLOCKING issue (missing tests), HIGH priority issue (error handling), and MEDIUM priority issue (edge case warning) from the code review. Many thanks to @pratapladhani for identifying this bug and providing the initial fix! Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
|
Thank you @pratapladhani for identifying issue #252 and providing the fix! You correctly identified that a365 deploy was overwriting requirements.txt for Python projects without pyproject.toml. I've added some enhancements to your PR: ✅ Error handling - Added try-catch for File.Copy operations Thanks again for the great contribution! |
Summary
Fixes #252 -
a365 deployoverwritesrequirements.txtfor Python projects withoutpyproject.tomlProblem
When deploying Python projects that have only
requirements.txt(nopyproject.tomlorsetup.py), the CLI overwrites the requirements file with-e ., which fails because pip cannot find a package to install.Error from Azure Oryx:
Solution
Modified
CreateAzureRequirementsTxt()inPythonBuilder.csto detect the project structure:pyproject.tomlorsetup.pyexists: Use the existing-e .(editable install) approachrequirements.txtexists: Copy the existing file as-is to preserve dependenciesChanges
PythonBuilder.cs: UpdatedCreateAzureRequirementsTxt()method with project structure detectionprojectDirparameter to access source requirements.txtTesting
dotnet build -c Release)Compatibility
This is a backward-compatible fix:
pyproject.tomlorsetup.pycontinue to work as beforerequirements.txtnow work correctly