8686
8787import test as test_py
8888
89+ pymupdf_dir = os .path .abspath ( f'{ __file__ } /../..' )
90+
91+ sys .path .insert (0 , pymupdf_dir )
92+ import pipcl
93+ del sys .path [0 ]
94+
95+ log = pipcl .log0
96+
8997# Requirements for a system build and install:
9098#
9199# system packages (Debian names):
106114def main ():
107115
108116 if 1 :
109- print (f'## { __file__ } : Starting.' )
110- print (f'{ sys .executable = } ' )
111- print (f'{ platform .python_version ()= } ' )
112- print (f'{ __file__ = } ' )
113- print (f'{ sys .argv = } ' )
114- print (f'{ sysconfig .get_path ("platlib" )= } ' )
117+ log (f'## { __file__ } : Starting.' )
118+ log (f'{ sys .executable = } ' )
119+ log (f'{ platform .python_version ()= } ' )
120+ log (f'{ __file__ = } ' )
121+ log (f'{ sys .argv = } ' )
122+ log (f'{ sysconfig .get_path ("platlib" )= } ' )
115123 run_command (f'python -V' , check = 0 )
116124 run_command (f'python3 -V' , check = 0 )
117125 run_command (f'sudo python -V' , check = 0 )
@@ -132,7 +140,6 @@ def main():
132140 packages = True
133141 prefix = '/usr/local'
134142 pymupdf_do = True
135- pymupdf_dir = os .path .abspath ( f'{ __file__ } /../..' )
136143 root = 'sysinstall_test'
137144 tesseract5 = True
138145 pytest_args = None
@@ -152,7 +159,7 @@ def main():
152159 except StopIteration :
153160 break
154161 if arg in ('-h' , '--help' ):
155- print (__doc__ )
162+ log (__doc__ )
156163 return
157164 elif arg == '--mupdf-do' : mupdf_do = int (next (args ))
158165 elif arg == '--mupdf-dir' : mupdf_dir = next (args )
@@ -161,7 +168,6 @@ def main():
161168 elif arg == '--packages' : packages = int (next (args ))
162169 elif arg == '--prefix' : prefix = next (args )
163170 elif arg == '--pymupdf-do' : pymupdf_do = int (next (args ))
164- elif arg == '--pymupdf-dir' : pymupdf_dir = next (args )
165171 elif arg == '--root' : root = next (args )
166172 elif arg == '--tesseract5' : tesseract5 = int (next (args ))
167173 elif arg == '--pytest-do' : pytest_do = int (next (args ))
@@ -191,23 +197,23 @@ def run(command):
191197 if mupdf_git :
192198 # Update existing checkout or do `git clone`.
193199 if os .path .exists (mupdf_dir ):
194- print (f'## Update MuPDF checkout { mupdf_dir } .' )
200+ log (f'## Update MuPDF checkout { mupdf_dir } .' )
195201 run (f'cd { mupdf_dir } && git pull && git submodule update --init' )
196202 else :
197203 # No existing git checkout, so do a fresh clone.
198- print (f'## Clone MuPDF into { mupdf_dir } .' )
204+ log (f'## Clone MuPDF into { mupdf_dir } .' )
199205 run (f'git clone --recursive --depth 1 --shallow-submodules { mupdf_git } { mupdf_dir } ' )
200206
201207 if packages :
202208 # Install required system packages. We assume a Debian package system.
203209 #
204- print ('## Install system packages required by MuPDF.' )
210+ log ('## Install system packages required by MuPDF.' )
205211 run (f'sudo apt update' )
206212 run (f'sudo apt install { " " .join (g_sys_packages )} ' )
207213 # Ubuntu-22.04 has freeglut3-dev, not libglut-dev.
208214 run (f'sudo apt install libglut-dev | sudo apt install freeglut3-dev' )
209215 if tesseract5 :
210- print (f'## Force installation of libtesseract-dev version 5.' )
216+ log (f'## Force installation of libtesseract-dev version 5.' )
211217 # https://stackoverflow.com/questions/76834972/how-can-i-run-pytesseract-python-library-in-ubuntu-22-04
212218 #
213219 run ('sudo apt install -y software-properties-common' )
@@ -220,12 +226,12 @@ def run(command):
220226 # Build+install MuPDF. We use mupd:Makefile's install-shared-python target.
221227 #
222228 if pip == 'sudo' :
223- print ('## Installing Python packages required for building MuPDF and PyMuPDF.' )
229+ log ('## Installing Python packages required for building MuPDF and PyMuPDF.' )
224230 run (f'sudo pip install --upgrade pip' )
225231 names = test_py .wrap_get_requires_for_build_wheel (f'{ __file__ } /../..' )
226232 run (f'sudo pip install { names } ' )
227233
228- print ('## Build and install MuPDF.' )
234+ log ('## Build and install MuPDF.' )
229235 command = f'cd { mupdf_dir } '
230236 command += f' && { sudo } make'
231237 command += f' -j { multiprocessing .cpu_count ()} '
@@ -246,10 +252,10 @@ def run(command):
246252
247253 # Build+install PyMuPDF.
248254 #
249- print ('## Build and install PyMuPDF.' )
255+ log ('## Build and install PyMuPDF.' )
250256 def run (command ):
251257 return run_command (command , doit = pymupdf_do )
252- flags_freetype2 = run_command ('pkg-config --cflags freetype2' , capture_output = 1 ). stdout . strip ( )
258+ flags_freetype2 = run_command ('pkg-config --cflags freetype2' , capture = 1 )
253259 compile_flags = f'-I { root_prefix } /include { flags_freetype2 } '
254260 link_flags = f'-L { root_prefix } /lib'
255261 env = ''
@@ -258,7 +264,7 @@ def run(command):
258264 env += f'LDFLAGS="-L { root } /{ prefix } /lib" '
259265 env += f'PYMUPDF_SETUP_MUPDF_BUILD= ' # Use system MuPDF.
260266 if use_installer :
261- print (f'## Building wheel.' )
267+ log (f'## Building wheel.' )
262268 if pip == 'venv' :
263269 venv_name = 'venv-pymupdf-sysinstall'
264270 run (f'pwd' )
@@ -277,7 +283,7 @@ def run(command):
277283 wheel = glob .glob (f'dist/*' )
278284 assert len (wheel ) == 1 , f'{ wheel = } '
279285 wheel = wheel [0 ]
280- print (f'## Installing wheel using `installer`.' )
286+ log (f'## Installing wheel using `installer`.' )
281287 pv = '.' .join (platform .python_version_tuple ()[:2 ])
282288 p = f'{ root_prefix } /lib/python{ pv } '
283289 # `python -m installer` fails to overwrite existing files.
@@ -315,13 +321,10 @@ def run(command):
315321 if leaf in dirnames :
316322 pythonpath .append (os .path .join (dirpath , leaf ))
317323 pythonpath = ':' .join (pythonpath )
318- print (f'{ pythonpath = } ' )
324+ log (f'{ pythonpath = } ' )
319325 else :
320326 command = f'{ env } pip install -vv --root { root } { os .path .abspath (pymupdf_dir )} '
321327 run ( command )
322- sys .path .insert (0 , pymupdf_dir )
323- import pipcl
324- del sys .path [0 ]
325328 pythonpath = pipcl .install_dir (root )
326329
327330 # Show contents of installation directory. This is very slow on github,
@@ -330,7 +333,7 @@ def run(command):
330333
331334 # Run pytest tests.
332335 #
333- print ('## Run PyMuPDF pytest tests.' )
336+ log ('## Run PyMuPDF pytest tests.' )
334337 def run (command ):
335338 return run_command (command , doit = pytest_do )
336339 import gh_release
@@ -387,13 +390,11 @@ def run(command):
387390 run (command )
388391
389392
390- def run_command (command , capture_output = False , check = True , doit = True ):
393+ def run_command (command , capture = False , check = True , doit = True ):
391394 if doit :
392- print (f'## Running: { command } ' )
393- sys .stdout .flush ()
394- return subprocess .run (command , shell = 1 , check = check , text = 1 , capture_output = capture_output )
395+ return pipcl .run (command , capture = capture , check = check , caller = 2 )
395396 else :
396- print (f'## Would have run: { command } ' )
397+ log (f'## Would have run: { command } ' , caller = 2 )
397398
398399
399400if __name__ == '__main__' :
0 commit comments