[bug#54412] [PATCH] python: use the posix_prefix sysconfig scheme on Debian

2022-03-16 Thread stefanor
Hi Karl (2022.03.16_21:25:45_+)

> Stefano, Gianfranco - thanks for this. Forgive my ignorance, but I don't
> use Debian, or Python, and have never the term "sysconfig scheme" before.
Compare these:

$ python3.9 -m sysconfig
Current installation scheme: "posix_prefix"

Paths: 
data = "/usr"
include = "/usr/include/python3.9"
platinclude = "/usr/include/python3.9"
platlib = "/usr/lib/python3.9/site-packages"
platstdlib = "/usr/lib/python3.9"
purelib = "/usr/lib/python3.9/site-packages"
scripts = "/usr/bin"
stdlib = "/usr/lib/python3.9"
...
prefix = "/usr"
...

To this:
$ python3.10 -m sysconfig
Current installation scheme: "posix_local"

Paths: 
data = "/usr/local"
include = "/usr/local/include/python3.10"
platinclude = "/usr/local/include/python3.10"
platlib = "/usr/local/lib/python3.10/dist-packages"
platstdlib = "/usr/lib/python3.10"
purelib = "/usr/local/lib/python3.10/dist-packages"
scripts = "/usr/local/bin"
stdlib = "/usr/lib/python3.10"
...
prefix = "/usr"
...

The "posix_local" scheme uses {prefix}/local/lib/... That's the issue.

> Does your patch change the default behavior of Automake? I gather not,
> but ...

This patch restores the previous (pre 3.10) behaviour. If you use --prefix
/usr, it installs modules to /usr, with --prefix /usr/local, it installs to
/usr/local.

> Also, it feels like there should be some documentation about this.
> Can you write something brief? --thanks, karl.

I think it shouldn't affect users. If anything needs to be documented, it's:
Automake will select the posix_prefix scheme instead of posix_local, on Debian
Python 3.10+. To install modules into /usr/local, instead of /usr, use --prefix
/usr/local.

SR

-- 
Stefano Rivera
  http://tumbleweed.org.za/
  +1 415 683 3272





[bug#54412] [PATCH] python: use the posix_prefix sysconfig scheme on Debian

2022-03-18 Thread stefanor
Hi Karl (2022.03.16_21:25:45_+)

Oops, somehow I missed that this patch failed on older versions of
cPython. This version is compatible back to 2.7.4.

SR

-- 
Stefano Rivera
  http://tumbleweed.org.za/
  +1 415 683 3272
From b07451795dc4626ca348cd1fd743d41a87daca61 Mon Sep 17 00:00:00 2001
From: Stefano Rivera 
Date: Tue, 15 Mar 2022 19:08:55 -0400
Subject: [PATCH] python: use the posix_prefix sysconfig scheme on Debian

Fixes Debian's bug: https://bugs.debian.org/1006784

Debian adds a custom sysconfig scheme to system python installs,
"posix_local". This is the default scheme, and it redirects local users'
Python module installs to /usr/local even though Python is installed
with a /usr prefix. Both are on Debian's python's sys.path module search
path.

Automake and its users understand prefixes, and are likely to select
/usr/local, explicitly. Select the "posix_prefix" scheme, with the
user-supplied prefix.

Previously this custom sysconfig scheme was specified in
distutils.sysconfig, but not sysconfig itself. As distutils is being
deprecated, the custom scheme is now specified in sysconfig, since
Debian's Python 3.10 (3.10.2-4).

Thank you, Gianfranco Costamagna , for porting
the patch to automake.

* m4/python.m4: use the posix_prefix sysconfig scheme on Debian

Copyright-paperwork-exempt: yes
---
 m4/python.m4 | 18 --
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/m4/python.m4 b/m4/python.m4
index 6653e4d89..b44d8ba55 100644
--- a/m4/python.m4
+++ b/m4/python.m4
@@ -255,7 +255,14 @@ 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'})
+  if hasattr(sysconfig, 'get_default_scheme'):
+scheme = sysconfig.get_default_scheme()
+  else:
+scheme = sysconfig._get_default_scheme()
+  if scheme == 'posix_local':
+# Debian's default scheme installs to /usr/local/ but we want to find headers in /usr/
+scheme = 'posix_prefix'
+  sitedir = sysconfig.get_path('purelib', scheme, vars={'base':'$am_py_prefix'})
 else:
   from distutils import sysconfig
   sitedir = sysconfig.get_python_lib(0, 0, prefix='$am_py_prefix')
@@ -297,7 +304,14 @@ 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_exec_prefix'})
+  if hasattr(sysconfig, 'get_default_scheme'):
+scheme = sysconfig.get_default_scheme()
+  else:
+scheme = sysconfig._get_default_scheme()
+  if scheme == 'posix_local':
+# Debian's default scheme installs to /usr/local/ but we want to find headers in /usr/
+scheme = 'posix_prefix'
+  sitedir = sysconfig.get_path('platlib', scheme, vars={'platbase':'$am_py_exec_prefix'})
 else:
   from distutils import sysconfig
   sitedir = sysconfig.get_python_lib(1, 0, prefix='$am_py_exec_prefix')
-- 
2.35.1



[bug#54412] [PATCH] python: use the posix_prefix sysconfig scheme on Debian

2024-01-17 Thread stefanor
Hi Karl (2024.01.17_22:48:30_+)
> Gianfranoc, Stefano - thanks much for the patch wrt Automake and Debian
> Python posix_local vs. posix_prefix. Below is what I installed -- the
> code change is substantively the same as what you wrote; I just took the
> extra try..catch that Bogdan added.
> 
> I changed the paragraph in the manual about pythondir. If you could look
> at it, that would be great. Is it correct that the basic idea is that,
> with this change, Automake again follows --prefix (and related) + using
> site-packages instead of Debian's defaults of /usr/local and
> dist-packages? --thanks, karl.

Thanks for the review.

You're right about that being a part of this patch. I didn't put much
thought into that bit, because in the context of Debian package builds,
it's inconsequential. (Our Python package tooling will find things that
got installed into site-packages and move them into dist-packages.)

This patch does have the effect of moving the installation destination
from dist-packages to site-packages. But previously (before this patch
was needed) Debian's sysconfig module wasn't patched to know about
dist-packages. So, if we are comparing to that point in time, this is
returning automake behaviour back to what it used to be.

Improving on that gets tricky.

Installs into /usr/local should go into
/usr/local/lib/pythonX.Y/dist-packages.
This is what the posix_local scheme will provide, no matter what prefix
it is specified.

Installs into /usr/ shouldn't happen on a Debian system, outside a
Debian package build. But there, they should go into
/usr/lib/python3/dist-packages.
This is what the deb_system scheme will provide, no matter what prefix
is specified.

Using the posix_prefix scheme was a lazy way to use the prefix, and
restore the old behaviour.

We could special-case both the '/usr' and '/usr/local' prefixes and
select 'posix_local' and 'deb_system' schemes, as appropriate. The logic
would boil down to:

if default_scheme == 'posix_local':  # Debian
   if prefix == '/usr':
   scheme = 'deb_system'  # Should only happen during Debian package builds
   elif prefix != '/usr/local':
   scheme = 'posix_prefix'

How does that sound?

Stefano

-- 
Stefano Rivera
  http://tumbleweed.org.za/
  +1 415 683 3272





[bug#54412] [PATCH] python: use the posix_prefix sysconfig scheme on Debian

2024-01-18 Thread stefanor
Hi Karl (2024.01.18_22:58:30_+)
> if default_scheme == 'posix_local':  # Debian
> 
> posix_local only exists on Debian, not any other system?
> The name is generic.

Yes, it's a Debianism. It was the best way to get "setup.py install" to
direct to /usr/local by default, on Debian systems, at the time. And
we've had to carry that API since.

> In any case, I guess it would be safe if it's possible to check if the
> deb_system scheme exists, and only do the special casing if both
> posix_local and deb_system are present.

Yeah that sounds nice and safe. But I'm not aware of anyone else using
posix_local.

Stefano

-- 
Stefano Rivera
  http://tumbleweed.org.za/
  +1 415 683 3272