Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable support for Python3.11 #3343

Merged
merged 2 commits into from
May 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Azure.Functions.Cli/Azure.Functions.Cli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@
<EmbeddedResource Include="StaticResources\Dockerfile.python3.10">
<LogicalName>$(AssemblyName).Dockerfile.python3.10</LogicalName>
</EmbeddedResource>
<EmbeddedResource Include="StaticResources\Dockerfile.python3.11">
<LogicalName>$(AssemblyName).Dockerfile.python3.11</LogicalName>
</EmbeddedResource>
<EmbeddedResource Include="StaticResources\Dockerfile.typescript">
<LogicalName>$(AssemblyName).Dockerfile.typescript</LogicalName>
</EmbeddedResource>
Expand Down
1 change: 1 addition & 0 deletions src/Azure.Functions.Cli/Common/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ public static class DockerImages
public const string LinuxPython38ImageAmd64 = "mcr.microsoft.com/azure-functions/python:3.0.15066-python3.8-buildenv";
public const string LinuxPython39ImageAmd64 = "mcr.microsoft.com/azure-functions/python:3.0.15066-python3.9-buildenv";
public const string LinuxPython310ImageAmd64 = "mcr.microsoft.com/azure-functions/python:4-python3.10-buildenv";
public const string LinuxPython311ImageAmd64 = "mcr.microsoft.com/azure-functions/python:4-python3.11-buildenv";
}

public static class StaticResourcesNames
Expand Down
21 changes: 14 additions & 7 deletions src/Azure.Functions.Cli/Helpers/PythonHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,31 +165,31 @@ public static void AssertPythonVersion(WorkerLanguageVersionInfo pythonVersion,
{
if (pythonVersion?.Version == null)
{
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.";
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.";
pdthummar marked this conversation as resolved.
Show resolved Hide resolved
if (errorIfNoVersion) throw new CliException(message);
ColoredConsole.WriteLine(WarningColor(message));
return;
}

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

// Python 3.[6|7|8|9|10] (supported)
// Python 3.[6|7|8|9|10|11] (supported)
pdthummar marked this conversation as resolved.
Show resolved Hide resolved
if (IsVersionSupported(pythonVersion))
{
return;
}

// Python 3.x (but not 3.[6|7|8|9|10]), not recommended, may fail. E.g.: 3.4, 3.5.
// Python 3.x (but not 3.[6|7|8|9|10|11]), not recommended, may fail. E.g.: 3.4, 3.5.
if (pythonVersion.Major == 3)
{
if (errorIfNotSupported)
throw new CliException($"Python 3.6.x to 3.10.x is required for this operation. " +
$"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.");
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."));
throw new CliException($"Python 3.6.x to 3.11.x is required for this operation. " +
$"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.");
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."));
}

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

var versions = new List<WorkerLanguageVersionInfo>
{
Expand All @@ -233,6 +234,7 @@ public static async Task<WorkerLanguageVersionInfo> GetEnvironmentPythonVersion(
await python38GetVersionTask,
await python39GetVersionTask,
await python310GetVersionTask,
await python311GetVersionTask,
};

// Highest preference -- Go through the list, if we find the first python 3.6 or python 3.7 worker, we prioritize that.
Expand Down Expand Up @@ -553,6 +555,8 @@ public static Task<string> GetDockerInitFileContent(WorkerLanguageVersionInfo in
return StaticResources.DockerfilePython39;
case 10:
return StaticResources.DockerfilePython310;
case 11:
return StaticResources.DockerfilePython311;
}
}
return StaticResources.DockerfilePython37;
Expand All @@ -574,6 +578,8 @@ private static string GetBuildNativeDepsEnvironmentImage(WorkerLanguageVersionIn
return Constants.DockerImages.LinuxPython39ImageAmd64;
case 10:
return Constants.DockerImages.LinuxPython310ImageAmd64;
case 11:
return Constants.DockerImages.LinuxPython311ImageAmd64;
}
}
return Constants.DockerImages.LinuxPython36ImageAmd64;
Expand All @@ -585,6 +591,7 @@ private static bool IsVersionSupported(WorkerLanguageVersionInfo info)
{
switch (info?.Minor)
{
case 11:
case 10:
case 9:
case 8:
Expand Down
11 changes: 11 additions & 0 deletions src/Azure.Functions.Cli/StaticResources/Dockerfile.python3.11
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# To enable ssh & remote debugging on app service change the base image to the one below
# FROM mcr.microsoft.com/azure-functions/python:4-python3.11-appservice
FROM mcr.microsoft.com/azure-functions/python:4-python3.11

ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
AzureFunctionsJobHost__Logging__Console__IsEnabled=true

COPY requirements.txt /
RUN pip install -r /requirements.txt

COPY . /home/site/wwwroot
2 changes: 2 additions & 0 deletions src/Azure.Functions.Cli/StaticResources/StaticResources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public static async Task<string> GetValue(string name)

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

public static Task<string> DockerfilePython311 => GetValue("Dockerfile.python3.11");

pdthummar marked this conversation as resolved.
Show resolved Hide resolved
public static Task<string> DockerfilePowershell7 => GetValue("Dockerfile.powershell7");

public static Task<string> DockerfilePowershell72 => GetValue("Dockerfile.powershell7.2");
Expand Down
5 changes: 3 additions & 2 deletions test/Azure.Functions.Cli.Tests/PythonHelperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public void ShouldHaveMatchingLinuxFxVersion(string linuxFxVersion, int major, i
[InlineData("3.8.0", false)]
[InlineData("3.9.0", false)]
[InlineData("3.10.0", false)]
[InlineData("3.11.0", false)]
public void AssertPythonVersion(string pythonVersion, bool expectException)
{
WorkerLanguageVersionInfo worker = new WorkerLanguageVersionInfo(WorkerRuntime.python, pythonVersion, "python");
Expand All @@ -92,11 +93,11 @@ public SkipIfPythonNonExistFact()
string[] pythons;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
pythons = new string[] { "python.exe", "python3.exe", "python36.exe", "python37.exe", "python38.exe", "python39.exe", "python310.exe", "py.exe" };
pythons = new string[] { "python.exe", "python3.exe", "python36.exe", "python37.exe", "python38.exe", "python39.exe", "python310.exe", "python311.exe", "py.exe" };
}
else
{
pythons = new string[] { "python", "python3", "python36", "python37", "python38", "python39", "python310" };
pythons = new string[] { "python", "python3", "python36", "python37", "python38", "python39", "python310", "python311" };
}

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