Skip to content

Commit c85a0fa

Browse files
committed
Revert "Add automatic remote build detection for Python apps in func pack command (#4530)"
This reverts commit b791c6e.
1 parent 37e031e commit c85a0fa

File tree

7 files changed

+46
-200
lines changed

7 files changed

+46
-200
lines changed

release_notes.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,4 @@
1010
- Fix dotnet templates installation (#4538)
1111
- Disable diagnostic events in local development by replacing the `IDiagnosticEventRepository` with a `DiagnosticEventNullRepository` (#4542)
1212
- Add `func pack` support for in-proc functions (#4529)
13-
- Default to remote build for `func pack` for python apps (#4530)
1413
- Update `func init` to default to the .NET 8 template for in-proc apps (#4557)

src/Cli/func/Actions/AzureActions/PublishFunctionAppAction.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ public override async Task RunAsync()
214214
var additionalAppSettings = await ValidateFunctionAppPublish(functionApp, workerRuntime, functionAppRoot);
215215

216216
// Update build option
217-
PublishBuildOption = ResolveBuildOptionHelper.ResolveBuildOption(PublishBuildOption, workerRuntime, functionApp, BuildNativeDeps, NoBuild);
217+
PublishBuildOption = PublishHelper.ResolveBuildOption(PublishBuildOption, workerRuntime, functionApp, BuildNativeDeps, NoBuild);
218218

219219
bool isNonCsxDotnetRuntime = WorkerRuntimeLanguageHelper.IsDotnet(workerRuntime) && !Csx;
220220

src/Cli/func/Actions/LocalActions/PackAction.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

44
using Azure.Functions.Cli.Common;
@@ -88,10 +88,6 @@ public override async Task RunAsync()
8888
}
8989

9090
var workerRuntime = WorkerRuntimeLanguageHelper.GetCurrentWorkerRuntimeLanguage(_secretsManager);
91-
92-
// Resolve build option to detect if remote build is needed (e.g., Python app on Windows)
93-
var buildOption = ResolveBuildOptionHelper.ResolveBuildOption(BuildOption.Default, workerRuntime, site: null, BuildNativeDeps, noBuild: false);
94-
9591
outputPath += Squashfs ? ".squashfs" : ".zip";
9692
if (FileSystemHelpers.FileExists(outputPath))
9793
{
@@ -113,7 +109,7 @@ public override async Task RunAsync()
113109
bool useGoZip = EnvironmentHelper.GetEnvironmentVariableAsBool(Constants.UseGoZip);
114110
TelemetryHelpers.AddCommandEventToDictionary(TelemetryCommandEvents, "UseGoZip", useGoZip.ToString());
115111

116-
var stream = await ZipHelper.GetAppZipFile(functionAppRoot, BuildNativeDeps, noBuild: false, buildOption: buildOption, additionalPackages: AdditionalPackages);
112+
var stream = await ZipHelper.GetAppZipFile(functionAppRoot, BuildNativeDeps, BuildOption.Default, noBuild: false, additionalPackages: AdditionalPackages);
117113

118114
if (Squashfs)
119115
{

src/Cli/func/Helpers/PublishHelper.cs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

44
using System.Net.Http.Handlers;
5+
using Azure.Functions.Cli.Arm.Models;
56
using Azure.Functions.Cli.Common;
67

78
namespace Azure.Functions.Cli.Helpers
@@ -25,6 +26,33 @@ public static GitIgnoreParser GetIgnoreParser(string workingDir)
2526
return null;
2627
}
2728

29+
public static BuildOption ResolveBuildOption(BuildOption currentBuildOption, WorkerRuntime runtime, Site site, bool buildNativeDeps, bool noBuild)
30+
{
31+
// --no-build and --build-native-deps will take precedence over --build local and --build remote
32+
if (noBuild)
33+
{
34+
return BuildOption.None;
35+
}
36+
37+
if (buildNativeDeps)
38+
{
39+
return BuildOption.Container;
40+
}
41+
42+
if (currentBuildOption == BuildOption.Default)
43+
{
44+
// Change to remote build if, python app, has requirements.txt, requirements.txt has content
45+
if (runtime == WorkerRuntime.Python &&
46+
FileSystemHelpers.FileExists(Constants.RequirementsTxt) &&
47+
new FileInfo(Path.Combine(Environment.CurrentDirectory, Constants.RequirementsTxt)).Length > 0)
48+
{
49+
return BuildOption.Remote;
50+
}
51+
}
52+
53+
return currentBuildOption;
54+
}
55+
2856
public static async Task<HttpResponseMessage> InvokeLongRunningRequest(HttpClient client, ProgressMessageHandler handler, HttpRequestMessage request, long requestSize = 0, string prompt = null)
2957
{
3058
if (prompt == null)

src/Cli/func/Helpers/ResolveBuildOptionHelper.cs

Lines changed: 0 additions & 43 deletions
This file was deleted.

test/Cli/Func.E2ETests/Commands/FuncPack/PythonPackTests.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ public void Pack_Python_WorksAsExpected()
3434
{
3535
"host.json",
3636
"requirements.txt",
37-
"function_app.py"
37+
"function_app.py",
38+
Path.Combine(".python_packages", "requirements.txt.md5")
3839
});
3940
}
4041

@@ -82,14 +83,22 @@ public void Pack_PythonFromCache_WorksAsExpected()
8283
firstPackResult.Should().HaveStdOutContaining("Creating a new package");
8384
firstPackResult.Should().NotHaveStdOutContaining(syncDirMessage);
8485

86+
// Verify .python_packages/requirements.txt.md5 file exists
87+
var pythonPackagesMd5Path = Path.Combine(workingDir, ".python_packages", "requirements.txt.md5");
88+
var packFilesToValidate = new List<(string FilePath, string[] ExpectedContent)>
89+
{
90+
(pythonPackagesMd5Path, new[] { string.Empty }) // Just check file exists, content can be empty
91+
};
92+
firstPackResult.Should().FilesExistsWithExpectContent(packFilesToValidate);
93+
8594
// Step 3: Run pack again without changing requirements.txt (should use cache)
8695
var secondPackResult = funcPackCommand
8796
.WithWorkingDirectory(workingDir)
8897
.Execute([]);
8998

9099
secondPackResult.Should().ExitWith(0);
91100
secondPackResult.Should().HaveStdOutContaining("Creating a new package");
92-
secondPackResult.Should().NotHaveStdOutContaining(syncDirMessage);
101+
secondPackResult.Should().HaveStdOutContaining(syncDirMessage);
93102

94103
// Step 4: Update requirements.txt and pack again (should restore dependencies)
95104
var requirementsPath = Path.Combine(workingDir, "requirements.txt");
@@ -103,6 +112,9 @@ public void Pack_PythonFromCache_WorksAsExpected()
103112
thirdPackResult.Should().ExitWith(0);
104113
thirdPackResult.Should().HaveStdOutContaining("Creating a new package");
105114
thirdPackResult.Should().NotHaveStdOutContaining(syncDirMessage);
115+
116+
// Verify .python_packages/requirements.txt.md5 file still exists
117+
thirdPackResult.Should().FilesExistsWithExpectContent(packFilesToValidate);
106118
}
107119
}
108120
}

test/Cli/Func.UnitTests/HelperTests/ResolveBuildOptionTests.cs

Lines changed: 0 additions & 146 deletions
This file was deleted.

0 commit comments

Comments
 (0)