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

Python 3.6 baggage code removal #1419

Merged
merged 9 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"dockerfile": "Dockerfile",
"context": "..",
"args": {
// Update 'VARIANT' to pick a Python version: 3, 3.10, 3.9, 3.8, 3.7, 3.6
// Update 'VARIANT' to pick a Python version: 3, 3.10, 3.9, 3.8, 3.7
// Append -bullseye or -buster to pin to an OS version.
// Use -bullseye variants on local on arm64/Apple Silicon.
"VARIANT": "3.9",
Expand Down
14 changes: 3 additions & 11 deletions azure_functions_worker/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,6 @@

_TRUE = "true"

"""In Python 3.6, the current_task method was in the Task class, but got moved
out in 3.7+ and fully removed in 3.9. Thus, to support 3.6 and 3.9 together, we
need to switch the implementation of current_task for 3.6.
"""
_CURRENT_TASK = asyncio.Task.current_task \
if (sys.version_info[0] == 3 and sys.version_info[1] == 6) \
else asyncio.current_task


class DispatcherMeta(type):
__current_dispatcher__ = None
Expand Down Expand Up @@ -446,7 +438,7 @@ async def _handle__invocation_request(self, request):

# Set the current `invocation_id` to the current task so
# that our logging handler can find it.
current_task = _CURRENT_TASK(self._loop)
current_task = asyncio.current_task(self._loop)
assert isinstance(current_task, ContextEnabledTask)
current_task.set_azure_invocation_id(invocation_id)

Expand Down Expand Up @@ -860,7 +852,7 @@ class ContextEnabledTask(asyncio.Task):
def __init__(self, coro, loop):
super().__init__(coro, loop=loop)

current_task = _CURRENT_TASK(loop)
current_task = asyncio.current_task(loop)
if current_task is not None:
invocation_id = getattr(
current_task, self.AZURE_INVOCATION_ID, None)
Expand All @@ -874,7 +866,7 @@ def set_azure_invocation_id(self, invocation_id: str) -> None:
def get_current_invocation_id() -> Optional[str]:
loop = asyncio._get_running_loop()
if loop is not None:
current_task = _CURRENT_TASK(loop)
current_task = asyncio.current_task(loop)
if current_task is not None:
task_invocation_id = getattr(current_task,
ContextEnabledTask.AZURE_INVOCATION_ID,
Expand Down
6 changes: 3 additions & 3 deletions azure_functions_worker/utils/dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,19 @@ class DependencyManager:
Linux Consumption sys.path: [
"/tmp/functions\\standby\\wwwroot", # Placeholder folder
"/home/site/wwwroot/.python_packages/lib/site-packages", # CX's deps
"/azure-functions-host/workers/python/3.6/LINUX/X64", # Worker's deps
"/azure-functions-host/workers/python/3.11/LINUX/X64", # Worker's deps
"/home/site/wwwroot" # CX's Working Directory
]

Linux Dedicated/Premium sys.path: [
"/home/site/wwwroot", # CX's Working Directory
"/home/site/wwwroot/.python_packages/lib/site-packages", # CX's deps
"/azure-functions-host/workers/python/3.6/LINUX/X64", # Worker's deps
"/azure-functions-host/workers/python/3.11/LINUX/X64", # Worker's deps
]

Core Tools sys.path: [
"%appdata%\\azure-functions-core-tools\\bin\\workers\\"
"python\\3.6\\WINDOWS\\X64", # Worker's deps
"python\\3.11\\WINDOWS\\X64", # Worker's deps
"C:\\Users\\user\\Project\\.venv38\\lib\\site-packages", # CX's deps
hallvictoria marked this conversation as resolved.
Show resolved Hide resolved
"C:\\Users\\user\\Project", # CX's Working Directory
]
Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Azure Functions for Python
Requirements
============

Azure Functions for Python support Python 3.6 or later.
Azure Functions for Python support Python 3.7 or later.


Programming Model
Expand Down
4 changes: 0 additions & 4 deletions pack/Microsoft.Azure.Functions.V2.PythonWorker.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
<copyright>© .NET Foundation. All rights reserved.</copyright>
</metadata>
<files>
<file src="..\3.6_WINDOWS_x64\**" target="tools\3.6\WINDOWS\X64" />
<!-- <file src="..\3.6_WINDOWS_X86\**" target="tools\3.6\WINDOWS\X86" /> -->
<file src="..\3.6_LINUX_X64\**" target="tools\3.6\LINUX\X64" />
<file src="..\3.6_OSX_X64\**" target="tools\3.6\OSX\X64" />
<file src="..\3.7_WINDOWS_X64\**" target="tools\3.7\WINDOWS\X64" />
<file src="..\3.7_WINDOWS_X86\**" target="tools\3.7\WINDOWS\X86" />
<file src="..\3.7_LINUX_X64\**" target="tools\3.7\LINUX\X64" />
Expand Down
4 changes: 0 additions & 4 deletions pack/Microsoft.Azure.Functions.V3.PythonWorker.nuspec
hallvictoria marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
<copyright>© .NET Foundation. All rights reserved.</copyright>
</metadata>
<files>
<file src="..\3.6_WINDOWS_x64\**" target="tools\3.6\WINDOWS\X64" />
<!-- <file src="..\3.6_WINDOWS_X86\**" target="tools\3.6\WINDOWS\X86" /> -->
<file src="..\3.6_LINUX_X64\**" target="tools\3.6\LINUX\X64" />
<file src="..\3.6_OSX_X64\**" target="tools\3.6\OSX\X64" />
<file src="..\3.7_WINDOWS_X64\**" target="tools\3.7\WINDOWS\X64" />
<file src="..\3.7_WINDOWS_X86\**" target="tools\3.7\WINDOWS\X86" />
<file src="..\3.7_LINUX_X64\**" target="tools\3.7\LINUX\X64" />
Expand Down
4 changes: 2 additions & 2 deletions python/prodV2/worker.config.json
hallvictoria marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"description":{
"language":"python",
"defaultRuntimeVersion":"3.6",
"defaultRuntimeVersion":"3.7",
"supportedOperatingSystems":["LINUX", "OSX", "WINDOWS"],
"supportedRuntimeVersions":["3.6", "3.7"],
"supportedRuntimeVersions":["3.7"],
"supportedArchitectures":["X64", "X86"],
"extensions":[".py"],
"defaultExecutablePath":"python",
Expand Down
9 changes: 0 additions & 9 deletions python/prodV2/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
PKGS_PATH = "site/wwwroot/.python_packages"
VENV_PKGS_PATH = "site/wwwroot/worker_venv"

PKGS_36 = "lib/python3.6/site-packages"
PKGS = "lib/site-packages"

# Azure environment variables
Expand All @@ -32,24 +31,16 @@ def add_script_root_to_sys_path():
def determine_user_pkg_paths():
"""This finds the user packages when function apps are running on the cloud

For Python 3.6 app, the third-party packages can live in any of the paths:
/home/site/wwwroot/.python_packages/lib/site-packages
/home/site/wwwroot/.python_packages/lib/python3.6/site-packages
/home/site/wwwroot/worker_venv/lib/python3.6/site-packages

For Python 3.7, we only accept:
/home/site/wwwroot/.python_packages/lib/site-packages
"""
minor_version = sys.version_info[1]

home = Path.home()
pkgs_path = os.path.join(home, PKGS_PATH)
venv_pkgs_path = os.path.join(home, VENV_PKGS_PATH)

user_pkg_paths = []
if minor_version == 6:
user_pkg_paths.append(os.path.join(venv_pkgs_path, PKGS_36))
user_pkg_paths.append(os.path.join(pkgs_path, PKGS_36))
user_pkg_paths.append(os.path.join(pkgs_path, PKGS))
elif minor_version == 7:
user_pkg_paths.append(os.path.join(pkgs_path, PKGS))
Expand Down
2 changes: 1 addition & 1 deletion python/prodV3/worker.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"language":"python",
"defaultRuntimeVersion":"3.8",
"supportedOperatingSystems":["LINUX", "OSX", "WINDOWS"],
"supportedRuntimeVersions":["3.6", "3.7", "3.8", "3.9"],
"supportedRuntimeVersions":["3.7", "3.8", "3.9"],
"supportedArchitectures":["X64", "X86"],
"extensions":[".py"],
"defaultExecutablePath":"python",
Expand Down
9 changes: 0 additions & 9 deletions python/prodV3/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
PKGS_PATH = "site/wwwroot/.python_packages"
VENV_PKGS_PATH = "site/wwwroot/worker_venv"

PKGS_36 = "lib/python3.6/site-packages"
PKGS = "lib/site-packages"

# Azure environment variables
Expand All @@ -32,24 +31,16 @@ def add_script_root_to_sys_path():
def determine_user_pkg_paths():
"""This finds the user packages when function apps are running on the cloud

For Python 3.6 app, the third-party packages can live in any of the paths:
/home/site/wwwroot/.python_packages/lib/site-packages
/home/site/wwwroot/.python_packages/lib/python3.6/site-packages
/home/site/wwwroot/worker_venv/lib/python3.6/site-packages

For Python 3.7 and Python 3.8, we only accept:
/home/site/wwwroot/.python_packages/lib/site-packages
"""
minor_version = sys.version_info[1]

home = Path.home()
pkgs_path = os.path.join(home, PKGS_PATH)
venv_pkgs_path = os.path.join(home, VENV_PKGS_PATH)

user_pkg_paths = []
if minor_version == 6:
user_pkg_paths.append(os.path.join(venv_pkgs_path, PKGS_36))
user_pkg_paths.append(os.path.join(pkgs_path, PKGS_36))
user_pkg_paths.append(os.path.join(pkgs_path, PKGS))
elif minor_version in (7, 8, 9):
user_pkg_paths.append(os.path.join(pkgs_path, PKGS))
Expand Down
23 changes: 0 additions & 23 deletions setup.cfg

This file was deleted.

4 changes: 0 additions & 4 deletions tests/unittests/test_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ class TestThreadPoolSettingsPython37(testutils.AsyncTestCase):
Python 3.7 and extended classes change this value and other platform
specific values to test the behavior across the different python versions.

- Why not python 3.6?
- In Azure.Functions (library), the typing_inspect module imports specific
modules which are not available on systems where Python 3.7+ is installed.

Ref:
NEW_TYPING = sys.version_info[:3] >= (3, 7, 0) # PEP 560
"""
Expand Down
2 changes: 0 additions & 2 deletions tests/unittests/test_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,15 +315,13 @@ def parse_int_no_raise(value: str):

def test_is_python_version(self):
# Should pass at least 1 test
is_python_version_36 = common.is_python_version('3.6')
is_python_version_37 = common.is_python_version('3.7')
is_python_version_38 = common.is_python_version('3.8')
is_python_version_39 = common.is_python_version('3.9')
is_python_version_310 = common.is_python_version('3.10')
is_python_version_311 = common.is_python_version('3.11')

self.assertTrue(any([
is_python_version_36,
is_python_version_37,
is_python_version_38,
is_python_version_39,
Expand Down
18 changes: 9 additions & 9 deletions tests/unittests/test_utilities_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def test_initialize_in_linux_consumption(self):
sys.path.extend([
'/tmp/functions\\standby\\wwwroot',
'/home/site/wwwroot/.python_packages/lib/site-packages',
'/azure-functions-host/workers/python/3.6/LINUX/X64',
hallvictoria marked this conversation as resolved.
Show resolved Hide resolved
'/azure-functions-host/workers/python/3.7/LINUX/X64',
'/home/site/wwwroot'
])
DependencyManager.initialize()
Expand All @@ -71,7 +71,7 @@ def test_initialize_in_linux_consumption(self):
)
self.assertEqual(
DependencyManager.worker_deps_path,
'/azure-functions-host/workers/python/3.6/LINUX/X64'
'/azure-functions-host/workers/python/3.7/LINUX/X64'
)

def test_initialize_in_linux_dedicated(self):
Expand Down Expand Up @@ -100,7 +100,7 @@ def test_initialize_in_windows_core_tools(self):
sys.path.extend([
'C:\\Users\\user\\AppData\\Roaming\\npm\\'
'node_modules\\azure-functions-core-tools\\bin\\'
'workers\\python\\3.6\\WINDOWS\\X64',
'workers\\python\\3.7\\WINDOWS\\X64',
'C:\\FunctionApp\\.venv38\\lib\\site-packages',
'C:\\FunctionApp'
])
Expand All @@ -116,7 +116,7 @@ def test_initialize_in_windows_core_tools(self):
self.assertEqual(
DependencyManager.worker_deps_path,
'C:\\Users\\user\\AppData\\Roaming\\npm\\node_modules\\'
'azure-functions-core-tools\\bin\\workers\\python\\3.6\\WINDOWS'
'azure-functions-core-tools\\bin\\workers\\python\\3.7\\WINDOWS'
'\\X64'
)

Expand All @@ -130,13 +130,13 @@ def test_get_cx_deps_path_in_script_root_no_sys_path(self):
self.assertEqual(result, '')

def test_get_cx_deps_path_in_script_root_with_sys_path_linux_py36(self):
# Test for Python 3.6 Azure Environment
# Test for Python 3.7 Azure Environment
sys.path.append('/home/site/wwwroot/.python_packages/sites/lib/'
'python3.6/site-packages/')
'python3.7/site-packages/')
os.environ['AzureWebJobsScriptRoot'] = '/home/site/wwwroot'
result = DependencyManager._get_cx_deps_path()
self.assertEqual(result, '/home/site/wwwroot/.python_packages/sites/'
'lib/python3.6/site-packages/')
'lib/python3.7/site-packages/')

def test_get_cx_deps_path_in_script_root_with_sys_path_linux(self):
# Test for Python 3.7+ Azure Environment
Expand Down Expand Up @@ -185,12 +185,12 @@ def test_get_worker_deps_path_from_windows_core_tools(self):
# Test for Windows Core Tools Environment
sys.path.append('C:\\Users\\user\\AppData\\Roaming\\npm\\'
'node_modules\\azure-functions-core-tools\\bin\\'
'workers\\python\\3.6\\WINDOWS\\X64')
'workers\\python\\3.7\\WINDOWS\\X64')
result = DependencyManager._get_worker_deps_path()
self.assertEqual(result,
'C:\\Users\\user\\AppData\\Roaming\\npm\\'
'node_modules\\azure-functions-core-tools\\bin\\'
'workers\\python\\3.6\\WINDOWS\\X64')
'workers\\python\\3.7\\WINDOWS\\X64')

def test_get_worker_deps_path_from_linux_azure_environment(self):
# Test for Azure Environment
Expand Down
6 changes: 1 addition & 5 deletions tests/utils/testutils_lc.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,7 @@ def _find_latest_mesh_image(cls,
return cls._mesh_images[host_major]

# match 3.1.3
regex = re.compile(host_major + r'.\d+.\d+')

# match 3.1.3-python3.x
if python_version != '3.6':
regex = re.compile(host_major + r'.\d+.\d+-python' + python_version)
regex = re.compile(host_major + r'.\d+.\d+-python' + python_version)

response = requests.get(_MESH_IMAGE_URL, allow_redirects=True)
if not response.ok:
Expand Down
Loading