Subject: bug#35322: AM_PATH_PYTHON incompatible with Python frameworks on macOS

From: Karl Berry <[email-masked]>
Date: Fri, 19 Feb 2021 19:26:33 -0700

Thanks for the follow-up.

    a question of whether the goal is installing modules in a consistent
    location across different systems, or installing them somewhere
    where the python on this system will be able to find them.

Yes. Ordinarily, install directories in Automake are supposed to be the
same across systems. But from what you quoted from the manual:

    The documentation says that pythondir is "The directory name for the 
    site-packages subdirectory of the standard Python install tree."

.. I tend to think pythondir was intended to be, or at least could
reasonably be, an exception.

Looking at the patch again (content pasted below for the record):
https://github.com/macports/macports-ports/blob/master/devel/automake/files/patch-issue57329.diff

It seems too dangerous to me to apply as is, i.e., simply removing all
the $am_py_prefix values. That would change the results of
AM_PYTHON_PATH on every system. Maybe in a good way, but maybe not, and
I, at least, am not prepared to induce that level of incompatible
change.  People could have their build systems set up to define the
prefix to be their desired directory.

What I think would be safer to apply is a patch that eliminates those
am_py_prefix values only on Macs. I'm not sure if am_py_prefix can be
defined (only on Macs) to something in the code above that sets it:

    [if test "x$prefix" = xNONE
     then
       am_py_prefix=$ac_default_prefix
     else
       am_py_prefix=$prefix
     fi

i.e.: if <on mac> then am_py_prefix=$something ...
or if it's necessary to make all those sysconfig.* calls conditional on
the system.

Wdyt? Can you provide a modified patch in whatever way seems best?
--thanks, karl.

diff --git m4/python.m4 m4/python.m4
index 63c0a0e04..f81684378 100644
--- m4/python.m4
+++ m4/python.m4
@@ -147,10 +147,10 @@ except ImportError:
      am_cv_python_pythondir=`$PYTHON -c "
 $am_python_setup_sysconfig
 if can_use_sysconfig:
-    sitedir = sysconfig.get_path('purelib', vars={'base':'$am_py_prefix'})
+    sitedir = sysconfig.get_path('purelib')
 else:
     from distutils import sysconfig
-    sitedir = sysconfig.get_python_lib(0, 0, prefix='$am_py_prefix')
+    sitedir = sysconfig.get_python_lib(0, 0)
 sys.stdout.write(sitedir)"`
      case $am_cv_python_pythondir in
      $am_py_prefix*)
@@ -189,10 +189,10 @@ sys.stdout.write(sitedir)"`
      am_cv_python_pyexecdir=`$PYTHON -c "
 $am_python_setup_sysconfig
 if can_use_sysconfig:
-    sitedir = sysconfig.get_path('platlib', vars={'platbase':'$am_py_prefix'})
+    sitedir = sysconfig.get_path('platlib')
 else:
     from distutils import sysconfig
-    sitedir = sysconfig.get_python_lib(1, 0, prefix='$am_py_prefix')
+    sitedir = sysconfig.get_python_lib(1, 0)
 sys.stdout.write(sitedir)"`
      case $am_cv_python_pyexecdir in
      $am_py_exec_prefix*)