Bug#695958: python2.7: Expose multiarch triplet in sys module

2012-12-20 Thread Barry Warsaw
On Dec 19, 2012, at 11:57 PM, Matthias Klose wrote:

hard-coding gcc is wrong. you should use CC and have this code at a position
where it's clear which CC to use.

if this patch is debian local, you can drop the dpkg-architecture check.

This is actually much simpler than I first though.  We already have a patch to
calculate `gcc -print-multiarch` in configure.ac and it's already stashed in
the MULTIARCH autoconf variable.

So really, all my patch needs to do is to expose that in the sys module.

_architecture is a bad name. just name it _multiarch, or obfuscate it even
more (a name longer than single_version_externally_managed would be
preferred).

sys.implementation._multiarch is fine.

Make sure that the tuple ends up in _sysconfigdata.py with a
sensible name, e.g. HOST_MULTIARCH. The latter one can be overwritten for
cross builds (once the 3.3 cross build changes are backported), and should be
the preferred way to access this information.

It's already there :)

$ python3.3 -c import _sysconfigdata; 
print(_sysconfigdata.build_time_vars['MULTIARCH'])
x86_64-linux-gnu
$ python2.7 -c import _sysconfigdata; 
print(_sysconfigdata.build_time_vars['MULTIARCH'])
x86_64-linux-gnu

Updated patch attached.
=== modified file 'debian/changelog'
--- debian/changelog	2012-12-10 19:10:32 +
+++ debian/changelog	2012-12-20 15:10:49 +
@@ -1,3 +1,10 @@
+python2.7 (2.7.3-13) experimental; urgency=low
+
+  * debian/patches/sys-multiarch.diff: Expose multiarch triplet as
+sys._multiarch.  Closes: #695958
+
+ -- Barry Warsaw ba...@python.org  Thu, 20 Dec 2012 08:53:42 -0500
+
 python2.7 (2.7.3-12) experimental; urgency=low
 
   * Fix typo in pkgconfig file. Closes: #695671, LP: #1088988.

=== modified file 'debian/patches/series.in'
--- debian/patches/series.in	2012-12-10 16:06:41 +
+++ debian/patches/series.in	2012-12-20 15:10:49 +
@@ -66,3 +66,4 @@
 lib2to3-no-pickled-grammar.diff
 add-python-config-sh.diff
 ssl.match_hostname.diff
+sys-multiarch.diff

=== added file 'debian/patches/sys-multiarch.diff'
--- debian/patches/sys-multiarch.diff	1970-01-01 00:00:00 +
+++ debian/patches/sys-multiarch.diff	2012-12-20 15:10:49 +
@@ -0,0 +1,25 @@
+--- a/Makefile.pre.in
 b/Makefile.pre.in
+@@ -1304,6 +1304,11 @@
+ 
+ Python/thread.o: @THREADHEADERS@
+ 
++Python/sysmodule.o: $(srcdir)/Python/sysmodule.c Makefile
++	$(CC) -c $(PY_CORE_CFLAGS) \
++		-DMULTIARCH='$(MULTIARCH)' \
++		-o $@ $(srcdir)/Python/sysmodule.c
++
+ # Declare targets that aren't real files
+ .PHONY: all build_all sharedmods oldsharedmods test quicktest memtest
+ .PHONY: install altinstall oldsharedinstall bininstall altbininstall
+--- a/Python/sysmodule.c
 b/Python/sysmodule.c
+@@ -1435,6 +1435,8 @@
+ PyFloat_GetInfo());
+ SET_SYS_FROM_STRING(long_info,
+ PyLong_GetInfo());
++SET_SYS_FROM_STRING(_multiarch,
++PyString_FromString(MULTIARCH));
+ #ifdef Py_USING_UNICODE
+ SET_SYS_FROM_STRING(maxunicode,
+ PyInt_FromLong(PyUnicode_GetMax()));

=== modified file 'debian/changelog'
--- debian/changelog	2012-12-10 19:10:32 +
+++ debian/changelog	2012-12-20 15:10:49 +
@@ -1,3 +1,10 @@
+python2.7 (2.7.3-13) experimental; urgency=low
+
+  * debian/patches/sys-multiarch.diff: Expose multiarch triplet as
+sys._multiarch.  Closes: #695958
+
+ -- Barry Warsaw ba...@python.org  Thu, 20 Dec 2012 08:53:42 -0500
+
 python2.7 (2.7.3-12) experimental; urgency=low
 
   * Fix typo in pkgconfig file. Closes: #695671, LP: #1088988.

=== modified file 'debian/patches/series.in'
--- debian/patches/series.in	2012-12-10 16:06:41 +
+++ debian/patches/series.in	2012-12-20 15:10:49 +
@@ -66,3 +66,4 @@
 lib2to3-no-pickled-grammar.diff
 add-python-config-sh.diff
 ssl.match_hostname.diff
+sys-multiarch.diff

=== added file 'debian/patches/sys-multiarch.diff'
--- debian/patches/sys-multiarch.diff	1970-01-01 00:00:00 +
+++ debian/patches/sys-multiarch.diff	2012-12-20 15:10:49 +
@@ -0,0 +1,25 @@
+--- a/Makefile.pre.in
 b/Makefile.pre.in
+@@ -1304,6 +1304,11 @@
+ 
+ Python/thread.o: @THREADHEADERS@
+ 
++Python/sysmodule.o: $(srcdir)/Python/sysmodule.c Makefile
++	$(CC) -c $(PY_CORE_CFLAGS) \
++		-DMULTIARCH='$(MULTIARCH)' \
++		-o $@ $(srcdir)/Python/sysmodule.c
++
+ # Declare targets that aren't real files
+ .PHONY: all build_all sharedmods oldsharedmods test quicktest memtest
+ .PHONY: install altinstall oldsharedinstall bininstall altbininstall
+--- a/Python/sysmodule.c
 b/Python/sysmodule.c
+@@ -1435,6 +1435,8 @@
+ PyFloat_GetInfo());
+ SET_SYS_FROM_STRING(long_info,
+ PyLong_GetInfo());
++SET_SYS_FROM_STRING(_multiarch,
++PyString_FromString(MULTIARCH));
+ #ifdef Py_USING_UNICODE
+ SET_SYS_FROM_STRING(maxunicode,
+ PyInt_FromLong(PyUnicode_GetMax()));



signature.asc
Description: PGP signature


Bug#695958: python2.7: Expose multiarch triplet in sys module

2012-12-19 Thread Jakub Wilk

* Barry Warsaw ba...@python.org, 2012-12-14, 16:29:

++dnl Debian multiarch support in sys.implementation._architecture
++dnl Try `dpkg-architecture -qDEB_BUILD_MULTIARCH` first, then
++dnl `gcc --print-multiarch`.
++AC_SUBST(MULTIARCH_BUILD)
++AC_CHECK_PROG(HAS_DPKG_ARCHITECTURE, dpkg-architecture, found, not-found)
++if test $HAS_DPKG_ARCHITECTURE = found
++then
++MULTIARCH_BUILD=dpkg-architecture -qDEB_BUILD_MULTIARCH
++else
++AC_CHECK_PROG(HAS_GCC_FOR_ARCH, gcc, found, not-found)
++if test $HAS_GCC_FOR_ARCH = found
++then
++MULTIARCH_BUILD=gcc --print-multiarch
++else
++MULTIARCH_BUILD=
++fi
++fi


s/DEB_BUILD_MULTIARCH/DEB_HOST_MULTIARCH/ presumably?

--
Jakub Wilk


--
To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org



Bug#695958: python2.7: Expose multiarch triplet in sys module

2012-12-19 Thread Barry Warsaw
On Dec 19, 2012, at 12:50 PM, Jakub Wilk wrote:

* Barry Warsaw ba...@python.org, 2012-12-14, 16:29:
++dnl Debian multiarch support in sys.implementation._architecture
++dnl Try `dpkg-architecture -qDEB_BUILD_MULTIARCH` first, then
++dnl `gcc --print-multiarch`.
++AC_SUBST(MULTIARCH_BUILD)
++AC_CHECK_PROG(HAS_DPKG_ARCHITECTURE, dpkg-architecture, found, not-found)
++if test $HAS_DPKG_ARCHITECTURE = found
++then
++MULTIARCH_BUILD=dpkg-architecture -qDEB_BUILD_MULTIARCH
++else
++AC_CHECK_PROG(HAS_GCC_FOR_ARCH, gcc, found, not-found)
++if test $HAS_GCC_FOR_ARCH = found
++then
++MULTIARCH_BUILD=gcc --print-multiarch
++else
++MULTIARCH_BUILD=
++fi
++fi

s/DEB_BUILD_MULTIARCH/DEB_HOST_MULTIARCH/ presumably?

Yes, I think you're right.  Thanks.

(Does it make sense to expose the other dpkg-architecture stuff, or should we
just keep it simple?)


signature.asc
Description: PGP signature


Bug#695958: python2.7: Expose multiarch triplet in sys module

2012-12-19 Thread Matthias Klose
Am 19.12.2012 21:30, schrieb Barry Warsaw:
 On Dec 19, 2012, at 12:50 PM, Jakub Wilk wrote:
 
 * Barry Warsaw ba...@python.org, 2012-12-14, 16:29:
 ++dnl Debian multiarch support in sys.implementation._architecture 
 ++dnl Try `dpkg-architecture -qDEB_BUILD_MULTIARCH` first, then ++dnl
 `gcc --print-multiarch`. ++AC_SUBST(MULTIARCH_BUILD) 
 ++AC_CHECK_PROG(HAS_DPKG_ARCHITECTURE, dpkg-architecture, found,
 not-found) ++if test $HAS_DPKG_ARCHITECTURE = found ++then ++
 MULTIARCH_BUILD=dpkg-architecture -qDEB_BUILD_MULTIARCH ++else ++
 AC_CHECK_PROG(HAS_GCC_FOR_ARCH, gcc, found, not-found) ++if test
 $HAS_GCC_FOR_ARCH = found ++then ++MULTIARCH_BUILD=gcc
 --print-multiarch ++else ++MULTIARCH_BUILD= ++fi 
 ++fi
 
 s/DEB_BUILD_MULTIARCH/DEB_HOST_MULTIARCH/ presumably?
 
 Yes, I think you're right.  Thanks.
 
 (Does it make sense to expose the other dpkg-architecture stuff, or should
 we just keep it simple?)

hard-coding gcc is wrong. you should use CC and have this code at a position
where it's clear which CC to use.

if this patch is debian local, you can drop the dpkg-architecture check.

_architecture is a bad name. just name it _multiarch, or obfuscate it even
more (a name longer than single_version_externally_managed would be
preferred). Make sure that the tuple ends up in _sysconfigdata.py with a
sensible name, e.g. HOST_MULTIARCH. The latter one can be overwritten for
cross builds (once the 3.3 cross build changes are backported), and should be
the preferred way to access this information.

  Matthias


-- 
To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org



Bug#695958: python2.7: Expose multiarch triplet in sys module

2012-12-14 Thread Barry Warsaw
Package: python2.7
Version: 2.7.3~rc2-2.1
Severity: normal

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA256

Dear Maintainer,

We have several cases where the multiarch triplet is needed for the
proper building or functioning of other Python modules or
applications.  A recent example is virtualenv.  In the debian-python
mailing list, several solutions for the virtualenv problem have been
discussed, but all of them are unsatisfying.

What we really need is an officially approved, common way of getting
the triplet, that doesn't require shelling out or globbing the file
system.  When Python is built, it already knows (or can easily find
out) what the triplet should be, so it's best if we expose this in the
sys module.

Attached is a patch similar to one discussed on debian-python.  It
exposes the triplet as `sys._architecture`.  A similar patch will be
made available for Python 3.3, except that there, it will be avialable
under `sys.implementation._architecture` as per PEP 421.  Bilingual
Python code can use:

 import sys
 getattr(sys, 'implementation', sys)._architecture

Cheers.


- -- System Information:
Debian Release: wheezy/sid
  APT prefers testing
  APT policy: (500, 'testing')
Architecture: amd64 (x86_64)

Kernel: Linux 3.2.0-4-amd64 (SMP w/1 CPU core)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash

Versions of packages python2.7 depends on:
ii  libbz2-1.0 1.0.6-4
ii  libc6  2.13-37
ii  libdb5.1   5.1.29-5
ii  libexpat1  2.1.0-1
ii  libgcc11:4.7.2-4
ii  libncursesw5   5.9-10
ii  libreadline6   6.2-8
ii  libsqlite3-0   3.7.13-1
ii  libtinfo5  5.9-10
ii  mime-support   3.52-1
ii  python2.7-minimal  2.7.3~rc2-2.1

python2.7 recommends no packages.

Versions of packages python2.7 suggests:
ii  binutils   2.22-7.1
pn  python2.7-doc  none

- -- no debconf information

-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.12 (GNU/Linux)

iQIbBAEBCAAGBQJQy5pQAAoJEBJutWOnSwa/e1QP91RxE/xWAUKQvSM08BEZsmW6
J7NEgCOz5GNIM2nG2VxTL2L2s3dxNNODhMi9r35RrmgSeTkkiUmMiqpL5hKPiVMs
5bjIA/GHYfdZp3wt52qBA2KckvW9D0257QoMs+d5j0lHs/syijTPLGvg9qAJx70L
4SsjZSCnJ4aKpYvu8je8RKc2lzmsLBuY6NuIoIRbee0KhZoXwXwb0y0JNpUj7r2T
QlCiM9dh8OS2vMtiRmL27/jT1HWLnoT3tkBzkP/eaYP+wyhwbIsQ8q9Ltk5PtzMV
gX/N7sy8QnetNopILxAhmK+h0O9OoH5Is4WrF8USsAJeb8TWLmxOjTTlDmHGyIde
xOqj7hlhzc+uNzR/jB09j7Uszj7J0i0hunJadGCmCTk/OunY5Y+IKHBA78+JSNVI
hF8j81p6iTg1BNzrcrKAwzbkXFWD/bUgK85xBP1wdtm6srIKVyBfSw5eqiuAVfgw
SwLyhiqZPz+UeFXaSKgOGAYLW+do5qZdaQ64CbXTAjm5P/hZR7+xwfA0cnla9RT5
ZclZnHojln9uw/9i1mTMZ+278hnIbTzfzxRkmaNUmKN7VV0gDry9ltlUJtHsGb3C
Kn/jYSVsnSqCV06qm2x4Gei5sPqlVN/TpuvEssf5ZnK40mSVMKvTDnit9Gvmh/yU
viPWNZdWPBrqaSJ2gAc=
=2fr2
-END PGP SIGNATURE-
=== modified file 'debian/changelog'
--- debian/changelog	2012-12-10 19:10:32 +
+++ debian/changelog	2012-12-14 20:24:32 +
@@ -1,3 +1,10 @@
+python2.7 (2.7.3-13) experimental; urgency=low
+
+  * debian/patches/sys-implementation.diff: Expose multiarch triplet value
+as sys._architecture.
+
+ -- Barry Warsaw ba...@python.org  Fri, 14 Dec 2012 15:23:02 -0500
+
 python2.7 (2.7.3-12) experimental; urgency=low
 
   * Fix typo in pkgconfig file. Closes: #695671, LP: #1088988.

=== modified file 'debian/patches/series.in'
--- debian/patches/series.in	2012-12-10 16:06:41 +
+++ debian/patches/series.in	2012-12-14 20:24:32 +
@@ -66,3 +66,4 @@
 lib2to3-no-pickled-grammar.diff
 add-python-config-sh.diff
 ssl.match_hostname.diff
+sys-implementation.diff

=== added file 'debian/patches/sys-implementation.diff'
--- debian/patches/sys-implementation.diff	1970-01-01 00:00:00 +
+++ debian/patches/sys-implementation.diff	2012-12-14 20:24:32 +
@@ -0,0 +1,60 @@
+--- a/configure.ac
 b/configure.ac
+@@ -24,6 +24,24 @@
+ prefix=`echo $prefix | sed -e 's/\/$//g'`
+ fi
+ 
++dnl Debian multiarch support in sys.implementation._architecture
++dnl Try `dpkg-architecture -qDEB_BUILD_MULTIARCH` first, then
++dnl `gcc --print-multiarch`.
++AC_SUBST(MULTIARCH_BUILD)
++AC_CHECK_PROG(HAS_DPKG_ARCHITECTURE, dpkg-architecture, found, not-found)
++if test $HAS_DPKG_ARCHITECTURE = found
++then
++MULTIARCH_BUILD=dpkg-architecture -qDEB_BUILD_MULTIARCH
++else
++AC_CHECK_PROG(HAS_GCC_FOR_ARCH, gcc, found, not-found)
++if test $HAS_GCC_FOR_ARCH = found
++then
++MULTIARCH_BUILD=gcc --print-multiarch
++else
++MULTIARCH_BUILD=
++fi
++fi
++
+ dnl This is for stuff that absolutely must end up in pyconfig.h.
+ dnl Please use pyport.h instead, if possible.
+ AH_TOP([
+--- a/Makefile.pre.in
 b/Makefile.pre.in
+@@ -40,6 +40,7 @@
+ HGVERSION=	@HGVERSION@
+ HGTAG=		@HGTAG@
+ HGBRANCH=	@HGBRANCH@
++MULTIARCH_BUILD=	@MULTIARCH_BUILD@
+ 
+ GNULD=  @GNULD@
+ 
+@@ -1304,6 +1305,11 @@
+ 
+ Python/thread.o: @THREADHEADERS@
+ 
++Python/sysmodule.o: $(srcdir)/Python/sysmodule.c Makefile
++	$(CC) -c $(PY_CORE_CFLAGS) \
++		-DMULTIARCH_BUILD=\`LC_ALL=C