1
-
2
- from pythonforandroid .logger import info_notify
3
1
from pythonforandroid .recipe import CppCompiledComponentsPythonRecipe
4
2
from pythonforandroid .util import ensure_dir
5
3
6
4
from os .path import join
5
+ import shutil
7
6
8
7
9
8
class MatplotlibRecipe (CppCompiledComponentsPythonRecipe ):
10
9
11
- version = '3.1.3 '
10
+ version = '3.5.2 '
12
11
url = 'https://github.com/matplotlib/matplotlib/archive/v{version}.zip'
13
12
14
- depends = ['numpy' , 'png' , 'setuptools' , 'freetype' , 'kiwisolver' ]
15
-
16
- python_depends = ['pyparsing' , 'cycler' , 'python-dateutil' ]
17
-
18
- # We need to patch to:
19
- # - make mpl install work without importing numpy
20
- # - make mpl use shared libraries for freetype and png
21
- # - make mpl link to png16, to match p4a library name for png
22
- # - prevent mpl trying to build TkAgg, which wouldn't work
23
- # on Android anyway but has build issues
24
- patches = ['mpl_android_fixes.patch' ]
13
+ depends = ['kiwisolver' , 'numpy' , 'pillow' , 'setuptools' , 'freetype' ]
25
14
26
- call_hostpython_via_targetpython = False
15
+ python_depends = [ 'cycler' , 'fonttools' , 'packaging' , 'pyparsing' , 'python-dateutil' ]
27
16
28
17
def generate_libraries_pc_files (self , arch ):
29
18
"""
@@ -42,10 +31,9 @@ def generate_libraries_pc_files(self, arch):
42
31
# version for freetype, but we have our recipe named without
43
32
# the version...so we add it in here for our pc file
44
33
'freetype' : 'freetype2.pc' ,
45
- 'png' : 'png.pc' ,
46
34
}
47
35
48
- for lib_name in {'freetype' , 'png' }:
36
+ for lib_name in {'freetype' }:
49
37
pc_template_file = join (
50
38
self .get_recipe_dir (),
51
39
f'lib{ lib_name } .pc.template'
@@ -67,83 +55,26 @@ def generate_libraries_pc_files(self, arch):
67
55
with open (pc_dest_file , 'w' ) as pc_file :
68
56
pc_file .write (text_buffer )
69
57
70
- def download_web_backend_dependencies (self , arch ):
71
- """
72
- During building, host needs to download the jquery-ui package (in order
73
- to make it work the mpl web backend). This operation seems to fail
74
- in our CI tests, so we download this package at the expected location
75
- by the mpl install script which is defined by the environ variable
76
- `XDG_CACHE_HOME` (we modify that one in our `get_recipe_env` so it will
77
- be the same regardless of the host platform).
78
- """
79
-
80
- env = self .get_recipe_env (arch )
81
-
82
- info_notify ('Downloading jquery-ui for matplatlib web backend' )
83
- # We use the same jquery-ui version than mpl's setup.py script,
84
- # inside function `_download_jquery_to`
85
- jquery_sha = (
86
- 'f8233674366ab36b2c34c577ec77a3d70cac75d2e387d8587f3836345c0f624d'
87
- )
88
- url = "https://jqueryui.com/resources/download/jquery-ui-1.12.1.zip"
89
- target_file = join (env ['XDG_CACHE_HOME' ], 'matplotlib' , jquery_sha )
90
-
91
- info_notify (f'Will download into { env ["XDG_CACHE_HOME" ]} ' )
92
- ensure_dir (join (env ['XDG_CACHE_HOME' ], 'matplotlib' ))
93
- self .download_file (url , target_file )
94
-
95
58
def prebuild_arch (self , arch ):
96
- with open (join (self .get_recipe_dir (), 'setup.cfg.template' )) as fileh :
97
- setup_cfg = fileh .read ()
98
-
99
- with open (join (self .get_build_dir (arch ), 'setup.cfg' ), 'w' ) as fileh :
100
- fileh .write (setup_cfg .format (
101
- ndk_sysroot_usr = join (self .ctx .ndk .sysroot , 'usr' )))
102
-
59
+ shutil .copyfile (
60
+ join (self .get_recipe_dir (), "setup.cfg.template" ),
61
+ join (self .get_build_dir (arch ), "mplsetup.cfg" ),
62
+ )
103
63
self .generate_libraries_pc_files (arch )
104
- self .download_web_backend_dependencies (arch )
105
64
106
65
def get_recipe_env (self , arch = None , with_flags_in_cc = True ):
107
66
env = super ().get_recipe_env (arch , with_flags_in_cc )
108
- if self .need_stl_shared :
109
- # matplotlib compile flags does not honor the standard flags:
110
- # `CPPFLAGS` and `LDLIBS`, so we put in `CFLAGS` and `LDFLAGS` to
111
- # correctly link with the `c++_shared` library
112
- env ['CFLAGS' ] += ' -I{}' .format (self .ctx .ndk .libcxx_include_dir )
113
- env ['CFLAGS' ] += ' -frtti -fexceptions'
114
-
115
- env ['LDFLAGS' ] += ' -L{}' .format (arch .ndk_lib_dir )
116
- env ['LDFLAGS' ] += ' -l{}' .format (self .stl_lib_name )
117
-
118
- # we modify `XDG_CACHE_HOME` to download `jquery-ui` into that folder,
119
- # or mpl install will fail when trying to download/install it, but if
120
- # we have the proper package already downloaded, it will use the cached
121
- # package to successfully finish the installation.
122
- # Note: this may not be necessary for some local systems, but it is
123
- # for our CI provider: `gh-actions`, which will
124
- # fail trying to download the `jquery-ui` package
125
- env ['XDG_CACHE_HOME' ] = join (self .get_build_dir (arch ), 'p4a_files' )
67
+
126
68
# we make use of the same directory than `XDG_CACHE_HOME`, for our
127
69
# custom library pc files, so we have all the install files that we
128
70
# generate at the same place
71
+ env ['XDG_CACHE_HOME' ] = join (self .get_build_dir (arch ), 'p4a_files' )
129
72
env ['PKG_CONFIG_PATH' ] = env ['XDG_CACHE_HOME' ]
130
73
131
- # We set a new environ variable `NUMPY_INCLUDES` to be able to tell
132
- # the matplotlib script where to find our numpy without importing it
133
- # (which will fail, because numpy isn't installed in our hostpython)
134
- env ['NUMPY_INCLUDES' ] = join (
135
- self .ctx .get_site_packages_dir (arch ),
136
- 'numpy' , 'core' , 'include' ,
137
- )
138
-
139
74
# creating proper *.pc files for our libraries does not seem enough to
140
75
# success with our build (without depending on system development
141
76
# libraries), but if we tell the compiler where to find our libraries
142
77
# and includes, then the install success :)
143
- png = self .get_recipe ('png' , self .ctx )
144
- env ['CFLAGS' ] += f' -I{ png .get_build_dir (arch )} '
145
- env ['LDFLAGS' ] += f' -L{ join (png .get_build_dir (arch .arch ), ".libs" )} '
146
-
147
78
freetype = self .get_recipe ('freetype' , self .ctx )
148
79
free_lib_dir = join (freetype .get_build_dir (arch .arch ), 'objs' , '.libs' )
149
80
free_inc_dir = join (freetype .get_build_dir (arch .arch ), 'include' )
0 commit comments