Simplifying Tcl/Tk detection

TL;DR: simplify Tcl/Tk detection to pkgconfig and basic autoconf headers/libs checks.

Background

@tiran and I have been rewriting stdlib extension module dependency detection in bpo-45847[1] and bpo-45573[2], partly sparked by Christian’s bpo-45743[3].

Proposal

I had a look a Ned’s comments in bpo-34956[4] and related commits; IIUC, trying to use the macOS bundled Tcl/Tk is not recommended, so why then do we try so hard (in setup.py) to locate it? How about simplifying it to this:

  • Replace TCLTK_INCLUDES with TCLTK_CFLAGS (for consistency)
  • Keep the --with-tcltk-* options
  • In configure:
    1. use pkgconfig to check for Tcl/Tk >= 8.4.2 (we’ll have to loop over the various namings here: tcl, tcl8.6, tcl84, etc.)
    2. fall back to standard AC check headers/libs
  • Reduce detect_tkinter in setup.py to one addext() line

pkgconfig should cover most *nix systems. Mac users should use Homebrew::

$ PKG_CONFIG_PATH=$(brew --prefix tcl-tk)/lib/pkgconfig pkg-config --cflags --libs tcl tk
-I/usr/local/Cellar/tcl-tk/8.6.12_1/include -L/usr/local/Cellar/tcl-tk/8.6.12_1/lib -ltk8.6 -ltkstub8.6 -ltcl8.6 -ltclstub8.6

Thoughts? cc. @nad, @ronaldoussoren


  1. Port module setup to PY_STDLIB_MOD macro and addext() ↩︎

  2. Use pkg-config autoconf macros to detect flags for Modules/Setup ↩︎

  3. Cleanup and simplify setup.py ↩︎

  4. _tkinter built on macOS 10.14 does not link to Tcl and Tk in /Library/Frameworks ↩︎

2 Likes

We should deprecate the TCLTK_* variables and just rely on pkg-config. That works with MacPorts as well. Write up a PR and we can review it there.

1 Like

Even better. I’ve got a WIP branch from a couple of months ago. I’ll dig it up and create a PR.

Thank you! :+1:

1 Like

We can drop support of 8.4, and maybe even 8.5.

1 Like

Nice! I’ll create a separate bpo for that, though.

Would the build continue to work without having pkg-config? The tool is not installed on macOS by default or through Xcode / Command Line Tools. Not everyone uses homebrew or macports.

You will be able to build Python without pkg-config, but some dependencies won’t be detected.

1 Like

I guess installing pkg-config isn’t too bad, one already has to install other libraries to get a full build (such as openssl).

BTW. I’m in favour of dropping support for the system install of Tcl/Tk, that library is ancient and broken. It is better to not have tkinter than one using the system version of Tk.

2 Likes

Great; I’ll keep the PR as it is, then.

1 Like

FTR, I’m talking about GH-31698

See also Issue 46996: Drop support of Tcl/Tk older than 8.5.12 - Python tracker.

1 Like