1-
2- from pythonforandroid .logger import info_notify
31from pythonforandroid .recipe import CppCompiledComponentsPythonRecipe
42from pythonforandroid .util import ensure_dir
53
64from os .path import join
5+ import shutil
76
87
98class MatplotlibRecipe (CppCompiledComponentsPythonRecipe ):
109
11- version = '3.1.3 '
10+ version = '3.5.2 '
1211 url = 'https://github.com/matplotlib/matplotlib/archive/v{version}.zip'
1312
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' ]
2514
26- call_hostpython_via_targetpython = False
15+ python_depends = [ 'cycler' , 'fonttools' , 'packaging' , 'pyparsing' , 'python-dateutil' ]
2716
2817 def generate_libraries_pc_files (self , arch ):
2918 """
@@ -42,10 +31,9 @@ def generate_libraries_pc_files(self, arch):
4231 # version for freetype, but we have our recipe named without
4332 # the version...so we add it in here for our pc file
4433 'freetype' : 'freetype2.pc' ,
45- 'png' : 'png.pc' ,
4634 }
4735
48- for lib_name in {'freetype' , 'png' }:
36+ for lib_name in {'freetype' }:
4937 pc_template_file = join (
5038 self .get_recipe_dir (),
5139 f'lib{ lib_name } .pc.template'
@@ -67,83 +55,26 @@ def generate_libraries_pc_files(self, arch):
6755 with open (pc_dest_file , 'w' ) as pc_file :
6856 pc_file .write (text_buffer )
6957
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-
9558 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+ )
10363 self .generate_libraries_pc_files (arch )
104- self .download_web_backend_dependencies (arch )
10564
10665 def get_recipe_env (self , arch = None , with_flags_in_cc = True ):
10766 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+
12668 # we make use of the same directory than `XDG_CACHE_HOME`, for our
12769 # custom library pc files, so we have all the install files that we
12870 # generate at the same place
71+ env ['XDG_CACHE_HOME' ] = join (self .get_build_dir (arch ), 'p4a_files' )
12972 env ['PKG_CONFIG_PATH' ] = env ['XDG_CACHE_HOME' ]
13073
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-
13974 # creating proper *.pc files for our libraries does not seem enough to
14075 # success with our build (without depending on system development
14176 # libraries), but if we tell the compiler where to find our libraries
14277 # 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-
14778 freetype = self .get_recipe ('freetype' , self .ctx )
14879 free_lib_dir = join (freetype .get_build_dir (arch .arch ), 'objs' , '.libs' )
14980 free_inc_dir = join (freetype .get_build_dir (arch .arch ), 'include' )
0 commit comments