Merge pull request #1226 from adamjstewart/features/tkinter

Add Tkinter support for Python
This commit is contained in:
Todd Gamblin 2016-07-19 09:41:12 -07:00 committed by GitHub
commit a64a2e72cf
3 changed files with 62 additions and 15 deletions

View file

@ -53,6 +53,7 @@ class Python(Package):
extendable = True
variant('tk', default=False, description='Provide support for Tkinter')
variant('ucs4', default=False, description='Enable UCS4 (wide) unicode strings')
# From https://docs.python.org/2/c-api/unicode.html: Python's default
# builds use a 16-bit type for Py_UNICODE and store Unicode values
@ -68,6 +69,8 @@ class Python(Package):
depends_on("ncurses")
depends_on("sqlite")
depends_on("zlib")
depends_on("tk", when="+tk")
depends_on("tcl", when="+tk")
def install(self, spec, prefix):
# Need this to allow python build to find the Python installation.
@ -77,24 +80,32 @@ def install(self, spec, prefix):
# Rest of install is pretty standard except setup.py needs to
# be able to read the CPPFLAGS and LDFLAGS as it scans for the
# library and headers to build
cppflags = ' -I'.join([
include_dirs = [
spec['openssl'].prefix.include, spec['bzip2'].prefix.include,
spec['readline'].prefix.include, spec['ncurses'].prefix.include,
spec['sqlite'].prefix.include, spec['zlib'].prefix.include
])
]
ldflags = ' -L'.join([
library_dirs = [
spec['openssl'].prefix.lib, spec['bzip2'].prefix.lib,
spec['readline'].prefix.lib, spec['ncurses'].prefix.lib,
spec['sqlite'].prefix.lib, spec['zlib'].prefix.lib
])
]
if '+tk' in spec:
include_dirs.extend([
spec['tk'].prefix.include, spec['tcl'].prefix.include
])
library_dirs.extend([
spec['tk'].prefix.lib, spec['tcl'].prefix.lib
])
config_args = [
"--prefix={0}".format(prefix),
"--with-threads",
"--enable-shared",
"CPPFLAGS=-I{0}".format(cppflags),
"LDFLAGS=-L{0}".format(ldflags)
"CPPFLAGS=-I{0}".format(" -I".join(include_dirs)),
"LDFLAGS=-L{0}".format(" -L".join(library_dirs))
]
if '+ucs4' in spec:
@ -116,6 +127,25 @@ def install(self, spec, prefix):
self.filter_compilers(spec, prefix)
# TODO: Once better testing support is integrated, add the following tests
# https://wiki.python.org/moin/TkInter
#
# if '+tk' in spec:
# env['TK_LIBRARY'] = join_path(spec['tk'].prefix.lib,
# 'tk{0}'.format(spec['tk'].version.up_to(2)))
# env['TCL_LIBRARY'] = join_path(spec['tcl'].prefix.lib,
# 'tcl{0}'.format(spec['tcl'].version.up_to(2)))
#
# $ python
# >>> import _tkinter
#
# if spec.satisfies('@3:')
# >>> import tkinter
# >>> tkinter._test()
# else:
# >>> import Tkinter
# >>> Tkinter._test()
def filter_compilers(self, spec, prefix):
"""Run after install to tell the configuration files and Makefiles
to use the compilers that Spack built the package with.

View file

@ -24,6 +24,7 @@
##############################################################################
from spack import *
class Tcl(Package):
"""Tcl (Tool Command Language) is a very powerful but easy to
learn dynamic programming language, suitable for a very wide
@ -34,9 +35,6 @@ class Tcl(Package):
extensible."""
homepage = "http://www.tcl.tk"
def url_for_version(self, version):
return 'http://prdownloads.sourceforge.net/tcl/tcl%s-src.tar.gz' % version
version('8.6.5', '0e6426a4ca9401825fbc6ecf3d89a326')
version('8.6.4', 'd7cbb91f1ded1919370a30edd1534304')
version('8.6.3', 'db382feca91754b7f93da16dc4cdad1f')
@ -44,8 +42,18 @@ def url_for_version(self, version):
depends_on('zlib')
def url_for_version(self, version):
base_url = 'http://prdownloads.sourceforge.net/tcl'
return '{0}/tcl{1}-src.tar.gz'.format(base_url, version)
def setup_environment(self, spack_env, env):
# When using Tkinter from within spack provided python+tk, python
# will not be able to find Tcl/Tk unless TCL_LIBRARY is set.
env.set('TCL_LIBRARY', join_path(self.prefix.lib, 'tcl{0}'.format(
self.spec.version.up_to(2))))
def install(self, spec, prefix):
with working_dir('unix'):
configure("--prefix=%s" % prefix)
configure("--prefix={0}".format(prefix))
make()
make("install")

View file

@ -24,6 +24,7 @@
##############################################################################
from spack import *
class Tk(Package):
"""Tk is a graphical user interface toolkit that takes developing
desktop applications to a higher level than conventional
@ -33,16 +34,24 @@ class Tk(Package):
and more."""
homepage = "http://www.tcl.tk"
def url_for_version(self, version):
return "http://prdownloads.sourceforge.net/tcl/tk%s-src.tar.gz" % version
version('8.6.5', '11dbbd425c3e0201f20d6a51482ce6c4')
version('8.6.3', '85ca4dbf4dcc19777fd456f6ee5d0221')
depends_on("tcl")
def url_for_version(self, version):
base_url = "http://prdownloads.sourceforge.net/tcl"
return "{0}/tk{1}-src.tar.gz".format(base_url, version)
def setup_environment(self, spack_env, env):
# When using Tkinter from within spack provided python+tk, python
# will not be able to find Tcl/Tk unless TK_LIBRARY is set.
env.set('TK_LIBRARY', join_path(self.prefix.lib, 'tk{0}'.format(
self.spec.version.up_to(2))))
def install(self, spec, prefix):
with working_dir('unix'):
configure("--prefix=%s" % prefix,
"--with-tcl=%s" % spec['tcl'].prefix.lib)
configure("--prefix={0}".format(prefix),
"--with-tcl={0}".format(spec['tcl'].prefix.lib))
make()
make("install")