Skip to content

Enable linking multiple Python formulae#107517

Closed
carlocab wants to merge 10 commits intoHomebrew:masterfrom
carlocab:link-all-pythons
Closed

Enable linking multiple Python formulae#107517
carlocab wants to merge 10 commits intoHomebrew:masterfrom
carlocab:link-all-pythons

Conversation

@carlocab
Copy link
Copy Markdown
Member

@carlocab carlocab commented Aug 7, 2022

  • python@3.9: use altinstall target
  • python@3.10: link into HOMEBREW_PREFIX
  • python@3.9: cleanup
  • python@3.10: cleanup
  • Update Python aliases
  • versioned_keg_only_allowlist: add Python 3.10

The primary change (see first commit) uses the altinstall target in the Python Makefile to make sure that Python3.9 only installs files that contain Python's major and minor version. That is, python@3.9 will now install only python3.9, python3.9-config, etc., instead of python3 and python3-config.

This will allow users to have both python@3.9 and python@3.10 linked into HOMEBREW_PREFIX simultaneously. Users who wish to call python3.9 as python3 can add libexec/"bin" to their PATH.

Going forward, I believe this will help simplify migrating to newer Python versions, since there will be no need to make the newer version keg-only while most dependent formulae still depend on the older version of Python.

I've made a lot of changes here. For ease of review, I placed substantive changes in the first two commits. The third and fourth commits are refactoring, and the last two fifth and sixth update non-formula files.

I have not tested this on Linux. This may require a few more adjustments there.

See discussion at Homebrew/discussions#2776 and documentation at https://github.com/python/cpython#installing-multiple-versions.

Closes #87075.


  • Have you followed the guidelines for contributing?
  • Have you ensured that your commits follow the commit style guide?
  • Have you checked that there aren't other open pull requests for the same formula update/change?
  • Have you built your formula locally with brew install --build-from-source <formula>, where <formula> is the name of the formula you're submitting?
  • Is your test running fine brew test <formula>, where <formula> is the name of the formula you're submitting?
  • Does your build pass brew audit --strict <formula> (after doing brew install --build-from-source <formula>)? If this is a new formula, does it pass brew audit --new <formula>?

@BrewTestBot BrewTestBot added the automerge-skip `brew pr-automerge` will skip this pull request label Aug 7, 2022
@carlocab carlocab mentioned this pull request Aug 7, 2022
6 tasks
@carlocab carlocab requested a review from a team August 7, 2022 06:26
@carlocab carlocab force-pushed the link-all-pythons branch 6 times, most recently from a56c57e to 6598029 Compare August 7, 2022 09:22
@carlocab carlocab force-pushed the link-all-pythons branch 2 times, most recently from b19b708 to 5a5f61a Compare August 7, 2022 09:36
@carlocab

This comment was marked as resolved.

@carlocab carlocab added long build Set a long timeout for formula testing CI-no-fail-fast Continue CI tests despite failing GitHub Actions matrix builds. CI-linux-self-hosted Build on Linux self-hosted runner labels Aug 7, 2022
Copy link
Copy Markdown
Member

@Rylan12 Rylan12 left a comment

Choose a reason for hiding this comment

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

Doesn't this mean that if you run brew install python@3.9 (no alias so no auto upgrade to python@3.10) and then have a script that relies on /opt/homebrew/bin/python3 it will no longer work unless you manually install python@3.10?

@carlocab
Copy link
Copy Markdown
Member Author

carlocab commented Aug 7, 2022

Doesn't this mean that if you run brew install python@3.9 (no alias so no auto upgrade to python@3.10) and then have a script that relies on /opt/homebrew/bin/python3 it will no longer work unless you manually install python@3.10?

Yes. But the same thing happens whenever we make python@3.9 keg-only and link python@3.10, so the way we've been handling this so far has the same problem.

@carlocab carlocab added do not merge CI-skip-recursive-dependents Pass --skip-recursive-dependents to brew test-bot. CI-skip-dependents Pass --skip-dependents to brew test-bot. and removed CI-linux-self-hosted Build on Linux self-hosted runner long build Set a long timeout for formula testing labels Aug 8, 2022
Comment on lines 456 to 465
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@Rylan12 this should help a bit with users who really just want python3 (of whatever version) but did brew install python@3.9.

It won't make it go away, since not everyone reads the caveats, but it should help a bit.

@carlocab
Copy link
Copy Markdown
Member Author

carlocab commented Aug 10, 2022

@carlocab carlocab mentioned this pull request Aug 10, 2022
6 tasks
@carlocab
Copy link
Copy Markdown
Member Author

swift test error is:

  'swiftpmtest': error: invalidManifestFormat("<unknown>:0: error: module \'_Builtin_stddef_max_align_t\' is defined in both \'/var/folders/_0/bwq744sj55n9b7yxj53j1rxw0000gq/C/clang/ModuleCache/OVVET4YQAF2U/_Builtin_stddef_max_align_t-2S6J4W9HHDZWV.pcm\' and \'/var/folders/_0/bwq744sj55n9b7yxj53j1rxw0000gq/C/clang/ModuleCache/OVVET4YQAF2U/_Builtin_stddef_max_align_t-E8YDO9UD74YG.pcm\'\n/private/tmp/swift-test-20220809-75938-1pkfhpt/swiftpmtest/Package.swift:4:8: error: failed to build module \'PackageDescription\' for importation due to the errors above; the textual interface may be broken by project issues or a compiler bug\nimport PackageDescription\n       ^", diagnosticFile: nil)

https://github.com/Homebrew/homebrew-core/runs/7748711279?check_suite_focus=true#step:10:6888

Seems unrelated to Python, but not certain. Any ideas, @Bo98?

@Bo98
Copy link
Copy Markdown
Member

Bo98 commented Aug 10, 2022

Probably a bad file in that machine's module cache. That's annoying. It shouldn't affect ephemeral at least.

I do pass a custom -module-cache-path in the tests to avoid issues like that, but we probably need it for the SwiftPM tests too. We could abuse this: https://github.com/apple/swift-package-manager/blob/release/5.6/Sources/PackageLoading/ManifestLoader.swift#L775

Before the SwiftPM test, try ENV["SWIFTPM_MODULECACHE_OVERRIDE"] = module_cache.

@carlocab
Copy link
Copy Markdown
Member Author

I plan to rebase, update resources, and re-run this as soon as #107645 is merged. The other fixes look like they'll take a bit longer.

carlocab and others added 10 commits August 11, 2022 18:09
This makes sure that Python does not install major-versioned files (e.g.
`python3`, `python3-config`) and instead only installs files with both a
major and minor version (e.g. `python3.9`, `python3.9-config`).

This will allow us to have multiple versions of Python linked into
`HOMEBREW_PREFIX` without conflicts.

If users want to call `python3.9` as `python3`, then they can add
`libexec/"bin"` to their `PATH`.

Going forward, this will help simplify migrating to newer versions of
Python, since we will not need to make the newer version keg-only while
dependent formulae are migrated.

See discussion at Homebrew/discussions#2776, and documentation at

    https://github.com/python/cpython#installing-multiple-versions

Closes Homebrew#87075.
The previous commit minimises the conflict between `python@3.9` and
`python@3.10`. The rest is handled by the `link_overwrite` lines.
Previous changes allow Python 3.9 and Python 3.10 to be linked at the
same time.
Co-authored-by: XuehaiPan <XuehaiPan@pku.edu.cn>
Co-authored-by: XuehaiPan <XuehaiPan@pku.edu.cn>
@carlocab
Copy link
Copy Markdown
Member Author

carlocab commented Aug 11, 2022

This is ready for review.

Some dependents will still fail, but all failures should have fixes in progress. See #107517 (comment).

I hope to be able to merge this once CI completes.

Copy link
Copy Markdown
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

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

Makes sense to me. One small question.

link_overwrite "Frameworks/Python.framework/Headers"
link_overwrite "Frameworks/Python.framework/Python"
link_overwrite "Frameworks/Python.framework/Resources"
link_overwrite "Frameworks/Python.framework/Versions/Current"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does this mean whichever version is linked last will be Current?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I contemplated that, but found it too confusing, so decided against it.

In this PR, only the newest Python in Homebrew/core (i.e. python@3.10) will have these symlinks.

I would like to find a way to do it so that the newest Python you have installed will have these symlinks, so that the behaviour is consistent and predictable, but im punting on that for now.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I contemplated that, but found it too confusing, so decided against it.

Agreed, I think it's better this way.

In this PR, only the newest Python in Homebrew/core (i.e. python@3.10) will have these symlinks.

How do we ensure these get updated/migrated on a new Python version? Audit? Could do something like fail if the alias doesn't point to python.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

How do we ensure these get updated/migrated on a new Python version? Audit? Could do something like fail if the alias doesn't point to python.

Yup, we should add an audit for this. Will look at one soon.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@carlocab Sounds great, doesn't need to block this PR 👍🏻

@BrewTestBot
Copy link
Copy Markdown
Contributor

:shipit: @carlocab has triggered a merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automerge-skip `brew pr-automerge` will skip this pull request CI-linux-self-hosted Build on Linux self-hosted runner CI-no-fail-fast Continue CI tests despite failing GitHub Actions matrix builds. long build Set a long timeout for formula testing python-3.10-migration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants