Thread: BUG #6633: PL/Python build does not honor PYTHON on Mac OS X

BUG #6633: PL/Python build does not honor PYTHON on Mac OS X

From
clay@daemons.net
Date:
The following bug has been logged on the website:

Bug reference:      6633
Logged by:          Clay McClure
Email address:      clay@daemons.net
PostgreSQL version: 9.1.3
Operating system:   Darwin / Mac OS X 10.7.3 (Lion)
Description:=20=20=20=20=20=20=20=20

According to the installation documentation, one can set the PYTHON
environment variable to control which python is used to build PL/Python, but
this does not work correctly on Mac OS X.

The configure script correctly sets python_libspec based on the PYTHON
environment variable, but the plpython Makefile clobbers that value:

# Darwin (OS X) has its own ideas about how to do this.
ifeq ($(PORTNAME), darwin)
shared_libpython =3D yes
override python_libspec =3D -framework Python
override python_additional_libs =3D
endif

According to a Homebrew bug report
(https://github.com/mxcl/homebrew/issues/11162):

"You should submit a bug report to PostgreSQL as they can't assume Python is
always built as a Framework on Darwin. They should be using python-config to
get the gory details."

Re: BUG #6633: PL/Python build does not honor PYTHON on Mac OS X

From
Tom Lane
Date:
clay@daemons.net writes:
> According to a Homebrew bug report
> (https://github.com/mxcl/homebrew/issues/11162):
> "You should submit a bug report to PostgreSQL as they can't assume Python is
> always built as a Framework on Darwin. They should be using python-config to
> get the gory details."

Hmm ... on my Mac,

$ python-config
Usage: /usr/bin/python-config [--prefix|--exec-prefix|--includes|--libs|--cflags|--ldflags|--help]

None of those options produce anything including "-framework Python".
So I think your upstream needs to clarify to us benighted database geeks
exactly how this needs to be done, in such a way that it doesn't break
the existing working cases while fixing their case.

            regards, tom lane

Re: BUG #6633: PL/Python build does not honor PYTHON on Mac OS X

From
Clay McClure
Date:
On Tue, May 8, 2012 at 1:42 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

> Hmm ... on my Mac,
>
> $ python-config
> Usage: /usr/bin/python-config [--prefix|--exec-prefix|--includes|--libs|--cflags|--ldflags|--help]
>
> None of those options produce anything including "-framework Python".
> So I think your upstream needs to clarify to us benighted database geeks
> exactly how this needs to be done, in such a way that it doesn't break
> the existing working cases while fixing their case.

Thanks for your reply, Tom. I will check with the Homebrew
maintainers, but my (albeit limited) understanding of the subject is
that a framework Python is only needed for GUI applications. Unless
PL/Python is opening windows and drawing buttons, plpython.so should
work when linked against a non-framework python, whose libraries can
be found like so:

  $ python-config --libs

What is interesting to me is that the top-level configure script in
the Postgres source distribution already does this, saving the result
in `python_libspec`. It's not clear to me why that is later overridden
in the plpython Makefile to build against a framework python.

I'll write back when I hear from the Homebrew folks.

Cheers,

Clay

Re: BUG #6633: PL/Python build does not honor PYTHON on Mac OS X

From
Clay McClure
Date:
On Tue, May 8, 2012 at 11:07 AM, Clay McClure <clay@daemons.net> wrote:

> Thanks for your reply, Tom. I will check with the Homebrew
> maintainers, but my (albeit limited) understanding of the subject is
> that a framework Python is only needed for GUI applications. Unless
> PL/Python is opening windows and drawing buttons, plpython.so should
> work when linked against a non-framework python, whose libraries can
> be found like so:
>
> =A0$ python-config --libs
>
> What is interesting to me is that the top-level configure script in
> the Postgres source distribution already does this, saving the result
> in `python_libspec`. It's not clear to me why that is later overridden
> in the plpython Makefile to build against a framework python.
>
> I'll write back when I hear from the Homebrew folks.

It turns out that `python-config --libs` is only useful when you're
dealing with a unix-style (not framework) python. Since Mac OS X ships
with framework pythons, it makes sense that PostgreSQL would assume a
framework python, but it would be nice if it would also accomodate
unix-style pythons. According to the Homebrew folks, here's how to do
that:

"The gist of it is to grab python-config --prefix and store it in a
variable, say py_prefix. If the file $py_prefix/Python exists, you are
dealing with a Framework build and -framework Python is the
appropriate method of linking. Otherwise, you have a UNIX-style build
and -lpython is the appropriate method of linking."

The '-lpython' specifics are those reported by `python-config --libs`.

Cheers,

Clay

Re: BUG #6633: PL/Python build does not honor PYTHON on Mac OS X

From
Peter Eisentraut
Date:
On tis, 2012-05-08 at 11:33 -0400, Clay McClure wrote:
> "The gist of it is to grab python-config --prefix and store it in a
> variable, say py_prefix. If the file $py_prefix/Python exists, you are
> dealing with a Framework build and -framework Python is the
> appropriate method of linking. Otherwise, you have a UNIX-style build
> and -lpython is the appropriate method of linking."

Please try the attached patch.  It's completely untested, as I don't
have that platform, but as a guidance about how it might work.


Attachment