Fix for FileNotFoundError when mercurial or git is not installed #2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Exception occurs when mercurial or git is not installed, subprocess.CalledProcessError exception is not raised by the subprocess.check_output() command. [WinError 2] The system cannot find the file specified exception is raised instead.
Django Version: 4.0.5
Python Version: 3.9.13
Steps to reproduce
Mercurial or git is not installed
Add
django_cachekiller
to yourINSTALLED_APPS
in yoursettings.py
Then use the
cdnstatic
tag in the templateException
FileNotFoundError at /
[WinError 2] The system cannot find the file specified
Request Method: GET
Request URL: http://localhost:8000/
Django Version: 4.0.5
Exception Type: FileNotFoundError
Exception Value:
[WinError 2] The system cannot find the file specified
Exception Location: D:\Python39\lib\subprocess.py, line 1420, in _execute_child
Python Executable: D:\Python39\python.exe
Python Version: 3.9.13
Template error:
39 :
File "D:\Python39\lib\site-packages\django_cachekiller\templatetags\cdnstaticfiles.py", line 92, in render
qs = 'tag=' + refcache.get_ref()
File "D:\Python39\lib\site-packages\django_cachekiller\templatetags\cdnstaticfiles.py", line 69, in get_ref
ref = self.get_hg_tip()
File "D:\Python39\lib\site-packages\django_cachekiller\templatetags\cdnstaticfiles.py", line 53, in get_hg_tip
ref = self._run_cmd(['hg', 'heads', '--template', '"{node}"'])
File "D:\Python39\lib\site-packages\django_cachekiller\templatetags\cdnstaticfiles.py", line 26, in _run_cmd
return subprocess.check_output(cmd, stderr=subprocess.STDOUT)
File "D:\Python39\lib\subprocess.py", line 424, in check_output
return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
File "D:\Python39\lib\subprocess.py", line 505, in run
with Popen(*popenargs, **kwargs) as process:
File "D:\Python39\lib\subprocess.py", line 951, in init
self._execute_child(args, executable, preexec_fn, close_fds,
File "D:\Python39\lib\subprocess.py", line 1420, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
Exception Type: FileNotFoundError at /
Exception Value: [WinError 2] The system cannot find the file specified