Skip to content

Commit 0130b8b

Browse files
authored
Fix python buildenv dockerfile name (#4742)
1 parent a945aaf commit 0130b8b

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

release_notes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@
1515
prompt the user to select which target framework to use for the Dockerfile.
1616
- Enhanced dotnet installation discovery by adopting the same `Muxer` logic used by the .NET SDK itself (#4732)
1717
- Update .NET templates package version to 4.0.5337 (#4728)
18+
- Fix `func pack --build-native-deps` failure on Windows for Python 3.13+ (#4742)

src/Cli/func/Helpers/PythonHelpers.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -564,10 +564,11 @@ private static async Task<DockerImageInfo> ChoosePythonBuildEnvImage()
564564
{
565565
// Setup image tag and content
566566
string imageContent = image;
567-
image = $"azure-functions/python:4-python{workerInfo.Major}.{workerInfo.Minor}-buildenv";
567+
string dockerfileName = $"4-python{workerInfo.Major}{workerInfo.Minor}-buildenv";
568+
image = $"azure-functions/python:{dockerfileName}";
568569

569570
// Prepare temporary directory for docker build context
570-
string tempDockerfileDirecotry = Path.Combine(Path.GetTempPath(), $"{image}-docker");
571+
string tempDockerfileDirecotry = Path.Combine(Path.GetTempPath(), $"{dockerfileName}");
571572
FileSystemHelpers.EnsureDirectory(tempDockerfileDirecotry);
572573
string tempDockerfile = Path.Combine(tempDockerfileDirecotry, "Dockerfile");
573574

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,29 @@ public void AssertPythonVersion(string pythonVersion, bool expectException)
9191
Assert.Throws<CliException>(() => PythonHelpers.AssertPythonVersion(worker));
9292
}
9393
}
94+
95+
[Theory]
96+
[InlineData(3, 10)]
97+
[InlineData(3, 11)]
98+
[InlineData(3, 12)]
99+
[InlineData(3, 13)]
100+
[InlineData(3, 14)]
101+
public void DockerfileNameShouldNotContainInvalidCharacters(int major, int minor)
102+
{
103+
// Verify the dockerfile name format matches what's used in ChoosePythonBuildEnvImage
104+
// The format should be "4-python{major}{minor}-buildenv" with no colons or other invalid chars
105+
string dockerfileName = $"4-python{major}{minor}-buildenv";
106+
107+
// Ensure no colons (invalid on Windows file paths)
108+
Assert.DoesNotContain(":", dockerfileName);
109+
110+
// Ensure no other invalid Windows path characters
111+
char[] invalidChars = Path.GetInvalidFileNameChars();
112+
Assert.DoesNotContain(dockerfileName, c => invalidChars.Contains(c));
113+
114+
// Verify expected format
115+
Assert.Matches(@"^4-python\d+-buildenv$", dockerfileName);
116+
}
94117
}
95118

96119
public sealed class SkipIfPythonNonExistFact : FactAttribute

0 commit comments

Comments
 (0)