8000 Simplify generation of error messages for missing libpng/freetype. · matplotlib/matplotlib@52b6474 · GitHub
[go: up one dir, main page]

Skip to content

Commit 52b6474

Browse files
committed
Simplify generation of error messages for missing libpng/freetype.
Since we don't manually check anymore for the presence of the headers, we'll never detect in setup.py/setupext.py that freetype or libpng are missing, so the message generation using install_help_msg() will never be used. Delete the relevant chunk of code. However, when using recent enough compilers (e.g. gcc 5 / VS2017 15.3), we can generate similar error messages on the compiler's side using `__has_include` (which is technically part of C++17, but always enabled by the compiler as an extension -- https://www.gnu.org/software/gcc/gcc-5/changes.html https://blogs.msdn.microsoft.com/vcblog/2017/05/10/c17-features-in-vs-2017-3/ ).
1 parent d1060a8 commit 52b6474

File tree

4 files changed

+40
-94
lines changed
  • < 8000 div class="PRIVATE_TreeView-item-visual prc-TreeView-TreeViewItemVisual-naWzj" aria-hidden="true">
    setupext.py
  • src
  • 4 files changed

    +40
    -94
    lines changed

    setup.py

    Lines changed: 0 additions & 4 deletions
    Original file line numberDiff line numberDiff line change
    @@ -166,10 +166,6 @@ def build_extensions(self):
    166166
    print_line()
    167167
    print_message("The following required packages can not be built: "
    168168
    "%s" % ", ".join(x.name for x in required_failed))
    169-
    for pkg in required_failed:
    170-
    msg = pkg.install_help_msg()
    171-
    if msg:
    172-
    print_message(msg)
    173169
    sys.exit(1)
    174170

    175171
    # Now collect all of the information we need to build all of the

    setupext.py

    Lines changed: 0 additions & 74 deletions
    F440
    Original file line numberDiff line numberDiff line change
    @@ -338,14 +338,6 @@ class CheckFailed(Exception):
    338338

    339339
    class SetupPackage(object):
    340340
    optional = False
    341-
    pkg_names = {
    342-
    "apt-get": None,
    343-
    "yum": None,
    344-
    "dnf": None,
    345-
    "brew": None,
    346-
    "port": None,
    347-
    "windows_url": None
    348-
    }
    349341

    350342
    def check(self):
    351343
    """
    @@ -461,56 +453,6 @@ def do_custom_build(self):
    461453
    """
    462454
    pass
    463455

    464-
    def install_help_msg(self):
    465-
    """
    466-
    Do not override this method !
    467-
    468-
    Generate the help message to show if the package is not installed.
    469-
    To use this in subclasses, simply add the dictionary `pkg_names` as
    470-
    a class variable:
    471-
    472-
    pkg_names = {
    473-
    "apt-get": <Name of the apt-get package>,
    474-
    "yum": <Name of the yum package>,
    475-
    "dnf": <Name of the dnf package>,
    476-
    "brew": <Name of the brew package>,
    477-
    "port": <Name of the port package>,
    478-
    "windows_url": <The url which has installation instructions>
    479-
    }
    480-
    481-
    All the dictionary keys are optional. If a key is not present or has
    482-
    the value `None` no message is provided for that platform.
    483-
    """
    484-
    def _try_managers(*managers):
    485-
    for manager in managers:
    486-
    pkg_name = self.pkg_names.get(manager, None)
    487-
    if pkg_name:
    488-
    if shutil.which(manager) is not None:
    489-
    if manager == 'port':
    490-
    pkgconfig = 'pkgconfig'
    491-
    else:
    492-
    pkgconfig = 'pkg-config'
    493-
    return ('Try installing {0} with `{1} install {2}` '
    494-
    'and pkg-config with `{1} install {3}`'
    495-
    .format(self.name, manager, pkg_name,
    496-
    pkgconfig))
    497-
    498-
    message = None
    499-
    if sys.platform == "win32":
    500-
    url = self.pkg_names.get("windows_url", None)
    501-
    if url:
    502-
    message = ('Please check {0} for instructions to install {1}'
    503-
    .format(url, self.name))
    504-
    elif sys.platform == "darwin":
    505-
    message = _try_managers("brew", "port")
    506-
    elif sys.platform == "linux":
    507-
    release = platform.linux_distribution()[0].lower()
    508-
    if release in ('debian', 'ubuntu'):
    509-
    message = _try_managers('apt-get')
    510-
    elif release in ('centos', 'redhat', 'fedora'):
    511-
    message = _try_managers('dnf', 'yum')
    512-
    return message
    513-
    514456

    515457
    class OptionalPackage(SetupPackage):
    516458
    optional = True
    @@ -823,14 +765,6 @@ def add_flags(self, ext, add_sources=True):
    823765

    824766
    class FreeType(SetupPackage):
    825767
    name = "freetype"
    826-
    pkg_names = {
    827-
    "apt-get": "libfreetype6-dev",
    828-
    "yum": "freetype-devel",
    829-
    "dnf": "freetype-devel",
    830-
    "brew": "freetype",
    831-
    "port": "freetype",
    832-
    "windows_url": "http://gnuwin32.sourceforge.net/packages/freetype.htm"
    833-
    }
    834768

    835769
    def add_flags(self, ext):
    836770
    ext.sources.insert(0, 'src/checkdep_freetype2.c')
    @@ -1005,14 +939,6 @@ def get_extension(self):
    1005939

    1006940
    class Png(SetupPackage):
    1007941
    name = "png"
    1008-
    pkg_names = {
    1009-
    "apt-get": "libpng12-dev",
    1010-
    "yum": "libpng-devel",
    1011-
    "dnf": "libpng-devel",
    1012-
    "brew": "libpng",
    1013-
    "port": "libpng",
    1014-
    "windows_url": "http://gnuwin32.sourceforge.net/packages/libpng.htm"
    1015-
    }
    1016942

    1017943
    def get_extension(self):
    1018944
    sources = [

    src/checkdep_freetype2.c

    Lines changed: 22 additions & 12 deletions
    Original file line numberDiff line numberDiff line change
    @@ -1,13 +1,23 @@
    1-
    #include <ft2build.h>
    2-
    #include FT_FREETYPE_H
    3-
    4-
    #define XSTR(x) STR(x)
    5-
    #define STR(x) #x
    6-
    7-
    #pragma message("Compiling with FreeType version " \
    8-
    XSTR(FREETYPE_MAJOR) "." XSTR(FREETYPE_MINOR) "." XSTR(FREETYPE_PATCH) ".")
    9-
    #if FREETYPE_MAJOR << 16 + FREETYPE_MINOR << 8 + FREETYPE_PATCH < 0x020300
    10-
    #error "FreeType version 2.3 or higher is required." \
    11-
    "Consider setting the MPLLOCALFREETYPE environment variable to 1."
    12-
    #error
    1+
    #if defined __has_include && ! __has_include(<ft2build.h>)
    2+
    3+
    #error "FreeType version 2.3 or higher is required. \
    4+
    You may set the MPLLOCALFREETYPE environment variable to 1 to let \
    5+
    Matplotlib download it."
    6+
    7+
    #else
    8+
    9+
    #include <ft2build.h>
    10+
    #include FT_FREETYPE_H
    11+
    12+
    #define XSTR(x) STR(x)
    13+
    #define STR(x) #x
    14+
    15+
    #pragma message("Compiling with FreeType version " \
    16+
    XSTR(FREETYPE_MAJOR) "." XSTR(FREETYPE_MINOR) "." XSTR(FREETYPE_PATCH) ".")
    17+
    #if FREETYPE_MAJOR << 16 + FREETYPE_MINOR << 8 + FREETYPE_PATCH < 0x020300
    18+
    #error "FreeType version 2.3 or higher is required. \
    19+
    You may set the MPLLOCALFREETYPE environment variable to 1 to let \
    20+
    Matplotlib download it."
    21+
    #endif
    22+
    1323
    #endif

    src/checkdep_libpng.c

    Lines changed: 18 additions & 4 deletions
    Original file line numberDiff line numberDiff line change
    @@ -1,5 +1,19 @@
    1-
    #include <png.h>
    2-
    #pragma message("Compiling with libpng version " PNG_LIBPNG_VER_STRING ".")
    3-
    #if PNG_LIBPNG_VER < 10200
    4-
    #error "libpng version 1.2 or higher is required."
    1+
    #if defined __has_include && ! __has_include(<png.h>)
    2+
    3+
    #error "libpng version 1.2 or higher is required. \
    4+
    Consider installing it with e.g. 'conda install libpng', \
    5+
    'apt install libpng12-dev', 'dnf install libpng-devel', or \
    6+
    'brew install libpng'."
    7+
    8+
    #else
    9+
    10+
    #include <png.h>
    11+
    #pragma message("Compiling with libpng version " PNG_LIBPNG_VER_STRING ".")
    12+
    #if PNG_LIBPNG_VER < 10200
    13+
    #error "libpng version 1.2 or higher is required. \
    14+
    Consider installing it with e.g. 'conda install libpng', \
    15+
    'apt install libpng12-dev', 'dnf install libpng-devel', or \
    16+
    'brew install libpng'."
    17+
    #endif
    18+
    519
    #endif

    0 commit comments

    Comments
     (0)
    0