8000 Merge pull request #13067 from anntzer/missing-freetype-libpng · matplotlib/matplotlib@5c7d2fe · GitHub
[go: up one dir, main page]

Skip to content

Commit 5c7d2fe

Browse files
authored
Merge pull request #13067 from anntzer/missing-freetype-libpng
Simplify generation of error messages for missing libpng/freetype.
2 parents 6ce2638 + 52b6474 commit 5c7d2fe

File tree

4 files changed

+40
-94
lines changed

4 files changed

+40
-94
lines changed

setup.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,6 @@ def run(self):
210210
print_line()
211211
print_message("The following required packages can not be built: "
212212
"%s" % ", ".join(x.name for x in required_failed))
213-
for pkg in required_failed:
214-
msg = pkg.install_help_msg()
215-
if msg:
216-
print_message(msg)
217213
sys.exit(1)
218214

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

setupext.py

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

292292
class SetupPackage(object):
293293
optional = False
294-
pkg_names = {
295-
"apt-get": None,
296-
"yum": None,
297-
"dnf": None,
298-
"brew": None,
299-
"port": None,
300-
"windows_url": None
301-
}
302294

303295
def check(self):
304296
"""
@@ -333,56 +325,6 @@ def do_custom_build(self):
333325
"""
334326
pass
335327

336-
def install_help_msg(self):
337-
"""
338-
Do not override this method !
339-
340-
Generate the help message to show if the package is not installed.
341-
To use this in subclasses, simply add the dictionary `pkg_names` as
342-
a class variable:
343-
344-
pkg_names = {
345-
"apt-get": <Name of the apt-get package>,
346-
"yum": <Name of the yum package>,
347-
"dnf": <Name of the dnf package>,
348-
"brew": <Name of the brew package>,
349-
"port": <Name of the port package>,
350-
"windows_url": <The url which has installation instructions>
351-
}
352-
353-
All the dictionary keys are optional. If a key is not present or has
354-
the value `None` no message is provided for that platform.
355-
"""
356-
def _try_managers(*managers):
357-
for manager in managers:
358-
pkg_name = self.pkg_names.get(manager, None)
359-
if pkg_name:
360-
if shutil.which(manager) is not None:
361-
if manager == 'port':
362-
pkgconfig = 'pkgconfig'
363-
else:
364-
pkgconfig = 'pkg-config'
365-
return ('Try installing {0} with `{1} install {2}` '
366-
'and pkg-config with `{1} install {3}`'
367-
.format(self.name, manager, pkg_name,
368-
pkgconfig))
369-
370-
message = None
371-
if sys.platform == "win32":
372-
url = self.pkg_names.get("windows_url", None)
373-
if url:
374-
message = ('Please check {0} for instructions to install {1}'
375-
.format(url, self.name))
376-
elif sys.platform == "darwin":
377-
message = _try_managers("brew", "port")
378-
elif sys.platform == "linux":
379-
release = platform.linux_distribution()[0].lower()
380-
if release in ('debian', 'ubuntu'):
381-
message = _try_managers('apt-get')
382-
elif release in ('centos', 'redhat', 'fedora'):
383-
message = _try_managers('dnf', 'yum')
384-
return message
385-
386328

387329
class OptionalPackage(SetupPackage):
388330
optional = True
@@ -552,14 +494,6 @@ def add_flags(self, ext, add_sources=True):
552494

553495
class FreeType(SetupPackage):
554496
name = "freetype"
555-
pkg_names = {
556-
"apt-get": "libfreetype6-dev",
557-
"yum": "freetype-devel",
558-
"dnf": "freetype-devel",
559-
"brew": "freetype",
560-
"port": "freetype",
561-
"windows_url": "http://gnuwin32.sourceforge.net/packages/freetype.htm"
562-
}
563497

564498
def add_flags(self, ext):
565499
ext.sources.insert(0, 'src/checkdep_freetype2.c')
@@ -708,14 +642,6 @@ def get_extension(self):
708642

709643
class Png(SetupPackage):
710644
name = "png"
711-
pkg_names = {
712-
"apt-get": "libpng12-dev",
713-
"yum": "libpng-devel",
714-
"dnf": "libpng-devel",
715-
"brew": "libpng",
716-
"port": "libpng",
717-
"windows_url": "http://gnuwin32.sourceforge.net/packages/libpng.htm"
718-
}
719645

720646
def get_extension(self):
721647
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