Skip to content

Commit

Permalink
Merge pull request #2509 from Flamefire/tkinter
Browse files Browse the repository at this point in the history
Clean up installation of Tkinter
  • Loading branch information
boegel authored Sep 1, 2021
2 parents e31410c + 93fe925 commit ab837f3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 23 deletions.
12 changes: 5 additions & 7 deletions easybuild/easyblocks/p/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,8 @@ def __init__(self, *args, **kwargs):

self.pyshortver = '.'.join(self.version.split('.')[:2])

self.pythonpath = None
if self.cfg['ebpythonprefixes']:
easybuild_subdir = log_path()
self.pythonpath = os.path.join(easybuild_subdir, 'python')
# Used for EBPYTHONPREFIXES handler script
self.pythonpath = os.path.join(log_path(), 'python')

ext_defaults = {
# Use PYPI_SOURCE as the default for source_urls of extensions.
Expand Down Expand Up @@ -455,7 +453,7 @@ def install_step(self):
if not os.path.isfile(pip_binary_path):
symlink('pip' + self.pyshortver, pip_binary_path, use_abspath_source=False)

if self.cfg['ebpythonprefixes']:
if self.cfg.get('ebpythonprefixes'):
write_file(os.path.join(self.installdir, self.pythonpath, 'sitecustomize.py'), SITECUSTOMIZE)

# symlink lib/python*/lib-dynload to lib64/python*/lib-dynload if it doesn't exist;
Expand Down Expand Up @@ -531,7 +529,7 @@ def sanity_check_step(self):
else:
self.log.info("No errors found in output of %s: %s", cmd, out)

if self.cfg['ebpythonprefixes']:
if self.cfg.get('ebpythonprefixes'):
self._sanity_check_ebpythonprefixes()

pyver = 'python' + self.pyshortver
Expand Down Expand Up @@ -583,7 +581,7 @@ def make_module_extra(self, *args, **kwargs):
"""Add path to sitecustomize.py to $PYTHONPATH"""
txt = super(EB_Python, self).make_module_extra()

if self.pythonpath:
if self.cfg.get('ebpythonprefixes'):
txt += self.module_generator.prepend_paths('PYTHONPATH', self.pythonpath)

return txt
37 changes: 21 additions & 16 deletions easybuild/easyblocks/t/tkinter.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
from easybuild.easyblocks.generic.pythonpackage import det_pylibdir
from easybuild.easyblocks.python import EB_Python
from easybuild.tools.build_log import EasyBuildError
from easybuild.tools.config import build_option
from easybuild.tools.filetools import copy, move_file, remove_dir
from easybuild.tools.modules import get_software_root
from easybuild.tools.systemtools import get_shared_lib_ext
Expand All @@ -51,10 +50,19 @@ class EB_Tkinter(EB_Python):
but only install the Tkinter bits.
"""

@staticmethod
def extra_options():
"""Disable EBPYTHONPREFIXES."""
extra_vars = EB_Python.extra_options()
# Not used for Tkinter
del extra_vars['ebpythonprefixes']

return extra_vars

def __init__(self, *args, **kwargs):
"""Initialize Tkinter-specific variables."""
super(EB_Tkinter, self).__init__(*args, **kwargs)
self.tkinter_so_basename = ''
self.tkinter_so_basename = None

def configure_step(self):
"""Check for Tk before configuring"""
Expand All @@ -75,30 +83,28 @@ def install_step(self):

tmpdir = tempfile.mkdtemp(dir=self.builddir)

if not self.tkinter_so_basename:
self.tkinter_so_basename = self.get_tkinter_so_basename()
self.tkinter_so_basename = self.get_tkinter_so_basename(False)
if LooseVersion(self.version) >= LooseVersion('3'):
tkparts = ["tkinter", os.path.join("lib-dynload", self.tkinter_so_basename)]
else:
tkparts = ["lib-tk", os.path.join("lib-dynload", self.tkinter_so_basename)]

pylibdir = os.path.join(self.installdir, os.path.dirname(det_pylibdir()))
copy([os.path.join(pylibdir, x) for x in tkparts], tmpdir)
pylibdir = os.path.join(self.installdir, det_pylibdir())
copy([os.path.join(os.path.dirname(pylibdir), x) for x in tkparts], tmpdir)

remove_dir(self.installdir)

move_file(os.path.join(tmpdir, tkparts[0]), os.path.join(pylibdir, tkparts[0]))
tkinter_so = os.path.basename(tkparts[1])
move_file(os.path.join(tmpdir, tkinter_so), os.path.join(pylibdir, tkinter_so))
move_file(os.path.join(tmpdir, self.tkinter_so_basename), os.path.join(pylibdir, self.tkinter_so_basename))

def get_tkinter_so_basename(self):
pylibdir = os.path.join(self.installdir, os.path.dirname(det_pylibdir()))
def get_tkinter_so_basename(self, in_final_dir):
pylibdir = os.path.join(self.installdir, det_pylibdir())
shlib_ext = get_shared_lib_ext()
if build_option('module_only'):
if in_final_dir:
# The build has already taken place so the file will have been moved into the final pylibdir
tkinter_so = os.path.join(pylibdir, '_tkinter*.' + shlib_ext)
else:
tkinter_so = os.path.join(pylibdir, 'lib-dynload', '_tkinter*.' + shlib_ext)
tkinter_so = os.path.join(os.path.dirname(pylibdir), 'lib-dynload', '_tkinter*.' + shlib_ext)
tkinter_so_hits = glob.glob(tkinter_so)
if len(tkinter_so_hits) != 1:
raise EasyBuildError("Expected to find exactly one _tkinter*.so: %s", tkinter_so_hits)
Expand All @@ -115,18 +121,17 @@ def sanity_check_step(self):
custom_commands = ["python -c 'import %s'" % tkinter]

if not self.tkinter_so_basename:
self.tkinter_so_basename = self.get_tkinter_so_basename()
self.tkinter_so_basename = self.get_tkinter_so_basename(True)

custom_paths = {
'files': [os.path.join(os.path.dirname(det_pylibdir()), self.tkinter_so_basename)],
'files': [os.path.join(det_pylibdir(), self.tkinter_so_basename)],
'dirs': ['lib']
}
super(EB_Python, self).sanity_check_step(custom_commands=custom_commands, custom_paths=custom_paths)

def make_module_extra(self):
"""Set PYTHONPATH"""
txt = super(EB_Tkinter, self).make_module_extra()
pylibdir = os.path.dirname(det_pylibdir())
txt += self.module_generator.prepend_paths('PYTHONPATH', pylibdir)
txt += self.module_generator.prepend_paths('PYTHONPATH', det_pylibdir())

return txt

0 comments on commit ab837f3

Please sign in to comment.