replace deprecated distutils.find_executable

In !309 (merged) I reverted the change from distutils.find_executable to shutils.which, because the latter method also found python files in the current working directory in some conditions.

This is due to a peculiarity of the shutil implementation on Windows (https://github.com/python/cpython/blob/3.10/Lib/shutil.py#L1430) which prepends the working dir to PATH, because that's what cmd's where command does. If ".PY" in os.environ["PATHEXT"].split(";"), this lead to e.g. ./pdflatex.py taking precendence over pdflatex.exe in PATH (and is what lead to inbox#5041 (closed)).

I'm not sure why .PY is contained in PATHEXT (it's not by default), it might be automatically added by some Python Installers for Windows (?). To avoid problems with manipulating the environment, I went for tricking the shutil.which implementation by explicitly appending the cwd to PATH, so PATH takes precendence.

The fix can be tested by inserting os.environ["PATHEXT"] += ";.PY" at the beginning of the command method. Without the optional path parameter, the pdflatex extension then fails.

Closes #432 (closed)

Edited by Jonathan Neuhauser

Merge request reports

Loading