Skip to content

Conversation

charles-zablit
Copy link
Contributor

@charles-zablit charles-zablit commented Aug 1, 2025

This patch adds Embeddable Python 3.10.1 to build.ps1.

This is part of 2 other PRs which aim to package Python with the Swift toolchain installer on Windows:

This is a follow-up to this discussion on the forums.

rdar://157773554

@charles-zablit charles-zablit self-assigned this Aug 1, 2025
@charles-zablit charles-zablit added Windows Platform: Windows lldb labels Aug 1, 2025
@charles-zablit
Copy link
Contributor Author

@swift-ci please test

utils/build.ps1 Outdated
SHA256 = "353815f59a7f64cdaca1c0307ee13558a0512f6db064e92fe833784f08539c7a";
Dependencies = @();
};
"unittest2" = @{
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unittest2 is not compatible with python3.10+ since it's a back port of unittest. There is no need for it anymore.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets leave that in place until we have switched to 3.10 by default.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only references to unittest2 in the whole toolchain will be removed in swiftlang/llvm-project#11084. I think it's safe to remove it, as even the 3.9.10 version of Python comes with unittest.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, nice! In that case, we should split this change out and merge it whenever swiftlang/llvm-project#11084 gets merged.

Copy link
Contributor Author

@charles-zablit charles-zablit Aug 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

URL = "https://www.python.org/ftp/python/3.10.1/python-3.10.1-embed-arm64.zip";
SHA256 = "1f9e215fe4e8f22a8e8fba1859efb1426437044fb3103ce85794630e3b511bc2";
};
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets leave the definitions for 3.9, allowing to optionally upgrade to 3.10 while we iterate to get this working. That will allow you to make progress and get the changes merged earlier rather than trying to keep up to date with the changes in this script.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, thanks

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a particular reason that we need both the regular and the embedded URLs? Could we not get away with just the embedded?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, embeddable python does not come with pip. We could download and run get-pip.py, but I don't think we would gain a lot of CI time in doing so. I have not tried it out.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reasoning for the version selection here is not CI times but rather to match what llvm.org distributes. I think that we don't need to inject pip unless we are building the installer for distribution (i.e. nightlies/releases).

utils/build.ps1 Outdated
Copy-Item -Force `
-Path "$(Get-EmbeddedPythonPath $HostPlatform)\*" `
-Destination "$($HostPlatform.ToolchainInstallRoot)\usr\bin" `
-Recurse
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we don't want to embed the Python release. This was what we discussed on the forums - this should be an additional separate MSI that you are building and optionally installing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Embed was not the right choice of words. I want to put the files in a place where wix can find them for the follow up patch here: swiftlang/swift-installer-scripts#447

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that we should merge this into the toolchain. I think that we should be doing a separate installation: S:\Program Files\Swift\Python-3.10.1 for the image (the WiX authoring should be able to pick it up from there).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the latest revision, the python files are now extracted to S:\Program Files\Swift\Python. Do we really need the version number? Doing so would mean passing a new parameter to Wix to specify the files path right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer that we keep the version number. Upgrading python is something that would be rare, so I don't think that it is a big deal. We already have the information in build.ps1 where we can pass that down.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the Python version in the latest revision 👍

URL = "https://www.python.org/ftp/python/3.10.1/python-3.10.1-embed-arm64.zip";
SHA256 = "1f9e215fe4e8f22a8e8fba1859efb1426437044fb3103ce85794630e3b511bc2";
};
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a particular reason that we need both the regular and the embedded URLs? Could we not get away with just the embedded?

utils/build.ps1 Outdated
SHA256 = "353815f59a7f64cdaca1c0307ee13558a0512f6db064e92fe833784f08539c7a";
Dependencies = @();
};
"unittest2" = @{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, nice! In that case, we should split this change out and merge it whenever swiftlang/llvm-project#11084 gets merged.

return [IO.Path]::Combine("$BinaryCache\", "Python$($Platform.Architecture.CMakeName)-$PythonVersion")
}

function Get-EmbeddedPythonPath([Hashtable] $Platform) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, is there a bigger picture around the embedded vs non-embedded python that the extraction needs special logic?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only reason is pip missing in embeddedable python. We build with the regular Python, but we bundle the embeddable python in the installer.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There-in lies the trick! We can inject pip into the packaging :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think injecting pip would work well because of this SO comment, especially because the Python documentation explicitly states:

Using pip to manage dependencies as for a regular Python installation is not supported with this distribution [embeddable Python]

Given that, and the extra steps it would take to manually install pip with the embeddable python, I think it's simpler to:

  • Build with the regular Python
  • Test with the regular Python (easier to install dependencies)
  • Package the embeddable Python.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that we should just use a boolean state on the known dictionary rather than extract this. Overall, I'd like to see the python distribution to be complete enough for use in scripting (i.e. has pip).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that we should just use a boolean state on the known dictionary rather than extract this.

I'm not sure I understand what that boolean state would look like: would it be something like hasPip?

Overall, I'd like to see the python distribution to be complete enough for use in scripting (i.e. has pip).

I agree that it would be more convenient, however in that case, why not package a complete Python install? pip is not supported by embeddable Python: https://github.com/swiftlang/swift/pull/83488/files#r2254566330.

I see the Embeddable Python in the installer feature as a way for users to get a functional lldb whether they have the correct Python version installed or not. This is the main source of confusion for users: llvm/llvm-project#74073 (comment)

I think it's reasonable to expect power users who want to have scripting features to install Python themselves and have proper pip support rather than to risk using pip in an unsupported way with Embeddable Python.

"$($HostPlatform.ToolchainInstallRoot)\usr\lib\swift\windows\_InternalSwiftScan.lib" `
"$($HostPlatform.ToolchainInstallRoot)\usr\lib"
-Path "$($HostPlatform.ToolchainInstallRoot)\usr\lib\swift\windows\_InternalSwiftScan.lib" `
-Destination "$($HostPlatform.ToolchainInstallRoot)\usr\lib"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The named parameters are a nice cleanup; we could split those out and merge them as a cleanup before even getting the python 3.10.1 upgrade completed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened #83517 to split the changes 👍

@charles-zablit charles-zablit force-pushed the charles-zablit/windows/upgrade-python-to-3.10 branch 3 times, most recently from 1fc553e to 7d3fdec Compare August 8, 2025 15:44
@charles-zablit charles-zablit force-pushed the charles-zablit/windows/upgrade-python-to-3.10 branch 2 times, most recently from 800ed49 to baf0b97 Compare September 8, 2025 15:14
@charles-zablit charles-zablit force-pushed the charles-zablit/windows/upgrade-python-to-3.10 branch from baf0b97 to 2b42dd6 Compare October 6, 2025 15:50
@charles-zablit
Copy link
Contributor Author

@swift-ci please smoke test

Comment on lines +1289 to +1292
if ($null -eq $Python) {
Write-Output "Python $PythonVersion does not have an embeddable version."
return
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that we should handle this similarly to Install-Python.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I'm not sure I understand: the 2 functions are identical to me apart from the if ($null -eq $Python) { check.

return [IO.Path]::Combine("$BinaryCache\", "Python$($Platform.Architecture.CMakeName)-$PythonVersion")
}

function Get-EmbeddedPythonPath([Hashtable] $Platform) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that we should just use a boolean state on the known dictionary rather than extract this. Overall, I'd like to see the python distribution to be complete enough for use in scripting (i.e. has pip).

@charles-zablit charles-zablit changed the title [windows] upgrade to Python 3.10.1 embeddable [windows] add Embeddable Python 3.10.1 to build.ps1 Oct 6, 2025
@charles-zablit charles-zablit force-pushed the charles-zablit/windows/upgrade-python-to-3.10 branch from 2b42dd6 to a83efe5 Compare October 8, 2025 15:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lldb Windows Platform: Windows
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants