Skip to content

Conversation

@pratapladhani
Copy link
Contributor

Summary

Fixes #252 - a365 deploy overwrites requirements.txt for Python projects without pyproject.toml

Problem

When deploying Python projects that have only requirements.txt (no pyproject.toml or setup.py), the CLI overwrites the requirements file with -e ., which fails because pip cannot find a package to install.

Error from Azure Oryx:

ERROR: file:///tmp/8de6a0cc7ececaa (from -r requirements.txt (line 3)) does not appear to be a Python project: neither 'setup.py' nor 'pyproject.toml' found.

Solution

Modified CreateAzureRequirementsTxt() in PythonBuilder.cs to detect the project structure:

  1. If pyproject.toml or setup.py exists: Use the existing -e . (editable install) approach
  2. If only requirements.txt exists: Copy the existing file as-is to preserve dependencies
  3. If neither exists: Create a minimal placeholder with a warning log

Changes

  • PythonBuilder.cs: Updated CreateAzureRequirementsTxt() method with project structure detection
  • Added projectDir parameter to access source requirements.txt
  • Improved logging to indicate which approach is being used

Testing

  • Build passes (dotnet build -c Release)
  • All tests pass (945 passed, 0 failed)
  • Manual test with Python project without pyproject.toml (was failing, now works)

Compatibility

This is a backward-compatible fix:

  • Projects with pyproject.toml or setup.py continue to work as before
  • Projects with only requirements.txt now work correctly

…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
@pratapladhani pratapladhani requested a review from a team as a code owner February 12, 2026 08:13
Copilot AI review requested due to automatic review settings February 12, 2026 08:13
@pratapladhani pratapladhani requested a review from a team as a code owner February 12, 2026 08:13
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

pratapladhani and others added 2 commits February 12, 2026 00:30
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>
Copilot AI review requested due to automatic review settings February 12, 2026 22:29
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

@sellakumaran
Copy link
Contributor

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
✅ Edge case warning - Added warning when both pyproject.toml and requirements.txt exist
✅ Added tests - Created 5 test scenarios covering all code paths (all tests pass!)

Thanks again for the great contribution!

@sellakumaran sellakumaran enabled auto-merge (squash) February 12, 2026 22:44
@sellakumaran sellakumaran merged commit 9bf15c6 into microsoft:main Feb 12, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] a365 deploy overwrites requirements.txt for Python projects without pyproject.toml

3 participants