# JH 2020

easyblock = 'Bundle'

name = 'PyQt5'
version = '5.13.1'

homepage = 'https://www.riverbankcomputing.co.uk/software/pyqt'
description = """PyQt5 is a set of Python bindings for v5 of the Qt application framework from The Qt Company.
This bundle includes PyQtWebEngine, a set of Python bindings for The Qt Company’s Qt WebEngine framework."""

toolchain = {'name': 'Py', 'version': '3.7'}
toolchainopts = {'cstd': 'c++11'}

dependencies = [
    ('Qt5', '5.13.1', '', True),
]

default_easyblock = 'ConfigureMakePythonPackage'

local_pylibdir = '%(installdir)s/lib/python3.7/site-packages'

local_sip_configopts = " ".join([
    "configure.py",
    "--bindir %(installdir)s/bin",
    "--incdir %(installdir)s/include",
    "--destdir %s" % local_pylibdir,
    "--sipdir=%(installdir)s/share/sip",
    # required for PyQt5, cfr. https://www.riverbankcomputing.com/static/Docs/PyQt5/installation.html#downloading-sip
    "--sip-module PyQt5.sip",
    "--no-dist-info",
    "--no-stubs",
])

local_pyqt5_configopts = " ".join([
    "configure.py",
    "--confirm-license --verbose --no-python-dbus",
    "--bindir=%(installdir)s/bin",
    "--destdir=%s" % local_pylibdir,
    "--sip=%(installdir)s/bin/sip",
    "--sip-incdir %(installdir)s/include/",
    "--sipdir=%(installdir)s/share/sip/PyQt5",
    "--designer-plugindir=%(installdir)s/plugins/designer",
    "--qml-plugindir=%(installdir)s/plugins/PyQt5",
    "--qsci-api-destdir=%(installdir)s/qsci",
    "--no-dist-info",
    "--no-stubs",
])

local_pyqtweb_configopts = " ".join([
    "configure.py",
    "--verbose",
    "--destdir=%s/PyQt5" % local_pylibdir,
    "--apidir=%(installdir)s/qsci",
    "--pyqt-sipdir=%(builddir)s/PyQt5_gpl-%(version)s/sip",
    "--no-dist-info",
    "--no-stubs",
])

local_setup_env = "export PATH=%(installdir)s/bin:$PATH && "
local_setup_env += "export PYTHONPATH=%(installdir)s/lib/python3.7/site-packages:$PYTHONPATH && "
local_sipver = '4.19.19'
components = [
    ('SIP', local_sipver, {
        'source_urls': ['https://www.riverbankcomputing.com/static/Downloads/sip/%s' % local_sipver],
        'sources': [SOURCELOWER_TAR_GZ],
        'checksums': ['5436b61a78f48c7e8078e93a6b59453ad33780f80c644e5f3af39f94be1ede44'],
        'start_dir': 'sip-%s' % local_sipver,
        'configopts': local_sip_configopts,
        'options': {'modulename': 'PyQt5.sip'},
    }),
    (name, version, {
        'source_urls': ['https://www.riverbankcomputing.com/static/Downloads/%(name)s/%(version)s/'],
        'sources': ['%(name)s_gpl-%(version)s.tar.gz'],
        'checksums': ['54b7f456341b89eeb3930e786837762ea67f235e886512496c4152ebe106d4af'],
        'start_dir': '%(name)s_gpl-%(version)s',
        'preconfigopts': local_setup_env,
        'configopts': local_pyqt5_configopts,
        'preinstallopts': local_setup_env,
        'options': {'modulename': 'PyQt5.QtCore'},
    }),
    ('PyQtWebEngine', version, {
        'source_urls': ['https://www.riverbankcomputing.com/static/Downloads/%(name)s/%(version)s/'],
        'sources': ['%(name)s_gpl-%(version)s.tar.gz'],
        'checksums': ['8d8c1262005d8465653a848bf67327fb338e0d3c2d26090a6f7eb071dbb42092'],
        'start_dir': '%(name)s_gpl-%(version)s',
        'preconfigopts': local_setup_env,
        'configopts': local_pyqtweb_configopts,
        'options': {'modulename': 'PyQt5.QtWebEngine'},
    }),
]

sanity_check_paths = {
    'files': ['bin/sip', 'include/sip.h'] + ['lib/python3.7/site-packages/%s' % x for x in (
        'sipconfig.py',
        'sipdistutils.py',
        '%%(name)s/sip.%s' % SHLIB_EXT,
        '%%(name)s/QtCore.%s' % SHLIB_EXT,
        '%%(name)s/QtWebEngine.%s' % SHLIB_EXT,
    )],
    'dirs': ['include', 'plugins', 'share/sip/PyQt5']
}

modextrapaths = {
    'PYTHONPATH': 'lib/python3.7/site-packages',
    'QT_INSTALL_DATA': 'qsci',
    'QT_PLUGIN_PATH': 'plugins',
}

skipsteps = ['sanitycheck']

moduleclass = 'vis'
