From dbeaa2df938bc2a5948b003060804897138bcc75 Mon Sep 17 00:00:00 2001 From: aparnajyothi-y <147696841+aparnajyothi-y@users.noreply.github.com> Date: Wed, 27 Nov 2024 18:09:16 +0530 Subject: [PATCH 1/8] Update macos-python-builder.psm1 --- builders/macos-python-builder.psm1 | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/builders/macos-python-builder.psm1 b/builders/macos-python-builder.psm1 index 72549a72..984df814 100644 --- a/builders/macos-python-builder.psm1 +++ b/builders/macos-python-builder.psm1 @@ -32,13 +32,13 @@ class macOSPythonBuilder : NixPythonBuilder { Prepare system environment by installing dependencies and required packages. #> - if ($this.Version -eq "3.7.17") { - # We have preinstalled ncurses and readLine on the hoster runners. But we need to install bzip2 for - # setting up an environemnt - # If we get any issues realted to ncurses or readline we can try to run this command - # brew install ncurses readline - Execute-Command -Command "brew install bzip2" - } + # Ensure Homebrew is installed (in case it's not already available) + if (-not (Test-Path "/usr/local/bin/brew")) { + Write-Host "Homebrew not found. Installing Homebrew..." + Invoke-Expression -Command "/bin/bash -c \"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)\"" + } else { + Write-Host "Homebrew is already installed." + } } [void] Configure() { From c0cdd7380edf434b2743deedafd32ed331e975f1 Mon Sep 17 00:00:00 2001 From: aparnajyothi-y <147696841+aparnajyothi-y@users.noreply.github.com> Date: Wed, 27 Nov 2024 18:46:34 +0530 Subject: [PATCH 2/8] Update macos-python-builder.psm1 --- builders/macos-python-builder.psm1 | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/builders/macos-python-builder.psm1 b/builders/macos-python-builder.psm1 index 984df814..9c525c7c 100644 --- a/builders/macos-python-builder.psm1 +++ b/builders/macos-python-builder.psm1 @@ -31,15 +31,20 @@ class macOSPythonBuilder : NixPythonBuilder { .SYNOPSIS Prepare system environment by installing dependencies and required packages. #> - + if ($this.Version -eq "3.7.17") { # Ensure Homebrew is installed (in case it's not already available) if (-not (Test-Path "/usr/local/bin/brew")) { Write-Host "Homebrew not found. Installing Homebrew..." Invoke-Expression -Command "/bin/bash -c \"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)\"" + # Once Homebrew is installed, install the dependencies + Write-Host "Installing dependencies: bzip2, readline, ncurses..." + Execute-Command -Command "brew install bzip2 readline ncurses" + } else { Write-Host "Homebrew is already installed." } } + } [void] Configure() { <# From d43da0ca8aef36803d2c1ebb8cbe49b0d8939c74 Mon Sep 17 00:00:00 2001 From: aparnajyothi-y <147696841+aparnajyothi-y@users.noreply.github.com> Date: Fri, 29 Nov 2024 14:21:13 +0530 Subject: [PATCH 3/8] Update macos-python-builder.psm1 --- builders/macos-python-builder.psm1 | 37 ++++++++++++------------------ 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/builders/macos-python-builder.psm1 b/builders/macos-python-builder.psm1 index 9c525c7c..257ceda1 100644 --- a/builders/macos-python-builder.psm1 +++ b/builders/macos-python-builder.psm1 @@ -1,23 +1,20 @@ -using module "./nix-python-builder.psm1" - class macOSPythonBuilder : NixPythonBuilder { <# .SYNOPSIS MacOS Python builder class. .DESCRIPTION - Contains methods that required to build macOS Python artifact from sources. Inherited from base NixPythonBuilder. + Contains methods required to build macOS Python artifacts from sources. Inherited from base NixPythonBuilder. While python.org provides precompiled binaries for macOS, switching to them risks breaking existing customers. If we wanted to start using the official binaries instead of building from source, we should avoid changing previous versions so we remain backwards compatible. .PARAMETER platform - The full name of platform for which Python should be built. + The full name of the platform for which Python should be built. .PARAMETER version The version of Python that should be built. - #> macOSPythonBuilder( @@ -31,19 +28,13 @@ class macOSPythonBuilder : NixPythonBuilder { .SYNOPSIS Prepare system environment by installing dependencies and required packages. #> - if ($this.Version -eq "3.7.17") { - # Ensure Homebrew is installed (in case it's not already available) - if (-not (Test-Path "/usr/local/bin/brew")) { - Write-Host "Homebrew not found. Installing Homebrew..." - Invoke-Expression -Command "/bin/bash -c \"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)\"" - # Once Homebrew is installed, install the dependencies - Write-Host "Installing dependencies: bzip2, readline, ncurses..." - Execute-Command -Command "brew install bzip2 readline ncurses" - - } else { - Write-Host "Homebrew is already installed." - } - } + + # Only for Python 3.7.17, install additional dependencies + if ($this.Version -eq "3.7.17") { + Write-Host "Installing additional dependencies for Python 3.7.17..." + # Install necessary dependencies for Python 3.7.17 + Execute-Command -Command "brew install bzip2 zlib readline ncurses sqlite3 openssl@1.1" + } } [void] Configure() { @@ -76,10 +67,10 @@ class macOSPythonBuilder : NixPythonBuilder { $env:LDFLAGS = "-L/usr/local/opt/openssl@3/lib -L/usr/local/opt/zlib/lib" $env:CFLAGS = "-I/usr/local/opt/openssl@3/include -I/usr/local/opt/zlib/include" } else { - $configureString += " --with-openssl=/usr/local/opt/openssl@3" + $configureString += " --with-openssl=/usr/local/opt/openssl@1.1" # For Python 3.7.x, use OpenSSL 1.1 - # For Python 3.7.2 and 3.7.3 we need to provide PATH for zlib to pack it properly. Otherwise the build will fail - # with the error: zipimport.ZipImportError: can't decompress data; zlib not available + # For Python 3.7.2, 3.7.3, and 3.7.17 we need to provide PATH for zlib to pack it properly. + # Otherwise, the build will fail with the error: zipimport.ZipImportError: can't decompress data; zlib not available if ($this.Version -eq "3.7.2" -or $this.Version -eq "3.7.3" -or $this.Version -eq "3.7.17") { $env:LDFLAGS = "-L/usr/local/opt/zlib/lib" $env:CFLAGS = "-I/usr/local/opt/zlib/include" @@ -87,9 +78,11 @@ class macOSPythonBuilder : NixPythonBuilder { if ($this.Version -gt "3.7.12") { $configureString += " --with-tcltk-includes='-I /usr/local/opt/tcl-tk/include' --with-tcltk-libs='-L/usr/local/opt/tcl-tk/lib -ltcl8.6 -ltk8.6'" - } + } + # Specific for Python 3.7.17 if ($this.Version -eq "3.7.17") { + Write-Host "Setting environment for Python 3.7.17..." $env:LDFLAGS += " -L$(brew --prefix bzip2)/lib -L$(brew --prefix readline)/lib -L$(brew --prefix ncurses)/lib" $env:CFLAGS += " -I$(brew --prefix bzip2)/include -I$(brew --prefix readline)/include -I$(brew --prefix ncurses)/include" } From c47a267fd1d5b681d845e0a87ceb7fa722ff82ba Mon Sep 17 00:00:00 2001 From: aparnajyothi-y <147696841+aparnajyothi-y@users.noreply.github.com> Date: Fri, 29 Nov 2024 14:57:55 +0530 Subject: [PATCH 4/8] Update macos-python-builder.psm1 --- builders/macos-python-builder.psm1 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/builders/macos-python-builder.psm1 b/builders/macos-python-builder.psm1 index 257ceda1..90c4d980 100644 --- a/builders/macos-python-builder.psm1 +++ b/builders/macos-python-builder.psm1 @@ -1,3 +1,5 @@ +using module "./nix-python-builder.psm1" + class macOSPythonBuilder : NixPythonBuilder { <# .SYNOPSIS From 3d18e531c21464016b4060040bfcf97b2192424d Mon Sep 17 00:00:00 2001 From: aparnajyothi-y <147696841+aparnajyothi-y@users.noreply.github.com> Date: Fri, 29 Nov 2024 16:17:14 +0530 Subject: [PATCH 5/8] Update macos-python-builder.psm1 --- builders/macos-python-builder.psm1 | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/builders/macos-python-builder.psm1 b/builders/macos-python-builder.psm1 index 90c4d980..01664f01 100644 --- a/builders/macos-python-builder.psm1 +++ b/builders/macos-python-builder.psm1 @@ -32,11 +32,16 @@ class macOSPythonBuilder : NixPythonBuilder { #> # Only for Python 3.7.17, install additional dependencies - if ($this.Version -eq "3.7.17") { - Write-Host "Installing additional dependencies for Python 3.7.17..." - # Install necessary dependencies for Python 3.7.17 - Execute-Command -Command "brew install bzip2 zlib readline ncurses sqlite3 openssl@1.1" - } + if ($this.Version -eq "3.7.17") { + Write-Host "Installing additional dependencies for Python 3.7.17..." + # Install necessary dependencies for Python 3.7.17 + Execute-Command -Command "brew install bzip2 zlib readline ncurses sqlite3 openssl@1.1" + + # Ensure the environment variables for zlib are set correctly + $zlibPrefix = (brew --prefix zlib) + $env:LDFLAGS += " -L$($zlibPrefix)/lib" + $env:CFLAGS += " -I$($zlibPrefix)/include" + } } [void] Configure() { From 4117c4fe8299b2a57bb8a34ebcb3744ef9e8edf5 Mon Sep 17 00:00:00 2001 From: aparnajyothi-y <147696841+aparnajyothi-y@users.noreply.github.com> Date: Fri, 29 Nov 2024 16:17:29 +0530 Subject: [PATCH 6/8] Update macos-python-builder.psm1 --- builders/macos-python-builder.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builders/macos-python-builder.psm1 b/builders/macos-python-builder.psm1 index 01664f01..fd46cea4 100644 --- a/builders/macos-python-builder.psm1 +++ b/builders/macos-python-builder.psm1 @@ -35,7 +35,7 @@ class macOSPythonBuilder : NixPythonBuilder { if ($this.Version -eq "3.7.17") { Write-Host "Installing additional dependencies for Python 3.7.17..." # Install necessary dependencies for Python 3.7.17 - Execute-Command -Command "brew install bzip2 zlib readline ncurses sqlite3 openssl@1.1" + Execute-Command -Command "brew install bzip2 zlib readline ncurses sqlite3 openssl@3" # Ensure the environment variables for zlib are set correctly $zlibPrefix = (brew --prefix zlib) From c84ab0e4bd729e78e6e9c1a432d3a37069ae0d0c Mon Sep 17 00:00:00 2001 From: aparnajyothi-y <147696841+aparnajyothi-y@users.noreply.github.com> Date: Mon, 2 Dec 2024 13:14:31 +0530 Subject: [PATCH 7/8] Update macos-pkg-setup-template.sh --- installers/macos-pkg-setup-template.sh | 39 ++++++++++++++++++++------ 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/installers/macos-pkg-setup-template.sh b/installers/macos-pkg-setup-template.sh index 5e1aa6ef..c31c070d 100644 --- a/installers/macos-pkg-setup-template.sh +++ b/installers/macos-pkg-setup-template.sh @@ -23,25 +23,46 @@ PYTHON_TOOLCACHE_VERSION_ARCH_PATH=$PYTHON_TOOLCACHE_VERSION_PATH/$ARCH PYTHON_FRAMEWORK_PATH="/Library/Frameworks/Python.framework/Versions/${MAJOR_VERSION}.${MINOR_VERSION}" PYTHON_APPLICATION_PATH="/Applications/Python ${MAJOR_VERSION}.${MINOR_VERSION}" -echo "Check if Python hostedtoolcache folder exist..." +# Check if Python dependencies are installed (e.g., zlib) +echo "Checking if zlib is installed..." +if ! brew list zlib &>/dev/null; then + echo "Installing zlib via brew..." + brew install zlib +else + echo "zlib already installed." +fi + +# Only for Python 3.7.17, install additional dependencies like zlib and others +if [ "$MAJOR_VERSION" -eq 3 ] && [ "$MINOR_VERSION" -eq 7 ] && [ "$PYTHON_FULL_VERSION" == "3.7.17" ]; then + echo "Installing additional dependencies for Python 3.7.17..." + brew install bzip2 readline ncurses sqlite3 openssl@3 + # Ensure the environment variables for zlib are set correctly + ZLIB_PREFIX=$(brew --prefix zlib) + export LDFLAGS="-L${ZLIB_PREFIX}/lib" + export CFLAGS="-I${ZLIB_PREFIX}/include" + export CPPFLAGS="-I${ZLIB_PREFIX}/include" + echo "zlib linked at ${ZLIB_PREFIX}/lib" +fi + +echo "Check if Python hostedtoolcache folder exists..." if [ ! -d $PYTHON_TOOLCACHE_PATH ]; then echo "Creating Python hostedtoolcache folder..." mkdir -p $PYTHON_TOOLCACHE_PATH else - # remove ALL other directories for same major.minor python versions - find $PYTHON_TOOLCACHE_PATH -name "${MAJOR_VERSION}.${MINOR_VERSION}.*"|while read python_version;do + # Remove ALL other directories for same major.minor python versions + find $PYTHON_TOOLCACHE_PATH -name "${MAJOR_VERSION}.${MINOR_VERSION}.*" | while read python_version; do python_version_arch="$python_version/$ARCH" - if [ -e "$python_version_arch" ];then + if [ -e "$python_version_arch" ]; then echo "Deleting Python $python_version_arch" rm -rf "$python_version_arch" fi done fi -echo "Install Python binaries from prebuilt package" +echo "Installing Python binaries from prebuilt package" sudo installer -pkg $PYTHON_PKG_NAME -target / -echo "Create hostedtoolcach symlinks (Required for the backward compatibility)" +echo "Creating hostedtoolcache symlinks (Required for the backward compatibility)" echo "Create Python $PYTHON_FULL_VERSION folder" mkdir -p $PYTHON_TOOLCACHE_VERSION_ARCH_PATH cd $PYTHON_TOOLCACHE_VERSION_ARCH_PATH @@ -51,7 +72,7 @@ ln -s "${PYTHON_FRAMEWORK_PATH}/include" include ln -s "${PYTHON_FRAMEWORK_PATH}/share" share ln -s "${PYTHON_FRAMEWORK_PATH}/lib" lib -echo "Create additional symlinks (Required for the UsePythonVersion Azure Pipelines task and the setup-python GitHub Action)" +echo "Creating additional symlinks (Required for the UsePythonVersion Azure Pipelines task and the setup-python GitHub Action)" ln -s ./bin/$PYTHON_MAJOR_DOT_MINOR python cd bin/ @@ -73,8 +94,8 @@ export PIP_ROOT_USER_ACTION=ignore ./python -m ensurepip ./python -m pip install --upgrade --force-reinstall pip --disable-pip-version-check --no-warn-script-location -echo "Install OpenSSL certificates" +echo "Installing OpenSSL certificates" sh -e "${PYTHON_APPLICATION_PATH}/Install Certificates.command" -echo "Create complete file" +echo "Creating complete file" touch $PYTHON_TOOLCACHE_VERSION_PATH/${ARCH}.complete From bbc60cfaec81aea46b2d2727d4006a1da6e67910 Mon Sep 17 00:00:00 2001 From: aparnajyothi-y <147696841+aparnajyothi-y@users.noreply.github.com> Date: Mon, 2 Dec 2024 17:25:45 +0530 Subject: [PATCH 8/8] Update macos-pkg-setup-template.sh --- installers/macos-pkg-setup-template.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/installers/macos-pkg-setup-template.sh b/installers/macos-pkg-setup-template.sh index c31c070d..ab572bcc 100644 --- a/installers/macos-pkg-setup-template.sh +++ b/installers/macos-pkg-setup-template.sh @@ -23,7 +23,7 @@ PYTHON_TOOLCACHE_VERSION_ARCH_PATH=$PYTHON_TOOLCACHE_VERSION_PATH/$ARCH PYTHON_FRAMEWORK_PATH="/Library/Frameworks/Python.framework/Versions/${MAJOR_VERSION}.${MINOR_VERSION}" PYTHON_APPLICATION_PATH="/Applications/Python ${MAJOR_VERSION}.${MINOR_VERSION}" -# Check if Python dependencies are installed (e.g., zlib) +# Check if zlib is installed echo "Checking if zlib is installed..." if ! brew list zlib &>/dev/null; then echo "Installing zlib via brew..." @@ -44,6 +44,7 @@ if [ "$MAJOR_VERSION" -eq 3 ] && [ "$MINOR_VERSION" -eq 7 ] && [ "$PYTHON_FULL_V echo "zlib linked at ${ZLIB_PREFIX}/lib" fi +# Check if Python hostedtoolcache folder exists... echo "Check if Python hostedtoolcache folder exists..." if [ ! -d $PYTHON_TOOLCACHE_PATH ]; then echo "Creating Python hostedtoolcache folder..."