Skip to content

Commit 693c06a

Browse files
authored
Enable support for Python3.11 (#3343)
* Enable support for 3.11
1 parent ee3aca4 commit 693c06a

File tree

6 files changed

+34
-9
lines changed

6 files changed

+34
-9
lines changed

src/Azure.Functions.Cli/Azure.Functions.Cli.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@
9797
<EmbeddedResource Include="StaticResources\Dockerfile.python3.10">
9898
<LogicalName>$(AssemblyName).Dockerfile.python3.10</LogicalName>
9999
</EmbeddedResource>
100+
<EmbeddedResource Include="StaticResources\Dockerfile.python3.11">
101+
<LogicalName>$(AssemblyName).Dockerfile.python3.11</LogicalName>
102+
</EmbeddedResource>
100103
<EmbeddedResource Include="StaticResources\Dockerfile.typescript">
101104
<LogicalName>$(AssemblyName).Dockerfile.typescript</LogicalName>
102105
</EmbeddedResource>

src/Azure.Functions.Cli/Common/Constants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ public static class DockerImages
165165
public const string LinuxPython38ImageAmd64 = "mcr.microsoft.com/azure-functions/python:3.0.15066-python3.8-buildenv";
166166
public const string LinuxPython39ImageAmd64 = "mcr.microsoft.com/azure-functions/python:3.0.15066-python3.9-buildenv";
167167
public const string LinuxPython310ImageAmd64 = "mcr.microsoft.com/azure-functions/python:4-python3.10-buildenv";
168+
public const string LinuxPython311ImageAmd64 = "mcr.microsoft.com/azure-functions/python:4-python3.11-buildenv";
168169
}
169170

170171
public static class StaticResourcesNames

src/Azure.Functions.Cli/Helpers/PythonHelpers.cs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -165,31 +165,31 @@ public static void AssertPythonVersion(WorkerLanguageVersionInfo pythonVersion,
165165
{
166166
if (pythonVersion?.Version == null)
167167
{
168-
var message = "Could not find a Python version. Python 3.6.x, 3.7.x, 3.8.x, 3.9.x, or 3.10.x is recommended, and used in Azure Functions.";
168+
var message = "Could not find a Python version. Python 3.6.x, 3.7.x, 3.8.x, 3.9.x, 3.10.x or 3.11.x is recommended, and used in Azure Functions.";
169169
if (errorIfNoVersion) throw new CliException(message);
170170
ColoredConsole.WriteLine(WarningColor(message));
171171
return;
172172
}
173173

174174
ColoredConsole.WriteLine(AdditionalInfoColor($"Found Python version {pythonVersion.Version} ({pythonVersion.ExecutablePath})."));
175175

176-
// Python 3.[6|7|8|9|10] (supported)
176+
// Python 3.[6|7|8|9|10|11] (supported)
177177
if (IsVersionSupported(pythonVersion))
178178
{
179179
return;
180180
}
181181

182-
// Python 3.x (but not 3.[6|7|8|9|10]), not recommended, may fail. E.g.: 3.4, 3.5.
182+
// Python 3.x (but not 3.[6|7|8|9|10|11]), not recommended, may fail. E.g.: 3.4, 3.5.
183183
if (pythonVersion.Major == 3)
184184
{
185185
if (errorIfNotSupported)
186-
throw new CliException($"Python 3.6.x to 3.10.x is required for this operation. " +
187-
$"Please install Python 3.6, 3.7, 3.8, 3.9, or 3.10 and use a virtual environment to switch to Python 3.6, 3.7, 3.8, 3.9, or 3.10.");
188-
ColoredConsole.WriteLine(WarningColor("Python 3.6.x, 3.7.x, 3.8.x, 3.9.x, or 3.10.x is recommended, and used in Azure Functions."));
186+
throw new CliException($"Python 3.6.x to 3.11.x is required for this operation. " +
187+
$"Please install Python 3.6, 3.7, 3.8, 3.9, 3.10 or 3.11 and use a virtual environment to switch to Python 3.6, 3.7, 3.8, 3.9, 3.10 or 3.11.");
188+
ColoredConsole.WriteLine(WarningColor("Python 3.6.x, 3.7.x, 3.8.x, 3.9.x, 3.10.x or 3.11.x is recommended, and used in Azure Functions."));
189189
}
190190

191191
// No Python 3
192-
var error = "Python 3.x (recommended version 3.[6|7|8|9|10]) is required.";
192+
var error = "Python 3.x (recommended version 3.[6|7|8|9|10|11]) is required.";
193193
if (errorIfNoVersion) throw new CliException(error);
194194
ColoredConsole.WriteLine(WarningColor(error));
195195
}
@@ -222,6 +222,7 @@ public static async Task<WorkerLanguageVersionInfo> GetEnvironmentPythonVersion(
222222
var python38GetVersionTask = GetVersion("python3.8");
223223
var python39GetVersionTask = GetVersion("python3.9");
224224
var python310GetVersionTask = GetVersion("python3.10");
225+
var python311GetVersionTask = GetVersion("python3.11");
225226

226227
var versions = new List<WorkerLanguageVersionInfo>
227228
{
@@ -233,6 +234,7 @@ public static async Task<WorkerLanguageVersionInfo> GetEnvironmentPythonVersion(
233234
await python38GetVersionTask,
234235
await python39GetVersionTask,
235236
await python310GetVersionTask,
237+
await python311GetVersionTask,
236238
};
237239

238240
// Highest preference -- Go through the list, if we find the first python 3.6 or python 3.7 worker, we prioritize that.
@@ -553,6 +555,8 @@ public static Task<string> GetDockerInitFileContent(WorkerLanguageVersionInfo in
553555
return StaticResources.DockerfilePython39;
554556
case 10:
555557
return StaticResources.DockerfilePython310;
558+
case 11:
559+
return StaticResources.DockerfilePython311;
556560
}
557561
}
558562
return StaticResources.DockerfilePython37;
@@ -574,6 +578,8 @@ private static string GetBuildNativeDepsEnvironmentImage(WorkerLanguageVersionIn
574578
return Constants.DockerImages.LinuxPython39ImageAmd64;
575579
case 10:
576580
return Constants.DockerImages.LinuxPython310ImageAmd64;
581+
case 11:
582+
return Constants.DockerImages.LinuxPython311ImageAmd64;
577583
}
578584
}
579585
return Constants.DockerImages.LinuxPython36ImageAmd64;
@@ -585,6 +591,7 @@ private static bool IsVersionSupported(WorkerLanguageVersionInfo info)
585591
{
586592
switch (info?.Minor)
587593
{
594+
case 11:
588595
case 10:
589596
case 9:
590597
case 8:
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# To enable ssh & remote debugging on app service change the base image to the one below
2+
# FROM mcr.microsoft.com/azure-functions/python:4-python3.11-appservice
3+
FROM mcr.microsoft.com/azure-functions/python:4-python3.11
4+
5+
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
6+
AzureFunctionsJobHost__Logging__Console__IsEnabled=true
7+
8+
COPY requirements.txt /
9+
RUN pip install -r /requirements.txt
10+
11+
COPY . /home/site/wwwroot

src/Azure.Functions.Cli/StaticResources/StaticResources.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ public static async Task<string> GetValue(string name)
5050

5151
public static Task<string> DockerfilePython310 => GetValue("Dockerfile.python3.10");
5252

53+
public static Task<string> DockerfilePython311 => GetValue("Dockerfile.python3.11");
54+
5355
public static Task<string> DockerfilePowershell7 => GetValue("Dockerfile.powershell7");
5456

5557
public static Task<string> DockerfilePowershell72 => GetValue("Dockerfile.powershell7.2");

test/Azure.Functions.Cli.Tests/PythonHelperTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public void ShouldHaveMatchingLinuxFxVersion(string linuxFxVersion, int major, i
7171
[InlineData("3.8.0", false)]
7272
[InlineData("3.9.0", false)]
7373
[InlineData("3.10.0", false)]
74+
[InlineData("3.11.0", false)]
7475
public void AssertPythonVersion(string pythonVersion, bool expectException)
7576
{
7677
WorkerLanguageVersionInfo worker = new WorkerLanguageVersionInfo(WorkerRuntime.python, pythonVersion, "python");
@@ -92,11 +93,11 @@ public SkipIfPythonNonExistFact()
9293
string[] pythons;
9394
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
9495
{
95-
pythons = new string[] { "python.exe", "python3.exe", "python36.exe", "python37.exe", "python38.exe", "python39.exe", "python310.exe", "py.exe" };
96+
pythons = new string[] { "python.exe", "python3.exe", "python36.exe", "python37.exe", "python38.exe", "python39.exe", "python310.exe", "python311.exe", "py.exe" };
9697
}
9798
else
9899
{
99-
pythons = new string[] { "python", "python3", "python36", "python37", "python38", "python39", "python310" };
100+
pythons = new string[] { "python", "python3", "python36", "python37", "python38", "python39", "python310", "python311" };
100101
}
101102

102103
string pythonExe = pythons.FirstOrDefault(p => CheckIfPythonExist(p));

0 commit comments

Comments
 (0)